From c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 5 Oct 2019 15:09:28 +0200 Subject: global reindent, now with uncrustify hook enabled --- src/nat/gnunet-service-nat_stun.c | 171 +++++++++++++++++++------------------- 1 file changed, 86 insertions(+), 85 deletions(-) (limited to 'src/nat/gnunet-service-nat_stun.c') diff --git a/src/nat/gnunet-service-nat_stun.c b/src/nat/gnunet-service-nat_stun.c index d8b791d0a..8a5311254 100644 --- a/src/nat/gnunet-service-nat_stun.c +++ b/src/nat/gnunet-service-nat_stun.c @@ -40,14 +40,15 @@ #include "gnunet_util_lib.h" #include "nat_stun.h" -#define LOG(kind, ...) GNUNET_log_from(kind, "stun", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "stun", __VA_ARGS__) /** * Context for #stun_get_mapped(). * Used to store state across processing attributes. */ -struct StunState { +struct StunState +{ uint16_t attr; }; @@ -64,44 +65,44 @@ struct StunState { * @return #GNUNET_OK if @a arg was initialized */ static int -stun_get_mapped(struct StunState *st, - const struct stun_attr *attr, - uint32_t magic, - struct sockaddr_in *arg) +stun_get_mapped (struct StunState *st, + const struct stun_attr *attr, + uint32_t magic, + struct sockaddr_in *arg) { const struct stun_addr *returned_addr; - struct sockaddr_in *sa = (struct sockaddr_in *)arg; - uint16_t type = ntohs(attr->attr); + struct sockaddr_in *sa = (struct sockaddr_in *) arg; + uint16_t type = ntohs (attr->attr); switch (type) - { - case STUN_MAPPED_ADDRESS: - if ((st->attr == STUN_XOR_MAPPED_ADDRESS) || - (st->attr == STUN_MS_XOR_MAPPED_ADDRESS)) - return GNUNET_NO; - magic = 0; - break; + { + case STUN_MAPPED_ADDRESS: + if ((st->attr == STUN_XOR_MAPPED_ADDRESS) || + (st->attr == STUN_MS_XOR_MAPPED_ADDRESS)) + return GNUNET_NO; + magic = 0; + break; - case STUN_MS_XOR_MAPPED_ADDRESS: - if (st->attr == STUN_XOR_MAPPED_ADDRESS) - return GNUNET_NO; - break; + case STUN_MS_XOR_MAPPED_ADDRESS: + if (st->attr == STUN_XOR_MAPPED_ADDRESS) + return GNUNET_NO; + break; - case STUN_XOR_MAPPED_ADDRESS: - break; + case STUN_XOR_MAPPED_ADDRESS: + break; - default: - return GNUNET_NO; - } + default: + return GNUNET_NO; + } - if (ntohs(attr->len) < sizeof(struct stun_addr)) + if (ntohs (attr->len) < sizeof(struct stun_addr)) return GNUNET_NO; - returned_addr = (const struct stun_addr *)(attr + 1); + returned_addr = (const struct stun_addr *) (attr + 1); if (AF_INET != returned_addr->family) return GNUNET_NO; st->attr = type; sa->sin_family = AF_INET; - sa->sin_port = returned_addr->port ^ htons(ntohl(magic) >> 16); + sa->sin_port = returned_addr->port ^ htons (ntohl (magic) >> 16); sa->sin_addr.s_addr = returned_addr->addr ^ magic; return GNUNET_OK; } @@ -121,9 +122,9 @@ stun_get_mapped(struct StunState *st, * #GNUNET_NO if the packet is invalid (not a stun packet) */ int -GNUNET_NAT_stun_handle_packet_(const void *data, - size_t len, - struct sockaddr_in *arg) +GNUNET_NAT_stun_handle_packet_ (const void *data, + size_t len, + struct sockaddr_in *arg) { const struct stun_header *hdr; const struct stun_attr *attr; @@ -137,76 +138,76 @@ GNUNET_NAT_stun_handle_packet_(const void *data, * while 'data' is advanced accordingly. */ if (len < sizeof(struct stun_header)) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Packet too short to be a STUN packet\n"); - return GNUNET_NO; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Packet too short to be a STUN packet\n"); + return GNUNET_NO; + } hdr = data; /* Skip header as it is already in hdr */ len -= sizeof(struct stun_header); data += sizeof(struct stun_header); /* len as advertised in the message */ - advertised_message_size = ntohs(hdr->msglen); - message_magic_cookie = ntohl(hdr->magic); + advertised_message_size = ntohs (hdr->msglen); + message_magic_cookie = ntohl (hdr->magic); /* Compare if the cookie match */ if (STUN_MAGIC_COOKIE != message_magic_cookie) - { - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Invalid magic cookie for STUN packet\n"); - return GNUNET_NO; - } + { + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Invalid magic cookie for STUN packet\n"); + return GNUNET_NO; + } - LOG(GNUNET_ERROR_TYPE_INFO, - "STUN Packet, msg %s (%04x), length: %d\n", - stun_msg2str(ntohs(hdr->msgtype)), - ntohs(hdr->msgtype), - advertised_message_size); + LOG (GNUNET_ERROR_TYPE_INFO, + "STUN Packet, msg %s (%04x), length: %d\n", + stun_msg2str (ntohs (hdr->msgtype)), + ntohs (hdr->msgtype), + advertised_message_size); if (advertised_message_size > len) - { - LOG(GNUNET_ERROR_TYPE_INFO, - "Scrambled STUN packet length (got %d, expecting %d)\n", - advertised_message_size, - (int)len); - return GNUNET_NO; - } + { + LOG (GNUNET_ERROR_TYPE_INFO, + "Scrambled STUN packet length (got %d, expecting %d)\n", + advertised_message_size, + (int) len); + return GNUNET_NO; + } len = advertised_message_size; - memset(&st, 0, sizeof(st)); + memset (&st, 0, sizeof(st)); while (len > 0) + { + if (len < sizeof(struct stun_attr)) { - if (len < sizeof(struct stun_attr)) - { - LOG(GNUNET_ERROR_TYPE_INFO, - "Attribute too short (got %d, expecting %d)\n", - (int)len, - (int)sizeof(struct stun_attr)); - break; - } - attr = (const struct stun_attr *)data; - - /* compute total attribute length */ - advertised_message_size = ntohs(attr->len) + sizeof(struct stun_attr); - - /* Check if we still have space in our buffer */ - if (advertised_message_size > len) - { - LOG(GNUNET_ERROR_TYPE_INFO, - "Inconsistent attribute (length %d exceeds remaining msg len %d)\n", - advertised_message_size, - (int)len); - break; - } - if (GNUNET_OK == - stun_get_mapped(&st, - attr, - hdr->magic, - arg)) - ret = GNUNET_OK; - data += advertised_message_size; - len -= advertised_message_size; + LOG (GNUNET_ERROR_TYPE_INFO, + "Attribute too short (got %d, expecting %d)\n", + (int) len, + (int) sizeof(struct stun_attr)); + break; + } + attr = (const struct stun_attr *) data; + + /* compute total attribute length */ + advertised_message_size = ntohs (attr->len) + sizeof(struct stun_attr); + + /* Check if we still have space in our buffer */ + if (advertised_message_size > len) + { + LOG (GNUNET_ERROR_TYPE_INFO, + "Inconsistent attribute (length %d exceeds remaining msg len %d)\n", + advertised_message_size, + (int) len); + break; } + if (GNUNET_OK == + stun_get_mapped (&st, + attr, + hdr->magic, + arg)) + ret = GNUNET_OK; + data += advertised_message_size; + len -= advertised_message_size; + } return ret; } -- cgit v1.2.3