mirror of
https://github.com/asterisk/asterisk.git
synced 2026-06-09 03:45:27 +00:00
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: https://origsvn.digium.com/svn/asterisk/trunk@75034 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user