Add examples.
[novacoin.git] / src / ministun.h
1 /*
2  * ministun.h
3  * Part of the ministun package
4  *
5  * STUN support code borrowed from Asterisk -- An open source telephony toolkit.
6  * Copyright (C) 1999 - 2006, Digium, Inc.
7  * Mark Spencer <markster@digium.com>
8  * Standalone remake (c) 2009 Vladislav Grishenko <themiron@mail.ru>
9  *
10  * This software is licensed under the terms of the GNU General
11  * Public License (GPL). Please see the file COPYING for details.
12  *
13  */
14
15 #define PACKAGE  "ministun"
16 #define VERSION  "0.1"
17
18 #define STUN_SERVER "stun.xten.com"
19 #define STUN_PORT 3478
20 #define STUN_COUNT 3
21 #define STUN_TIMEOUT 3
22
23 #ifndef _MSC_VER
24     typedef struct { unsigned int id[4]; } __attribute__((packed)) stun_trans_id;
25
26     struct stun_header {
27         unsigned short msgtype;
28         unsigned short msglen;
29         stun_trans_id id;
30         unsigned char ies[0];
31     } __attribute__((packed));
32
33     struct stun_attr {
34         unsigned short attr;
35         unsigned short len;
36         unsigned char value[0];
37     } __attribute__((packed));
38
39     /*
40     * The format normally used for addresses carried by STUN messages.
41     */
42
43     struct stun_addr {
44         unsigned char unused;
45         unsigned char family;
46         unsigned short port;
47         unsigned int addr;
48     } __attribute__((packed));
49 #else
50     typedef struct { unsigned int id[4]; } stun_trans_id;
51
52 #pragma pack(push, 1)    
53     struct stun_header {
54         unsigned short msgtype;
55         unsigned short msglen;
56         stun_trans_id id;
57         unsigned char ies[0];
58     };
59 #pragma pack(pop)
60
61 #pragma pack(push, 1)
62     struct stun_attr {
63         unsigned short attr;
64         unsigned short len;
65         unsigned char value[0];
66     };
67 #pragma pack(pop)
68
69     /*
70     * The format normally used for addresses carried by STUN messages.
71     */
72 #pragma pack(push, 1)
73     struct stun_addr {
74         unsigned char unused;
75         unsigned char family;
76         unsigned short port;
77         unsigned int addr;
78     };
79 #pragma pack(pop)
80 #endif
81
82 #define STUN_IGNORE  (0)
83 #define STUN_ACCEPT  (1)
84
85 /* STUN message types
86  * 'BIND' refers to transactions used to determine the externally
87  * visible addresses. 'SEC' refers to transactions used to establish
88  * a session key for subsequent requests.
89  * 'SEC' functionality is not supported here.
90  */
91
92 #define STUN_BINDREQ 0x0001
93 #define STUN_BINDRESP 0x0101
94 #define STUN_BINDERR 0x0111
95 #define STUN_SECREQ 0x0002
96 #define STUN_SECRESP 0x0102
97 #define STUN_SECERR 0x0112
98
99 /* Basic attribute types in stun messages.
100  * Messages can also contain custom attributes (codes above 0x7fff)
101  */
102 #define STUN_MAPPED_ADDRESS 0x0001
103 #define STUN_RESPONSE_ADDRESS 0x0002
104 #define STUN_CHANGE_REQUEST 0x0003
105 #define STUN_SOURCE_ADDRESS 0x0004
106 #define STUN_CHANGED_ADDRESS 0x0005
107 #define STUN_USERNAME  0x0006
108 #define STUN_PASSWORD  0x0007
109 #define STUN_MESSAGE_INTEGRITY 0x0008
110 #define STUN_ERROR_CODE  0x0009
111 #define STUN_UNKNOWN_ATTRIBUTES 0x000a
112 #define STUN_REFLECTED_FROM 0x000b