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