netbios_session.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // This file is part of libdsm
  2. // Author: Julien 'Lta' BALLET <contact@lta.io>
  3. // Copyright VideoLabs 2014
  4. // License: MIT License
  5. #ifndef __BDSM_NETBIOS_SESSION_H_
  6. #define __BDSM_NETBIOS_SESSION_H_
  7. #include <stdint.h>
  8. #include <stddef.h>
  9. #include <sys/socket.h>
  10. #include <netinet/in.h>
  11. #include "bdsm/netbios_defs.h"
  12. #define NETBIOS_SESSION_NEW 0
  13. #define NETBIOS_SESSION_CONNECTING 1
  14. #define NETBIOS_SESSION_CONNECTED 2
  15. #define NETBIOS_SESSION_ERROR -1
  16. #define NETBIOS_SESSION_REFUSED -2
  17. #define NETBIOS_SESSION_BUFFER 2048
  18. #define NETBIOS_SESSION_PAYLOAD NETBIOS_SESSION_BUFFER
  19. typedef struct netbios_session_s {
  20. // The address of the remote peer;
  21. struct sockaddr_in remote_addr;
  22. // The socket of the TCP connection to the HOST'
  23. int socket;
  24. // The current sessions state; See macro before (eg. NETBIOS_SESSION_ERROR)
  25. int state;
  26. // What is the size of the allocated payload;
  27. size_t packet_payload_size;
  28. // Where is the write cursor relative to the beginning of the payload
  29. size_t packet_cursor;
  30. // Our allocated packet, this is where the magic happen :)
  31. netbios_session_packet_t *packet;
  32. // Some buffer space to receive message from peer;
  33. uint8_t recv_buffer[NETBIOS_SESSION_BUFFER];
  34. } netbios_session_t;
  35. // Return NULL if unable to open socket/connect
  36. netbios_session_t *netbios_session_new(uint32_t ip_addr);
  37. void netbios_session_destroy(netbios_session_t *);
  38. int netbios_session_connect(netbios_session_t *s, char *name);
  39. void netbios_session_packet_init(netbios_session_t *s,
  40. uint8_t opcode);
  41. int netbios_session_packet_append(netbios_session_t *s,
  42. char *data, size_t size);
  43. int netbios_session_packet_send(netbios_session_t *s);
  44. ssize_t netbios_session_packet_recv(netbios_session_t *s);
  45. #endif