diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-11-30 07:31:09 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-11-30 07:31:09 +0100 |
commit | 1b4333f3a6a4f76aa76fc3abc21e8476ea0a92e3 (patch) | |
tree | 86bbecfcd30d250ab5a123c793595f8ff6ff33b1 /src/nat/nat_stun.c | |
parent | 27068700bceca89cd940816a7b5cd03933d3cc0b (diff) | |
download | gnunet-1b4333f3a6a4f76aa76fc3abc21e8476ea0a92e3.tar.gz gnunet-1b4333f3a6a4f76aa76fc3abc21e8476ea0a92e3.zip |
towards moving STUN logic into new NAT service
Diffstat (limited to 'src/nat/nat_stun.c')
-rw-r--r-- | src/nat/nat_stun.c | 126 |
1 files changed, 0 insertions, 126 deletions
diff --git a/src/nat/nat_stun.c b/src/nat/nat_stun.c index b914abb2e..62916ab84 100644 --- a/src/nat/nat_stun.c +++ b/src/nat/nat_stun.c | |||
@@ -104,32 +104,6 @@ struct StunState | |||
104 | 104 | ||
105 | 105 | ||
106 | /** | 106 | /** |
107 | * Convert a message to a StunClass | ||
108 | * | ||
109 | * @param msg the received message | ||
110 | * @return the converted StunClass | ||
111 | */ | ||
112 | static int | ||
113 | decode_class(int msg) | ||
114 | { | ||
115 | /* Sorry for the magic, but this maps the class according to rfc5245 */ | ||
116 | return ((msg & 0x0010) >> 4) | ((msg & 0x0100) >> 7); | ||
117 | } | ||
118 | |||
119 | /** | ||
120 | * Convert a message to a StunMethod | ||
121 | * | ||
122 | * @param msg the received message | ||
123 | * @return the converted StunMethod | ||
124 | */ | ||
125 | static int | ||
126 | decode_method(int msg) | ||
127 | { | ||
128 | return (msg & 0x000f) | ((msg & 0x00e0) >> 1) | ((msg & 0x3e00) >> 2); | ||
129 | } | ||
130 | |||
131 | |||
132 | /** | ||
133 | * Encode a class and method to a compatible STUN format | 107 | * Encode a class and method to a compatible STUN format |
134 | * | 108 | * |
135 | * @param msg_class class to be converted | 109 | * @param msg_class class to be converted |
@@ -146,106 +120,6 @@ encode_message (enum StunClasses msg_class, | |||
146 | 120 | ||
147 | 121 | ||
148 | /** | 122 | /** |
149 | * Print a class and method from a STUN message | ||
150 | * | ||
151 | * @param msg | ||
152 | * @return string with the message class and method | ||
153 | */ | ||
154 | static const char * | ||
155 | stun_msg2str(int msg) | ||
156 | { | ||
157 | static const struct { | ||
158 | enum StunClasses value; | ||
159 | const char *name; | ||
160 | } classes[] = { | ||
161 | { STUN_REQUEST, "Request" }, | ||
162 | { STUN_INDICATION, "Indication" }, | ||
163 | { STUN_RESPONSE, "Response" }, | ||
164 | { STUN_ERROR_RESPONSE, "Error Response" }, | ||
165 | { 0, NULL } | ||
166 | }; | ||
167 | static const struct { | ||
168 | enum StunMethods value; | ||
169 | const char *name; | ||
170 | } methods[] = { | ||
171 | { STUN_BINDING, "Binding" }, | ||
172 | { 0, NULL } | ||
173 | }; | ||
174 | static char result[32]; | ||
175 | const char *msg_class = NULL; | ||
176 | const char *method = NULL; | ||
177 | int i; | ||
178 | int value; | ||
179 | |||
180 | value = decode_class(msg); | ||
181 | for (i = 0; classes[i].name; i++) | ||
182 | { | ||
183 | msg_class = classes[i].name; | ||
184 | if (classes[i].value == value) | ||
185 | break; | ||
186 | } | ||
187 | value = decode_method(msg); | ||
188 | for (i = 0; methods[i].name; i++) | ||
189 | { | ||
190 | method = methods[i].name; | ||
191 | if (methods[i].value == value) | ||
192 | break; | ||
193 | } | ||
194 | GNUNET_snprintf (result, | ||
195 | sizeof(result), | ||
196 | "%s %s", | ||
197 | method ? : "Unknown Method", | ||
198 | msg_class ? : "Unknown Class Message"); | ||
199 | return result; | ||
200 | } | ||
201 | |||
202 | |||
203 | /** | ||
204 | * Print attribute name | ||
205 | * | ||
206 | * @param msg with a attribute type | ||
207 | * @return string with the attribute name | ||
208 | */ | ||
209 | static const char * | ||
210 | stun_attr2str (int msg) | ||
211 | { | ||
212 | static const struct { | ||
213 | enum StunAttributes value; | ||
214 | const char *name; | ||
215 | } attrs[] = { | ||
216 | { STUN_MAPPED_ADDRESS, "Mapped Address" }, | ||
217 | { STUN_RESPONSE_ADDRESS, "Response Address" }, | ||
218 | { STUN_CHANGE_ADDRESS, "Change Address" }, | ||
219 | { STUN_SOURCE_ADDRESS, "Source Address" }, | ||
220 | { STUN_CHANGED_ADDRESS, "Changed Address" }, | ||
221 | { STUN_USERNAME, "Username" }, | ||
222 | { STUN_PASSWORD, "Password" }, | ||
223 | { STUN_MESSAGE_INTEGRITY, "Message Integrity" }, | ||
224 | { STUN_ERROR_CODE, "Error Code" }, | ||
225 | { STUN_UNKNOWN_ATTRIBUTES, "Unknown Attributes" }, | ||
226 | { STUN_REFLECTED_FROM, "Reflected From" }, | ||
227 | { STUN_REALM, "Realm" }, | ||
228 | { STUN_NONCE, "Nonce" }, | ||
229 | { STUN_XOR_MAPPED_ADDRESS, "XOR Mapped Address" }, | ||
230 | { STUN_MS_VERSION, "MS Version" }, | ||
231 | { STUN_MS_XOR_MAPPED_ADDRESS, "MS XOR Mapped Address" }, | ||
232 | { STUN_SOFTWARE, "Software" }, | ||
233 | { STUN_ALTERNATE_SERVER, "Alternate Server" }, | ||
234 | { STUN_FINGERPRINT, "Fingerprint" }, | ||
235 | { 0, NULL } | ||
236 | }; | ||
237 | unsigned int i; | ||
238 | |||
239 | for (i = 0; attrs[i].name; i++) | ||
240 | { | ||
241 | if (attrs[i].value == msg) | ||
242 | return attrs[i].name; | ||
243 | } | ||
244 | return "Unknown Attribute"; | ||
245 | } | ||
246 | |||
247 | |||
248 | /** | ||
249 | * Fill the stun_header with a random request_id | 123 | * Fill the stun_header with a random request_id |
250 | * | 124 | * |
251 | * @param req, stun header to be filled | 125 | * @param req, stun header to be filled |