STUN support. More...
#include "asterisk/network.h"
Go to the source code of this file.
Typedefs | |
typedef int( | stun_cb_f )(struct stun_attr *attr, void *arg) |
callback type to be invoked on stun responses. More... | |
Enumerations | |
enum | ast_stun_result { AST_STUN_IGNORE = 0, AST_STUN_ACCEPT } |
Functions | |
int | ast_stun_handle_packet (int s, struct sockaddr_in *src, unsigned char *data, size_t len, stun_cb_f *stun_cb, void *arg) |
handle an incoming STUN message. More... | |
int | ast_stun_request (int s, struct sockaddr_in *dst, const char *username, struct sockaddr_in *answer) |
Generic STUN request. More... | |
Variables | |
static const int | STANDARD_STUN_PORT = 3478 |
typedef int( stun_cb_f)(struct stun_attr *attr, void *arg) |
enum ast_stun_result |
int ast_stun_handle_packet | ( | int | s, |
struct sockaddr_in * | src, | ||
unsigned char * | data, | ||
size_t | len, | ||
stun_cb_f * | stun_cb, | ||
void * | arg | ||
) |
handle an incoming STUN message.
s | Socket to send any response to. |
src | Address where packet came from. |
data | STUN packet buffer to process. |
len | Length of packet |
stun_cb | If not NULL, callback for each STUN attribute. |
arg | Arg to pass to callback. |
Do some basic sanity checks on packet size and content, try to extract a bit of information, and possibly reply. At the moment this only processes BIND requests, and returns the externally visible address of the request. If a callback is specified, invoke it with the attribute.
AST_STUN_ACCEPT | if responed to a STUN request |
AST_STUN_IGNORE | |
-1 | on error |
Definition at line 264 of file stun.c.
References append_attr_address(), append_attr_string(), ast_debug, AST_STUN_ACCEPT, AST_STUN_IGNORE, ast_verbose(), stun_attr::attr, stun_header::id, stun_header::ies, stun_attr::len, stun_header::msglen, stun_header::msgtype, stun_attr2str(), STUN_BINDREQ, STUN_BINDRESP, STUN_MAPPED_ADDRESS, stun_msg2str(), stun_process_attr(), stun_send(), STUN_USERNAME, switch(), and stun_state::username.
Referenced by ast_rtp_read(), and ast_stun_request().
int ast_stun_request | ( | int | s, |
struct sockaddr_in * | dst, | ||
const char * | username, | ||
struct sockaddr_in * | answer | ||
) |
Generic STUN request.
s | The socket used to send the request. |
dst | If non null, the address of the STUN server. Only needed if the socket is not bound or connected. |
username | If non null, add the username in the request. |
answer | If non null, the function waits for a response and puts here the externally visible address. |
Send a generic STUN request to the server specified, possibly waiting for a reply and filling the answer parameter with the externally visible address. Note that in this case the request will be blocking.
0 | on success. |
<0 | on error. |
>0 | on timeout. |
Definition at line 373 of file stun.c.
References append_attr_string(), ast_debug, ast_poll, ast_stun_handle_packet(), stun_attr::attr, errno, stun_header::id, stun_header::ies, if(), stun_header::msglen, stun_header::msgtype, STUN_BINDERR, STUN_BINDREQ, STUN_BINDRESP, stun_get_mapped(), stun_id_cmp(), stun_req_id(), stun_send(), and STUN_USERNAME.
Referenced by ast_rtp_stun_request(), gtalk_update_externip(), and stun_monitor_request().
|
static |
Definition at line 35 of file stun.h.
Referenced by gtalk_load_config(), and setup_stunaddr().