This code provides some support for doing STUN transactions. More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
#include "gnunet_nat_service.h"
#include "nat_stun.h"
Go to the source code of this file.
Data Structures | |
struct | GNUNET_NAT_STUN_Handle |
Handle to a request given to the resolver. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "stun", __VA_ARGS__) |
#define | TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
Functions | |
static int | encode_message (enum StunClasses msg_class, enum StunMethods method) |
Encode a class and method to a compatible STUN format. More... | |
static void | generate_request_id (struct stun_header *req) |
Fill the stun_header with a random request_id. More... | |
static void | stun_dns_callback (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
Try to establish a connection given the specified address. More... | |
struct GNUNET_NAT_STUN_Handle * | GNUNET_NAT_stun_make_request (const char *server, uint16_t port, struct GNUNET_NETWORK_Handle *sock, GNUNET_NAT_TestCallback cb, void *cb_cls) |
Make Generic STUN request. More... | |
void | GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh) |
Cancel active STUN request. More... | |
This code provides some support for doing STUN transactions.
We send simplest possible packet ia REQUEST with BIND to a STUN server.
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 nat_api_stun.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "stun", __VA_ARGS__) |
Definition at line 46 of file nat_api_stun.c.
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
Definition at line 48 of file nat_api_stun.c.
|
static |
Encode a class and method to a compatible STUN format.
msg_class | class to be converted |
method | method to be converted |
Definition at line 103 of file nat_api_stun.c.
Referenced by stun_dns_callback().
|
static |
Fill the stun_header with a random request_id.
req | stun header to be filled |
Definition at line 118 of file nat_api_stun.c.
References GNUNET_CRYPTO_QUALITY_NONCE, GNUNET_CRYPTO_random_u32(), stun_trans_id::id, stun_header::id, stun_header::magic, and STUN_MAGIC_COOKIE.
Referenced by stun_dns_callback().
|
static |
Try to establish a connection given the specified address.
cls | our struct GNUNET_NAT_STUN_Handle * |
addr | address to try, NULL for "last call" |
addrlen | length of addr |
Definition at line 135 of file nat_api_stun.c.
References GNUNET_NAT_STUN_Handle::cb, GNUNET_NAT_STUN_Handle::cb_cls, GNUNET_NAT_STUN_Handle::dns_active, GNUNET_NAT_STUN_Handle::dns_success, encode_message(), generate_request_id(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log_strerror, GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, GNUNET_NAT_ERROR_NOT_ONLINE, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_stun_make_request_cancel(), GNUNET_NETWORK_socket_sendto(), GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, LOG, stun_header::msglen, stun_header::msgtype, GNUNET_NAT_STUN_Handle::sock, STUN_BINDING, GNUNET_NAT_STUN_Handle::stun_port, STUN_REQUEST, and GNUNET_NAT_STUN_Handle::stun_server.
Referenced by GNUNET_NAT_stun_make_request().