[asterisk-commits] mmichelson: branch group/v6-new r268733 - /team/group/v6-new/main/netsock2.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 7 14:04:22 CDT 2010


Author: mmichelson
Date: Mon Jun  7 14:04:19 2010
New Revision: 268733

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=268733
Log:
Fix a few coding guidelines issues in netsock2.c

* Added spaces after if, switch, and for
* Added curly braces to one-line if statements
* Changed some odd spacing in variable declarations in one function.


Modified:
    team/group/v6-new/main/netsock2.c

Modified: team/group/v6-new/main/netsock2.c
URL: http://svnview.digium.com/svn/asterisk/team/group/v6-new/main/netsock2.c?view=diff&rev=268733&r1=268732&r2=268733
==============================================================================
--- team/group/v6-new/main/netsock2.c (original)
+++ team/group/v6-new/main/netsock2.c Mon Jun  7 14:04:19 2010
@@ -37,11 +37,13 @@
 	const struct sockaddr_in6 *sin6;
 	struct sockaddr_in sin4;
 
-	if(!ast_sockaddr_is_ipv6(addr))
-		return 0;
-
-	if(!ast_sockaddr_is_ipv4_mapped(addr))
-		return 0;
+	if (!ast_sockaddr_is_ipv6(addr)) {
+		return 0;
+	}
+
+	if (!ast_sockaddr_is_ipv4_mapped(addr)) {
+		return 0;
+	}
 
 	sin6 = (const struct sockaddr_in6*)&addr->ss;
 
@@ -69,16 +71,19 @@
 	static const size_t size = sizeof(host) - 1 + sizeof(port) - 1 + 4;
 
 
