/*
This file is part of GNUnet.
- Copyright (C) 2009, 2015 GNUnet e.V.
+ Copyright (C) 2009, 2015, 2016 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
* Port number.
*/
uint16_t port;
-
+
/**
* IPv4 address. Should this be "struct in_addr"?
*/
/**
- * STUN message classes
+ * STUN message classes
*/
enum StunClasses {
INVALID_CLASS = 0,
* @param msg the received message
* @return the converted StunClass
*/
-static int
-decode_class(int msg)
+static enum StunClasses
+decode_class (int msg)
{
/* Sorry for the magic, but this maps the class according to rfc5245 */
- return ((msg & 0x0010) >> 4) | ((msg & 0x0100) >> 7);
+ return (enum StunClasses) ((msg & 0x0010) >> 4) | ((msg & 0x0100) >> 7);
}
+
/**
* Convert a message to a StunMethod
*
* @param msg the received message
* @return the converted StunMethod
*/
-static int
-decode_method(int msg)
+static enum StunMethods
+decode_method (int msg)
{
- return (msg & 0x000f) | ((msg & 0x00e0) >> 1) | ((msg & 0x3e00) >> 2);
+ return (enum StunMethods) (msg & 0x000f) | ((msg & 0x00e0) >> 1) | ((msg & 0x3e00) >> 2);
}
* @param msg
* @return string with the message class and method
*/
+GNUNET_UNUSED
static const char *
stun_msg2str (int msg)
{
{ STUN_INDICATION, "Indication" },
{ STUN_RESPONSE, "Response" },
{ STUN_ERROR_RESPONSE, "Error Response" },
- { 0, NULL }
+ { INVALID_CLASS, NULL }
};
static const struct {
enum StunMethods value;
const char *name;
} methods[] = {
{ STUN_BINDING, "Binding" },
- { 0, NULL }
+ { INVALID_METHOD, NULL }
};
static char result[64];
const char *msg_class = NULL;
const char *method = NULL;
- int value;
+ enum StunClasses cvalue;
+ enum StunMethods mvalue;
- value = decode_class (msg);
+ cvalue = decode_class (msg);
for (unsigned int i = 0; classes[i].name; i++)
- if (classes[i].value == value)
+ if (classes[i].value == cvalue)
{
msg_class = classes[i].name;
break;
}
- value = decode_method (msg);
+ mvalue = decode_method (msg);
for (unsigned int i = 0; methods[i].name; i++)
- if (methods[i].value == value)
+ if (methods[i].value == mvalue)
{
method = methods[i].name;
break;
* @param msg with a attribute type
* @return string with the attribute name
*/
+GNUNET_UNUSED
static const char *
stun_attr2str (enum StunAttributes msg)
{