netbios_ns.h 2.8 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_NS_H_
  19. #define __BDSM_NETBIOS_NS_H_
  20. #include "bdsm/netbios_defs.h"
  21. #include "bdsm/netbios_query.h"
  22. #include <sys/socket.h>
  23. #include <netinet/ip.h>
  24. #include <netinet/udp.h>
  25. typedef struct netbios_ns_entry_s
  26. {
  27. struct netbios_ns_entry_s *next;
  28. struct in_addr address;
  29. char name[NETBIOS_NAME_LENGTH + 2];
  30. } netbios_ns_entry_t;
  31. typedef struct {
  32. int socket;
  33. struct sockaddr_in addr;
  34. uint16_t last_trn_id; // Last transaction id used;
  35. netbios_ns_entry_t *entries; // Only used during discovery;
  36. } netbios_ns_t;
  37. netbios_ns_t *netbios_ns_new();
  38. void netbios_ns_destroy(netbios_ns_t *ns);
  39. int netbios_ns_resolve(netbios_ns_t *ns, const char *name, char type, uint32_t * addr);
  40. int netbios_ns_discover(netbios_ns_t *ns);
  41. int netbios_ns_inverse(netbios_ns_t *ns, netbios_ns_entry_t *entry);
  42. int netbios_ns_send_query(netbios_ns_t *ns, netbios_query_t *q,
  43. uint32_t ip);
  44. ssize_t netbios_ns_recv(int sock, void *buf, size_t buf_size,
  45. struct timeval *timeout, struct sockaddr *addr,
  46. socklen_t *addr_len);
  47. // Remove all the entry from the name service
  48. void netbios_ns_entry_clear(netbios_ns_t *ns);
  49. // Add an entry to the nameservice list with name and/or ip
  50. netbios_ns_entry_t *netbios_ns_entry_add(netbios_ns_t *ns, const char *name,
  51. uint32_t ip);
  52. // Find an entry in the list. Search by name if name is not NULL,
  53. // or by ip otherwise
  54. netbios_ns_entry_t *netbios_ns_entry_find(netbios_ns_t *ns, const char *by_name,
  55. uint32_t ip);
  56. #endif