Blame SOURCES/dnsmasq-2.66-replace-inet_addr-with-inet_pton-in-option-c.patch

cab8d5
From ddd9a6b499ae601231070854c562611a79e004c0 Mon Sep 17 00:00:00 2001
cab8d5
From: Simon Kelley <simon@thekelleys.org.uk>
cab8d5
Date: Mon, 29 Apr 2013 17:00:21 +0100
cab8d5
Subject: [PATCH] replace inet_addr with inet_pton() in src/option.c
cab8d5
cab8d5
---
cab8d5
 src/option.c | 52 ++++++++++++++++++++++++++--------------------------
cab8d5
 1 file changed, 26 insertions(+), 26 deletions(-)
cab8d5
cab8d5
diff --git a/src/option.c b/src/option.c
cab8d5
index 20a8668..d2ab689 100644
cab8d5
--- a/src/option.c
cab8d5
+++ b/src/option.c
cab8d5
@@ -660,7 +660,7 @@ char *parse_server(char *arg, union mysockaddr *addr, union mysockaddr *source_a
cab8d5
   scope_id = split_chr(arg, '%');
cab8d5
 #endif
cab8d5
   
cab8d5
-  if ((addr->in.sin_addr.s_addr = inet_addr(arg)) != (in_addr_t) -1)
cab8d5
+  if (inet_pton(AF_INET, arg, &addr->in.sin_addr) > 0)
cab8d5
     {
cab8d5
       addr->in.sin_port = htons(serv_port);	
cab8d5
       addr->sa.sa_family = source_addr->sa.sa_family = AF_INET;
cab8d5
@@ -675,7 +675,7 @@ char *parse_server(char *arg, union mysockaddr *addr, union mysockaddr *source_a
cab8d5
 	  if (flags)
cab8d5
 	    *flags |= SERV_HAS_SOURCE;
cab8d5
 	  source_addr->in.sin_port = htons(source_port);
cab8d5
-	  if ((source_addr->in.sin_addr.s_addr = inet_addr(source)) == (in_addr_t) -1)
cab8d5
+	  if (!(inet_pton(AF_INET, source, &source_addr->in.sin_addr) > 0))
cab8d5
 	    {
cab8d5
 #if defined(SO_BINDTODEVICE)
cab8d5
 	      source_addr->in.sin_addr.s_addr = INADDR_ANY;
cab8d5
@@ -1031,7 +1031,7 @@ static int parse_dhcp_opt(char *errstr, char *arg, int flags)
cab8d5
 	      cp = comma;
cab8d5
 	      comma = split(cp);
cab8d5
 	      slash = split_chr(cp, '/');
cab8d5
-	      in.s_addr = inet_addr(cp);
cab8d5
+	      inet_pton(AF_INET, cp, &in);
cab8d5
 	      if (!slash)
cab8d5
 		{
cab8d5
 		  memcpy(op, &in, INADDRSZ);
cab8d5
@@ -1576,7 +1576,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
 	comma = split(arg);
cab8d5
 	new->name = NULL;
cab8d5
 	unhide_metas(arg);
cab8d5
-	if ((new->addr.in.sin_addr.s_addr = inet_addr(arg)) != (in_addr_t)-1)
cab8d5
+	if (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0)
cab8d5
 	  new->addr.sa.sa_family = AF_INET;
cab8d5
 #ifdef HAVE_IPV6
cab8d5
 	else if (inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0)
cab8d5
@@ -1927,7 +1927,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
       {
cab8d5
 	struct in_addr addr;
cab8d5
 	unhide_metas(arg);
cab8d5
-	if (arg && (addr.s_addr = inet_addr(arg)) != (in_addr_t)-1)
cab8d5
+	if (arg && (inet_pton(AF_INET, arg, &addr) > 0))
cab8d5
 	  {
cab8d5
 	    struct bogus_addr *baddr = opt_malloc(sizeof(struct bogus_addr));
cab8d5
 	    baddr->next = daemon->bogus_addr;
cab8d5
@@ -1945,7 +1945,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
 	struct iname *new = opt_malloc(sizeof(struct iname));
cab8d5
 	comma = split(arg);
cab8d5
 	unhide_metas(arg);
cab8d5
-	if (arg && (new->addr.in.sin_addr.s_addr = inet_addr(arg)) != (in_addr_t)-1)
cab8d5
+	if (arg && (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0))
cab8d5
 	  {
cab8d5
 	    new->addr.sa.sa_family = AF_INET;
cab8d5
 	    new->addr.in.sin_port = 0;
cab8d5
@@ -2369,7 +2369,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
 	      }
cab8d5
 	    
cab8d5
 	    if (k >= 3 && strchr(a[2], '.') &&  
cab8d5
-		((new->netmask.s_addr = inet_addr(a[2])) != (in_addr_t)-1))
cab8d5
+		(inet_pton(AF_INET, a[2], &new->netmask) > 0))
cab8d5
 	      {
cab8d5
 		new->flags |= CONTEXT_NETMASK;
cab8d5
 		leasepos = 3;
cab8d5
@@ -2378,7 +2378,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
 	      }
cab8d5
 	    
cab8d5
 	    if (k >= 4 && strchr(a[3], '.') &&  
cab8d5
-		((new->broadcast.s_addr = inet_addr(a[3])) != (in_addr_t)-1))
cab8d5
+		(inet_pton(AF_INET, a[3], &new->broadcast) > 0))
cab8d5
 	      {
cab8d5
 		new->flags |= CONTEXT_BRDCAST;
cab8d5
 		leasepos = 4;
cab8d5
@@ -2608,7 +2608,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
 		    }		    
cab8d5
 		}
cab8d5
 	    }
cab8d5
-	  else if (strchr(a[j], '.') && (in.s_addr = inet_addr(a[j])) != (in_addr_t)-1)
cab8d5
+	  else if (strchr(a[j], '.') && (inet_pton(AF_INET, a[j], &in) > 0))
cab8d5
 	    {
cab8d5
 	      struct dhcp_config *configs;
cab8d5
 	      
cab8d5
@@ -2805,17 +2805,17 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
 		if (comma)
cab8d5
 		  {
cab8d5
 		    unhide_metas(comma);
cab8d5
-		    if ((dhcp_next_server.s_addr = inet_addr(comma)) == (in_addr_t)-1) {
cab8d5
-
cab8d5
-		      /*
cab8d5
-		       * The user may have specified the tftp hostname here.
cab8d5
-		       * save it so that it can be resolved/looked up during
cab8d5
-		       * actual dhcp_reply().
cab8d5
-		       */	
cab8d5
-
cab8d5
-		      tftp_sname = opt_string_alloc(comma);
cab8d5
-		      dhcp_next_server.s_addr = 0;
cab8d5
-		    }
cab8d5
+		    if (!(inet_pton(AF_INET, comma, &dhcp_next_server) > 0))
cab8d5
+		      {
cab8d5
+			/*
cab8d5
+			 * The user may have specified the tftp hostname here.
cab8d5
+			 * save it so that it can be resolved/looked up during
cab8d5
+			 * actual dhcp_reply().
cab8d5
+			 */	
cab8d5
+			
cab8d5
+			tftp_sname = opt_string_alloc(comma);
cab8d5
+			dhcp_next_server.s_addr = 0;
cab8d5
+		      }
cab8d5
 		  }
cab8d5
 	      }
cab8d5
 	    
cab8d5
@@ -2828,7 +2828,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
 	    new->next = daemon->boot_config;
cab8d5
 	    daemon->boot_config = new;
cab8d5
 	  }
cab8d5
-	
cab8d5
+      
cab8d5
 	break;
cab8d5
       }
cab8d5
 
cab8d5
@@ -3144,7 +3144,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
       while (arg) {
cab8d5
 	struct addr_list *new = opt_malloc(sizeof(struct addr_list));
cab8d5
 	comma = split(arg);
cab8d5
-	if ((new->addr.s_addr = inet_addr(arg)) == (in_addr_t)-1)
cab8d5
+	if (!(inet_pton(AF_INET, arg, &new->addr) > 0))
cab8d5
 	  ret_err(_("bad dhcp-proxy address"));
cab8d5
 	new->next = daemon->override_relays;
cab8d5
 	daemon->override_relays = new;
cab8d5
@@ -3187,15 +3187,15 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
cab8d5
 	dash = split_chr(a[0], '-');
cab8d5
 
cab8d5
 	if ((k < 2) || 
cab8d5
-	    ((new->in.s_addr = inet_addr(a[0])) == (in_addr_t)-1) ||
cab8d5
-	    ((new->out.s_addr = inet_addr(a[1])) == (in_addr_t)-1))
cab8d5
+	    (!(inet_pton(AF_INET, a[0], &new->in) > 0)) ||
cab8d5
+	    (!(inet_pton(AF_INET, a[1], &new->out) > 0)))
cab8d5
 	  option = '?';
cab8d5
 	
cab8d5
 	if (k == 3)
cab8d5
-	  new->mask.s_addr = inet_addr(a[2]);
cab8d5
+	  inet_pton(AF_INET, a[2], &new->mask);
cab8d5
 	
cab8d5
 	if (dash && 
cab8d5
-	    ((new->end.s_addr = inet_addr(dash)) == (in_addr_t)-1 ||
cab8d5
+	    (!(inet_pton(AF_INET, dash, &new->end) > 0) ||
cab8d5
 	     !is_same_net(new->in, new->end, new->mask) ||
cab8d5
 	     ntohl(new->in.s_addr) > ntohl(new->end.s_addr)))
cab8d5
 	  ret_err(_("invalid alias range"));
cab8d5
-- 
cab8d5
1.8.1.4
cab8d5