diff options
author | rizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-07-13 16:22:09 +0000 |
---|---|---|
committer | rizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b> | 2007-07-13 16:22:09 +0000 |
commit | 61e1de4b7abf3f8dd7ba7887a28a5a4eaaa0606c (patch) | |
tree | dae29c664c9f07f1ce2e0daf9798b30270777fd4 /include/asterisk/rtp.h | |
parent | e3fad44b06f9b96b72179b64717ffcca50047aaa (diff) |
Small improvement to the STUN support so it can be used by
sockets other than RTP ones.
The main change is a new API function in main/rtp.c (see there
for a description)
int ast_stun_request(int s, struct sockaddr_in *dst,
const char *username, struct sockaddr_in *answer)
which can be used to send an STUN request on a socket, and
optionally wait for a reply and store the STUN_MAPPED_ADDRESS
into the 'answer' argument (obviously, the version that
waits for a reply is blocking, but this is no different
from DNS resolutions).
Internally there are minor modifications to let stun_handle_packet()
be somewhat configurable on how to parse the body of responses.
At the moment i am not committing any change to the clients,
but adding STUN client support is extremely simple, e.g. chan_sip.c
could do something like this:
+ add a variable to store the stun server address;
static struct sockaddr_in stunaddr = { 0, }; /*!< stun server address */
+ add code to parse a config file of the form "stunaddr=my.stun.server.org:3478"
(not shown for brevity);
+ right after binding the main sip socket, talk to the stun server to
determine the externally visible address
if (stunaddr.sin_addr.s_addr != 0)
ast_stun_request(sipsock, &stunaddr, NULL, &externip);
so now 'externip' is set with the externally visible address.
so it is really trivial.
Similarly ast_stun_request could be called when creating the RTP
socket (possibly adding a struct sockaddr_in field in the struct
ast_rtp to store the externalip).
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@75034 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/rtp.h')
-rw-r--r-- | include/asterisk/rtp.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/include/asterisk/rtp.h b/include/asterisk/rtp.h index 492ad9119..8d54cbe88 100644 --- a/include/asterisk/rtp.h +++ b/include/asterisk/rtp.h @@ -211,7 +211,22 @@ void ast_rtp_setdtmfcompensate(struct ast_rtp *rtp, int compensate); /*! \brief Enable STUN capability */ void ast_rtp_setstun(struct ast_rtp *rtp, int stun_enable); -/*! \brief Send STUN request (??) */ +/*! \brief Generic STUN request + * send a generic stun request to the server specified. + * \param s the socket used to send the request + * \param dst the address of the STUN server + * \param username if non null, add the username in the request + * \param answer if non null, the function waits for a response and + * puts here the externally visible address. + * \return 0 on success, other values on error. + * The interface it may change in the future. + */ +int ast_stun_request(int s, struct sockaddr_in *dst, + const char *username, struct sockaddr_in *answer); + +/*! \brief Send STUN request for an RTP socket + * Deprecated, this is just a wrapper for ast_rtp_stun_request() + */ void ast_rtp_stun_request(struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username); /*! \brief The RTP bridge. |