44#define LOG(kind, ...) GNUNET_log_from (kind, "stun", __VA_ARGS__)
72 struct sockaddr_in *
arg)
75 struct sockaddr_in *sa = (
struct sockaddr_in *)
arg;
101 returned_addr = (
const struct stun_addr *) (attr + 1);
102 if (AF_INET != returned_addr->
family)
105 sa->sin_family = AF_INET;
106 sa->sin_port = returned_addr->
port ^ htons (ntohl (magic) >> 16);
107 sa->sin_addr.s_addr = returned_addr->
addr ^ magic;
128 struct sockaddr_in *
arg)
133 uint32_t advertised_message_size;
134 uint32_t message_magic_cookie;
144 "Packet too short to be a STUN packet\n");
153 advertised_message_size = ntohs (hdr->
msglen);
154 message_magic_cookie = ntohl (hdr->
magic);
159 "Invalid magic cookie for STUN packet\n");
164 "STUN Packet, msg %s (%04x), length: %d\n",
167 advertised_message_size);
168 if (advertised_message_size > len)
171 "Scrambled STUN packet length (got %d, expecting %d)\n",
172 advertised_message_size,
176 len = advertised_message_size;
177 memset (&
st, 0,
sizeof(
st));
184 "Attribute too short (got %d, expecting %d)\n",
192 advertised_message_size = ntohs (
attr->len) +
sizeof(
struct stun_attr);
195 if (advertised_message_size >
len)
198 "Inconsistent attribute (length %d exceeds remaining msg len %d)\n",
199 advertised_message_size,
209 data += advertised_message_size;
210 len -= advertised_message_size;
static int ret
Final status code.
static struct GNUNET_SCHEDULER_Task * st
The shutdown task.
static char * data
The data to insert into the dht.
static uint32_t type
Type string converted to DNS type value.
int GNUNET_NAT_stun_handle_packet_(const void *data, size_t len, struct sockaddr_in *arg)
Handle an incoming STUN response.
static int stun_get_mapped(struct StunState *st, const struct stun_attr *attr, uint32_t magic, struct sockaddr_in *arg)
Extract the STUN_MAPPED_ADDRESS from the stun response.
This code provides some support for doing STUN transactions.
@ GNUNET_ERROR_TYPE_DEBUG
Message types for STUN server resolution.
#define STUN_MAGIC_COOKIE
static const char * stun_msg2str(int msg)
Print a class and method from a STUN message.
@ STUN_MS_XOR_MAPPED_ADDRESS
@ STUN_XOR_MAPPED_ADDRESS
Context for stun_get_mapped().
The format normally used for addresses carried by STUN messages.
uint8_t family
Address family, we expect AF_INET.
uint32_t addr
IPv4 address.
uint16_t port
Port number.