aboutsummaryrefslogtreecommitdiff
path: root/src/nat/nat_stun.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/nat/nat_stun.h')
-rw-r--r--src/nat/nat_stun.h67
1 files changed, 32 insertions, 35 deletions
diff --git a/src/nat/nat_stun.h b/src/nat/nat_stun.h
index fb5262dfa..85b177271 100644
--- a/src/nat/nat_stun.h
+++ b/src/nat/nat_stun.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * Message types for STUN server resolution 21 * Message types for STUN server resolution
22 * 22 *
@@ -28,18 +28,17 @@
28 */ 28 */
29 29
30 30
31#define STUN_IGNORE (0) 31#define STUN_IGNORE (0)
32#define STUN_ACCEPT (1) 32#define STUN_ACCEPT (1)
33 33
34#define STUN_MAGIC_COOKIE 0x2112A442 34#define STUN_MAGIC_COOKIE 0x2112A442
35 35
36typedef struct { 36typedef struct {
37 uint32_t id[3]; 37 uint32_t id[3];
38} GNUNET_PACKED stun_trans_id; 38} GNUNET_PACKED stun_trans_id;
39 39
40 40
41struct stun_header 41struct stun_header {
42{
43 uint16_t msgtype; 42 uint16_t msgtype;
44 uint16_t msglen; 43 uint16_t msglen;
45 uint32_t magic; 44 uint32_t magic;
@@ -47,8 +46,7 @@ struct stun_header
47} GNUNET_PACKED; 46} GNUNET_PACKED;
48 47
49 48
50struct stun_attr 49struct stun_attr {
51{
52 uint16_t attr; 50 uint16_t attr;
53 uint16_t len; 51 uint16_t len;
54} GNUNET_PACKED; 52} GNUNET_PACKED;
@@ -57,14 +55,13 @@ struct stun_attr
57/** 55/**
58 * The format normally used for addresses carried by STUN messages. 56 * The format normally used for addresses carried by STUN messages.
59 */ 57 */
60struct stun_addr 58struct stun_addr {
61{ 59 uint8_t unused;
62 uint8_t unused;
63 60
64 /** 61 /**
65 * Address family, we expect AF_INET. 62 * Address family, we expect AF_INET.
66 */ 63 */
67 uint8_t family; 64 uint8_t family;
68 65
69 /** 66 /**
70 * Port number. 67 * Port number.
@@ -74,7 +71,7 @@ struct stun_addr
74 /** 71 /**
75 * IPv4 address. Should this be "struct in_addr"? 72 * IPv4 address. Should this be "struct in_addr"?
76 */ 73 */
77 uint32_t addr; 74 uint32_t addr;
78} GNUNET_PACKED; 75} GNUNET_PACKED;
79 76
80 77
@@ -136,10 +133,10 @@ enum StunAttributes {
136 * @return the converted StunClass 133 * @return the converted StunClass
137 */ 134 */
138static enum StunClasses 135static enum StunClasses
139decode_class (int msg) 136decode_class(int msg)
140{ 137{
141 /* Sorry for the magic, but this maps the class according to rfc5245 */ 138 /* Sorry for the magic, but this maps the class according to rfc5245 */
142 return (enum StunClasses) ((msg & 0x0010) >> 4) | ((msg & 0x0100) >> 7); 139 return (enum StunClasses)((msg & 0x0010) >> 4) | ((msg & 0x0100) >> 7);
143} 140}
144 141
145 142
@@ -150,9 +147,9 @@ decode_class (int msg)
150 * @return the converted StunMethod 147 * @return the converted StunMethod
151 */ 148 */
152static enum StunMethods 149static enum StunMethods
153decode_method (int msg) 150decode_method(int msg)
154{ 151{
155 return (enum StunMethods) (msg & 0x000f) | ((msg & 0x00e0) >> 1) | ((msg & 0x3e00) >> 2); 152 return (enum StunMethods)(msg & 0x000f) | ((msg & 0x00e0) >> 1) | ((msg & 0x3e00) >> 2);
156} 153}
157 154
158 155
@@ -164,7 +161,7 @@ decode_method (int msg)
164 */ 161 */
165GNUNET_UNUSED 162GNUNET_UNUSED
166static const char * 163static const char *
167stun_msg2str (int msg) 164stun_msg2str(int msg)
168{ 165{
169 static const struct { 166 static const struct {
170 enum StunClasses value; 167 enum StunClasses value;
@@ -189,25 +186,25 @@ stun_msg2str (int msg)
189 enum StunClasses cvalue; 186 enum StunClasses cvalue;
190 enum StunMethods mvalue; 187 enum StunMethods mvalue;
191 188
192 cvalue = decode_class (msg); 189 cvalue = decode_class(msg);
193 for (unsigned int i = 0; classes[i].name; i++) 190 for (unsigned int i = 0; classes[i].name; i++)
194 if (classes[i].value == cvalue) 191 if (classes[i].value == cvalue)
195 { 192 {
196 msg_class = classes[i].name; 193 msg_class = classes[i].name;
197 break; 194 break;
198 } 195 }
199 mvalue = decode_method (msg); 196 mvalue = decode_method(msg);
200 for (unsigned int i = 0; methods[i].name; i++) 197 for (unsigned int i = 0; methods[i].name; i++)
201 if (methods[i].value == mvalue) 198 if (methods[i].value == mvalue)
202 { 199 {
203 method = methods[i].name; 200 method = methods[i].name;
204 break; 201 break;
205 } 202 }
206 GNUNET_snprintf (result, 203 GNUNET_snprintf(result,
207 sizeof(result), 204 sizeof(result),
208 "%s %s", 205 "%s %s",
209 method ? : "Unknown Method", 206 method ? : "Unknown Method",
210 msg_class ? : "Unknown Class Message"); 207 msg_class ? : "Unknown Class Message");
211 return result; 208 return result;
212} 209}
213 210
@@ -220,7 +217,7 @@ stun_msg2str (int msg)
220 */ 217 */
221GNUNET_UNUSED 218GNUNET_UNUSED
222static const char * 219static const char *
223stun_attr2str (enum StunAttributes msg) 220stun_attr2str(enum StunAttributes msg)
224{ 221{
225 static const struct { 222 static const struct {
226 enum StunAttributes value; 223 enum StunAttributes value;