2
0

stun.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef __UNETD_STUN_H
  2. #define __UNETD_STUN_H
  3. #include <stdint.h>
  4. #include <stdbool.h>
  5. #define STUN_MSGTYPE_BINDING_REQUEST 0x0001
  6. #define STUN_MSGTYPE_BINDING_RESPONSE 0x0101
  7. #define STUN_MSGTYPE_BINDING_ERROR 0x0111
  8. #define STUN_MSGTYPE_BINDING_INDICATION 0x0011
  9. #define STUN_MSGTYPE_SHARED_SECRET_REQUEST 0x0002
  10. #define STUN_MSGTYPE_SHARED_SECRET_RESPONSE 0x0102
  11. #define STUN_MSGTYPE_SHARED_SECRET_ERROR 0x0112
  12. #define STUN_MAGIC 0x2112a442
  13. enum tlv_type {
  14. STUN_TLV_MAPPED_ADDRESS = 0x01,
  15. STUN_TLV_RESPONSE_ADDRESS = 0x02,
  16. STUN_TLV_CHANGE_REQUEST = 0x03,
  17. STUN_TLV_SOURCE_ADDRESS = 0x04,
  18. STUN_TLV_CHANGED_ADDRESS = 0x05,
  19. STUN_TLV_XOR_MAPPED_ADDRESS = 0x20,
  20. STUN_TLV_RESPONSE_PORT = 0x27,
  21. };
  22. struct stun_msg_hdr {
  23. uint16_t msg_type;
  24. uint16_t msg_len;
  25. uint32_t magic;
  26. uint8_t transaction[12];
  27. };
  28. struct stun_msg_tlv {
  29. uint16_t type;
  30. uint16_t len;
  31. };
  32. struct stun_tlv_policy {
  33. uint16_t type;
  34. uint16_t min_len;
  35. };
  36. struct stun_request {
  37. uint8_t transaction[12];
  38. uint16_t port;
  39. bool pending;
  40. };
  41. bool stun_msg_is_valid(const void *data, size_t len);
  42. const void *stun_msg_request_prepare(struct stun_request *req, size_t *len,
  43. uint16_t response_port);
  44. bool stun_msg_request_complete(struct stun_request *req, const void *data,
  45. size_t len);
  46. #endif