netbios_defs.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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_DEFS_H_
  19. #define __BDSM_NETBIOS_DEFS_H_
  20. #include <stdint.h>
  21. #define NETBIOS_PORT_NAME 137 // UDP
  22. #define NETBIOS_PORT_SESSION 139 // TCP
  23. #define NETBIOS_NAME_LENGTH 15
  24. // Netbios name types
  25. #define NETBIOS_WORKSTATION 0x00
  26. #define NETBIOS_MESSENGER 0x03
  27. #define NETBIOS_FILESERVER 0x20
  28. #define NETBIOS_DOMAINMASTER 0x1b
  29. // http://ubiqx.org/cifs/rfc-draft/rfc1001.html#s17.2
  30. #define NETBIOS_WILDCARD { 32, 'C', 'K', 'A', 'A', 'A', 'A', 'A', 'A', \
  31. 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', \
  32. 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 0 }
  33. #define NETBIOS_FLAG_QUERY (1 << 15)
  34. #define NETBIOS_FLAG_TRUNCATED (1 << 9)
  35. #define NETBIOS_FLAG_RECURSIVE (1 << 8)
  36. #define NETBIOS_FLAG_BROADCAST (1 << 4)
  37. // Name Service Query
  38. #define NETBIOS_OP_NAME_QUERY 0x00
  39. // Session Service
  40. #define NETBIOS_OP_SESSION_MSG 0x00
  41. #define NETBIOS_OP_SESSION_REQ 0x81
  42. #define NETBIOS_OP_SESSION_REQ_OK 0x82
  43. #define NETBIOS_OP_SESSION_REQ_NOK 0x83
  44. #define NETBIOS_OP_SESSION_RETARGET 0x84
  45. #define NETBIOS_OP_SESSION_KEEPALIVE 0x85
  46. typedef struct
  47. {
  48. uint16_t trn_id; // Transaction ID
  49. uint16_t flags; // Various flags
  50. uint16_t queries; // Number of queries in this packet
  51. uint16_t answers; // Number of answers
  52. uint16_t ns_count; // Number of authorities (?)
  53. uint16_t ar_count; // Additionnal (??)
  54. char payload[];
  55. } __attribute__((packed)) netbios_query_packet;
  56. typedef struct
  57. {
  58. uint8_t opcode; // 'TYPE'
  59. uint8_t flags; // 0-6 reserved (== 0), byte 7 is the
  60. // beginning of the length field (!!)
  61. uint16_t length; // payload length;
  62. uint8_t payload[];
  63. } __attribute__((packed)) netbios_session_packet;
  64. #endif