-	if(ast_sockaddr_isnull(sa))
+	if (ast_sockaddr_isnull(sa)) {
 		return "(null)";
-
-	if(!(str = ast_threadstorage_get(&ast_sockaddr_stringify_buf, size)))
+	}
+
+	if (!(str = ast_threadstorage_get(&ast_sockaddr_stringify_buf, size))) {
 		return "";
-
-	if(ast_sockaddr_ipv4_mapped(sa, &sa_ipv4))
+	}
+
+	if (ast_sockaddr_ipv4_mapped(sa, &sa_ipv4)) {
 		sa_tmp = &sa_ipv4;
-	else
+	} else {
 		sa_tmp = sa;
+	}
 
 	if ((e = getnameinfo((struct sockaddr *)&sa_tmp->ss, sa->len,
 			     format & AST_SOCKADDR_STR_ADDR ? host : NULL,
@@ -90,7 +95,7 @@
 		return "";
 	}
 
-	switch(format)  {
+	switch (format)  {
 	case AST_SOCKADDR_STR_DEFAULT:
 		snprintf(str, size, sa_tmp->ss.ss_family == AF_INET6 ?
 				"[%s]:%s" : "%s:%s", host, port);
@@ -172,16 +177,17 @@
 
 int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
 {
-	struct addrinfo		 hints;
-	struct addrinfo		*res;
-	char			*s;
-	char			*host;
-	char			*port;
-	int			 e;
+	struct addrinfo hints;
+	struct addrinfo	*res;
+	char *s;
+	char *host;
+	char *port;
+	int	e;
 
 	s = ast_strdupa(str);
-	if(!_ast_sockaddr_parse(s, &host, &port, flags))
-		return 0;
+	if (!_ast_sockaddr_parse(s, &host, &port, flags)) {
+		return 0;
+	}
 
 	memset(&hints, 0, sizeof(hints));
 	/* Hint to get only one entry from getaddrinfo */
@@ -198,9 +204,10 @@
 	 * I don't see how this could be possible since we're not resolving host
 	 * names. But let's be careful...
 	 */
-	if (res->ai_next != NULL)
+	if (res->ai_next != NULL) {
 		ast_log(LOG_WARNING, "getaddrinfo() returned multiple "
 			"addresses. Ignoring all but the first.\n");
+	}
 
 	addr->len = res->ai_addrlen;
 	memcpy(&addr->ss, res->ai_addr, addr->len);
@@ -218,8 +225,9 @@
 	int	e, i, res_cnt;
 
 	s = ast_strdupa(str);
-	if(!_ast_sockaddr_parse(s, &host, &port, flags))
-		return 0;
+	if (!_ast_sockaddr_parse(s, &host, &port, flags)) {
+		return 0;
+	}
 
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = family;
@@ -232,8 +240,9 @@
 	}
 
 	res_cnt = 0;
-	for (ai = res; ai; ai = ai->ai_next)
+	for (ai = res; ai; ai = ai->ai_next) {
 		res_cnt++;
+	}
 
 	*addrs = ast_malloc(res_cnt * sizeof(struct ast_sockaddr));
 
@@ -257,16 +266,18 @@
 	b_tmp = b;
 
 	if (a_tmp->len != b_tmp->len) {
-		if (ast_sockaddr_ipv4_mapped(a, &ipv4_mapped))
+		if (ast_sockaddr_ipv4_mapped(a, &ipv4_mapped)) {
 			a_tmp = &ipv4_mapped;
-		else if (ast_sockaddr_ipv4_mapped(b, &ipv4_mapped))
+		} else if (ast_sockaddr_ipv4_mapped(b, &ipv4_mapped)) {
 			b_tmp = &ipv4_mapped;
-	}
-
-	if (a_tmp->len < b_tmp->len)
+		}
+	}
+
+	if (a_tmp->len < b_tmp->len) {
 		return -1;
-	else if (a_tmp->len > b_tmp->len)
+	} else if (a_tmp->len > b_tmp->len) {
 		return 1;
+	}
 
 	return memcmp(&a_tmp->ss, &b_tmp->ss, a_tmp->len);
 }
@@ -283,18 +294,20 @@
 	b_tmp = b;
 
 	if (a_tmp->len != b_tmp->len) {
-		if (ast_sockaddr_ipv4_mapped(a, &ipv4_mapped))
+		if (ast_sockaddr_ipv4_mapped(a, &ipv4_mapped)) {
 			a_tmp = &ipv4_mapped;
-		else if (ast_sockaddr_ipv4_mapped(b, &ipv4_mapped))
+		} else if (ast_sockaddr_ipv4_mapped(b, &ipv4_mapped)) {
 			b_tmp = &ipv4_mapped;
-	}
-
-	if (a->len < b->len)
+		}
+	}
+
+	if (a->len < b->len) {
 		ret = -1;
-	else if (a->len > b->len)
+	} else if (a->len > b->len) {
 		ret = 1;
-
-	switch(a_tmp->ss.ss_family) {
+	}
+
+	switch (a_tmp->ss.ss_family) {
 	case AF_INET:
 		ip4a = &((const struct sockaddr_in*)&a_tmp->ss)->sin_addr;
 		ip4b = &((const struct sockaddr_in*)&b_tmp->ss)->sin_addr;
@@ -312,11 +325,12 @@
 uint16_t ast_sockaddr_port(const struct ast_sockaddr *addr)
 {
 	if (addr->ss.ss_family == AF_INET &&
-	    addr->len == sizeof(struct sockaddr_in))
+	    addr->len == sizeof(struct sockaddr_in)) {
 		return ntohs(((struct sockaddr_in *)&addr->ss)->sin_port);
-	else if (addr->ss.ss_family == AF_INET6 &&
-		 addr->len == sizeof(struct sockaddr_in6))
+	} else if (addr->ss.ss_family == AF_INET6 &&
+		 addr->len == sizeof(struct sockaddr_in6)) {
 		return ntohs(((struct sockaddr_in6 *)&addr->ss)->sin6_port);
+	}
 	ast_log(LOG_ERROR, "Not an IPv4 nor IPv6 address, cannot get port.\n");
 	return 0;
 }
@@ -324,14 +338,15 @@
 void ast_sockaddr_set_port(struct ast_sockaddr *addr, uint16_t port)
 {
 	if (addr->ss.ss_family == AF_INET &&
-	    addr->len == sizeof(struct sockaddr_in))
+	    addr->len == sizeof(struct sockaddr_in)) {
 		((struct sockaddr_in *)&addr->ss)->sin_port = htons(port);
-	else if (addr->ss.ss_family == AF_INET6 &&
-		 addr->len == sizeof(struct sockaddr_in6))
+	} else if (addr->ss.ss_family == AF_INET6 &&
+		 addr->len == sizeof(struct sockaddr_in6)) {
 		((struct sockaddr_in6 *)&addr->ss)->sin6_port = htons(port);
-	else
+	} else {
 		ast_log(LOG_ERROR,
 			"Not an IPv4 nor IPv6 address, cannot set port.\n");
+	}
 }
 
 uint32_t ast_sockaddr_ipv4(const struct ast_sockaddr *addr)
@@ -426,16 +441,18 @@
 {
 	int res;
 
-	if ((res = setsockopt(sockfd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))))
+	if ((res = setsockopt(sockfd, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) {
 		ast_log(LOG_WARNING, "Unable to set %s TOS to %d, may be you have no root privileges\n", desc, tos);
-	else if (tos)
+	} else if (tos) {
 		ast_verb(2, "Using %s TOS bits %d\n", desc, tos);
+	}
 
 #ifdef linux
-	if (setsockopt(sockfd, SOL_SOCKET, SO_PRIORITY, &cos, sizeof(cos)))
+	if (setsockopt(sockfd, SOL_SOCKET, SO_PRIORITY, &cos, sizeof(cos))) {
 		ast_log(LOG_WARNING, "Unable to set %s CoS to %d\n", desc, cos);
-	else if (cos)
+	} else if (cos) {
 		ast_verb(2, "Using %s CoS mark %d\n", desc, cos);
+	}
 #endif
 
 	return res;




More information about the asterisk-commits mailing list