netbios_session.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //---------------------------------------------------------------------------
  2. // __________________ _________ _____ _____ .__ ._.
  3. // \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. // | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. // | | \| ` \/ / Y \ / | | \ ___/ \|
  6. // |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. // \/ \/ \/ \/ )/ \/ \/ \/
  8. //
  9. // This file is part of libdsm. Copyright © 2014 VideoLabs SAS
  10. //
  11. // Author: Julien 'Lta' BALLET <contact@lta.io>
  12. //
  13. // This program is free software. It comes without any warranty, to the extent
  14. // permitted by applicable law. You can redistribute it and/or modify it under
  15. // the terms of the Do What The Fuck You Want To Public License, Version 2, as
  16. // published by Sam Hocevar. See the COPYING file for more details.
  17. //----------------------------------------------------------------------------
  18. #ifndef __BDSM_NETBIOS_SESSION_H_
  19. #define __BDSM_NETBIOS_SESSION_H_
  20. #include <stdint.h>
  21. #include <stddef.h>
  22. #include <sys/socket.h>
  23. #include <netinet/in.h>
  24. #include "bdsm/netbios_defs.h"
  25. #define NETBIOS_SESSION_NEW 0
  26. #define NETBIOS_SESSION_CONNECTING 1
  27. #define NETBIOS_SESSION_CONNECTED 2
  28. #define NETBIOS_SESSION_ERROR -1
  29. #define NETBIOS_SESSION_REFUSED -2
  30. typedef struct netbios_session_s
  31. {
  32. // The address of the remote peer;
  33. struct sockaddr_in remote_addr;
  34. // The socket of the TCP connection to the HOST'
  35. int socket;
  36. // The current sessions state; See macro before (eg. NETBIOS_SESSION_ERROR)
  37. int state;
  38. // What is the size of the allocated payload;
  39. size_t packet_payload_size;
  40. // Where is the write cursor relative to the beginning of the payload
  41. size_t packet_cursor;
  42. // Our allocated packet, this is where the magic happen (both send and recv :)
  43. netbios_session_packet *packet;
  44. } netbios_session;
  45. // Return NULL if unable to open socket/connect
  46. netbios_session *netbios_session_new(size_t buf_size);
  47. void netbios_session_destroy(netbios_session *);
  48. int netbios_session_connect(struct in_addr *addr,
  49. netbios_session *s,
  50. const char *name,
  51. int direct_tcp);
  52. void netbios_session_packet_init(netbios_session *s);
  53. int netbios_session_packet_append(netbios_session *s,
  54. const char *data, size_t size);
  55. int netbios_session_packet_send(netbios_session *s);
  56. ssize_t netbios_session_packet_recv(netbios_session *s, void **data);
  57. #endif