Switch GetMyExternalIP from HTTP request to STUN approach
[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 typedef struct { unsigned int id[4]; } __attribute__((packed)) stun_trans_id;
24
25 struct stun_header {
26     unsigned short msgtype;
27     unsigned short msglen;
28     stun_trans_id  id;
29     unsigned char  ies[0];
30 } __attribute__((packed));
31
32 struct stun_attr {
33     unsigned short attr;
34     unsigned short len;
35     unsigned char  value[0];
36 } __attribute__((packed));
37
38 /*
39  * The format normally used for addresses carried by STUN messages.
40  */
41 struct stun_addr {
42     unsigned char  unused;
43     unsigned char  family;
44     unsigned short port;
45     unsigned int   addr;
46 } __attribute__((packed));
47
48 #define STUN_IGNORE  (0)
49 #define STUN_ACCEPT  (1)
50
51 /* STUN message types
52  * 'BIND' refers to transactions used to determine the externally
53  * visible addresses. 'SEC' refers to transactions used to establish
54  * a session key for subsequent requests.
55  * 'SEC' functionality is not supported here.
56  */
57
58 #define STUN_BINDREQ 0x0001
59 #define STUN_BINDRESP 0x0101
60 #define STUN_BINDERR 0x0111
61 #define STUN_SECREQ 0x0002
62 #define STUN_SECRESP 0x0102
63 #define STUN_SECERR 0x0112
64
65 /* Basic attribute types in stun messages.
66  * Messages can also contain custom attributes (codes above 0x7fff)
67  */
68 #define STUN_MAPPED_ADDRESS 0x0001
69 #define STUN_RESPONSE_ADDRESS 0x0002
70 #define STUN_CHANGE_REQUEST 0x0003
71 #define STUN_SOURCE_ADDRESS 0x0004
72 #define STUN_CHANGED_ADDRESS 0x0005
73 #define STUN_USERNAME  0x0006
74 #define STUN_PASSWORD  0x0007
75 #define STUN_MESSAGE_INTEGRITY 0x0008
76 #define STUN_ERROR_CODE  0x0009
77 #define STUN_UNKNOWN_ATTRIBUTES 0x000a
78 #define STUN_REFLECTED_FROM 0x000b