This code provides some support for doing STUN transactions. More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "nat_stun.h"
#include "gnunet-service-nat_stun.h"
Go to the source code of this file.
Data Structures | |
struct | StunState |
Context for stun_get_mapped(). More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "stun", __VA_ARGS__) |
Functions | |
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. More... | |
int | GNUNET_NAT_stun_handle_packet_ (const void *data, size_t len, struct sockaddr_in *arg) |
Handle an incoming STUN response. More... | |
This code provides some support for doing STUN transactions.
We receive the simplest possible packet as the STUN server and try to respond properly.
All STUN packets start with a simple header made of a type, length (excluding the header) and a 16-byte random transaction id. Following the header we may have zero or more attributes, each structured as a type, length and a value (whose format depends on the type, but often contains addresses). Of course all fields are in network format.
This code was based on ministun.c.
Functions for STUN functionality
Definition in file gnunet-service-nat_stun.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "stun", __VA_ARGS__) |
Definition at line 44 of file gnunet-service-nat_stun.c.
|
static |
Extract the STUN_MAPPED_ADDRESS from the stun response.
This is used as a callback for stun_handle_response when called from stun_request.
[out] | st | pointer where we will set the type |
attr | received stun attribute | |
magic | Magic cookie | |
[out] | arg | pointer to a sockaddr_in where we will set the reported IP and port |
Definition at line 69 of file gnunet-service-nat_stun.c.
References stun_addr::addr, find_typedefs::arg, stun_attr::attr, stun_addr::family, GNUNET_NO, GNUNET_OK, stun_attr::len, stun_addr::port, st, STUN_MAPPED_ADDRESS, STUN_MS_XOR_MAPPED_ADDRESS, STUN_XOR_MAPPED_ADDRESS, and type.
Referenced by GNUNET_NAT_stun_handle_packet_().
int GNUNET_NAT_stun_handle_packet_ | ( | const void * | data, |
size_t | len, | ||
struct sockaddr_in * | arg | ||
) |
Handle an incoming STUN response.
Do some basic sanity checks on packet size and content, try to extract information. At the moment this only processes BIND requests, and returns the externally visible address of the original request.
data | the packet | |
len | the length of the packet in data | |
[out] | arg | sockaddr_in where we will set our discovered address |
Definition at line 126 of file gnunet-service-nat_stun.c.
References find_typedefs::arg, stun_attr::attr, data, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, stun_attr::len, LOG, stun_header::magic, stun_header::msglen, stun_header::msgtype, ret, st, stun_get_mapped(), STUN_MAGIC_COOKIE, and stun_msg2str().
Referenced by handle_stun().