[asterisk-dev] [svn-commits] seanbright: trunk r357005 - in /trunk: channels/ include/asterisk/ main/

Mark Michelson mmichelson at digium.com
Mon Feb 27 10:48:19 CST 2012


On 02/27/2012 10:31 AM, SVN commits to the Digium repositories wrote:

Please place changes of this magnitude on review board prior to 
committing. See in-line for comments.
> Author: seanbright
> Date: Mon Feb 27 10:31:24 2012
> New Revision: 357005
>
> URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=357005
> Log:
> Convert netsock.h over to use ast_sockaddrs rather than sockaddr_in and update
> chan_iax2 to pass in the correct types.
>
> chan_iax2 is the only consumer for the various ast_netsock_* functions in trunk
> at this point, so this feels like a safe change to make.
>
> Modified:
>      trunk/channels/chan_iax2.c
>      trunk/include/asterisk/netsock.h
>      trunk/main/netsock.c
>
> Modified: trunk/channels/chan_iax2.c
> URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=357005&r1=357004&r2=357005
> ==============================================================================
> --- trunk/channels/chan_iax2.c (original)
> +++ trunk/channels/chan_iax2.c Mon Feb 27 10:31:24 2012
> @@ -12266,19 +12266,17 @@
>   /*! \brief Check if address can be used as packet source.
>    \return 0  address available, 1  address unavailable, -1  error
>   */
> -static int check_srcaddr(struct sockaddr *sa, socklen_t salen)
> +static int check_srcaddr(struct ast_sockaddr *addr)
>   {
>   	int sd;
> -	int res;
> -
> -	sd = socket(AF_INET, SOCK_DGRAM, 0);
> +
> +	sd = socket(ast_sockaddr_is_ipv4(addr) ? AF_INET : AF_INET6, SOCK_DGRAM, 0);

Two things:

1. The IAX2 protocol does not support IPv6 at all, so you should remove 
code from here that would allow for us to bind to an IPv6 address.
2. For future reference, if you want to change the family based on the 
addr, you can just use addr->ss.ss_family instead of using the ternary 
logic you have here.

>   	if (sd<  0) {
>   		ast_log(LOG_ERROR, "Socket: %s\n", strerror(errno));
>   		return -1;
>   	}
>
> -	res = bind(sd, sa, salen);
> -	if (res<  0) {
> +	if (ast_bind(sd, addr)<  0) {
>   		ast_debug(1, "Can't bind: %s\n", strerror(errno));
>   		close(sd);
>   		return 1;
> @@ -12293,19 +12291,18 @@
>     not found. */
>   static int peer_set_srcaddr(struct iax2_peer *peer, const char *srcaddr)
>   {
> -	struct sockaddr_in sin;
> -	struct ast_sockaddr sin_tmp;
> +	struct ast_sockaddr addr;
>   	int nonlocal = 1;
>   	int port = IAX_DEFAULT_PORTNO;
>   	int sockfd = defaultsockfd;
>   	char *tmp;
> -	char *addr;
> +	char *host;
>   	char *portstr;
>
>   	if (!(tmp = ast_strdupa(srcaddr)))
>   		return -1;
>
> -	addr = strsep(&tmp, ":");
> +	host = strsep(&tmp, ":");

Use ast_sockaddr_split_hostport().

[remainder snipped]

Mark Michelson



More information about the asterisk-dev mailing list