The following reply was made to PR kern/92880; it has been noted by GNATS.

From: Andrey Simonenko <[email protected]>
To: [email protected]
Cc:  
Subject: Re: kern/92880: [libc] [patch] almost rewritten inet_network(3)
 function
Date: Mon, 24 Jan 2011 14:56:25 +0200

 Since all '=' were changed to '=3D' in previous email, here is the copy
 of diff for the inet_network.c file.
 
 --- inet_network.c.orig        2008-01-15 00:55:20.000000000 +0200
 +++ inet_network.c     2011-01-21 15:58:17.000000000 +0200
 @@ -48,57 +48,56 @@ __FBSDID("$FreeBSD: src/lib/libc/inet/in
   * network numbers.
   */
  in_addr_t
 -inet_network(cp)
 -      const char *cp;
 +inet_network(const char *s)
  {
 -      in_addr_t val, base, n;
 -      char c;
 -      in_addr_t parts[4], *pp = parts;
 -      int i, digit;
 +      u_int base, dots;
 +      in_addr_t res, val;
 +      u_char c;
 +      char got_data;
  
 -again:
 -      val = 0; base = 10; digit = 0;
 -      if (*cp == '0')
 -              digit = 1, base = 8, cp++;
 -      if (*cp == 'x' || *cp == 'X')
 -              base = 16, cp++;
 -      while ((c = *cp) != 0) {
 -              if (isdigit((unsigned char)c)) {
 -                      if (base == 8U && (c == '8' || c == '9'))
 +      res = 0;
 +      dots = 0;
 +      for (;;) {
 +              val = 0;
 +              got_data = 0;
 +              if (*s == '0') {
 +                      s++;
 +                      if (*s == 'x' || *s == 'X') {
 +                              s++;
 +                              base = 16;
 +                      } else {
 +                              base = 8;
 +                              got_data = 1;
 +                      }
 +              } else
 +                      base = 10;
 +              while ((c = *s) != '\0') {
 +                      if (isdigit(c)) {
 +                              if (base == 8 && c > '7')
 +                                      return (INADDR_NONE);
 +                              val = val * base + c - '0';
 +                      } else if (base == 16 && isxdigit(c))
 +                              val = (val << 4) + c + 10 -
 +                                  (islower(c) ? 'a' : 'A');
 +                      else
 +                              break;
 +                      if (val > 0xff)
                                return (INADDR_NONE);
 -                      val = (val * base) + (c - '0');
 -                      cp++;
 -                      digit = 1;
 -                      continue;
 +                      s++;
 +                      got_data = 1;
                }
 -              if (base == 16U && isxdigit((unsigned char)c)) {
 -                      val = (val << 4) +
 -                            (c + 10 - (islower((unsigned char)c) ? 'a' : 
'A'));
 -                      cp++;
 -                      digit = 1;
 -                      continue;
 -              }
 -              break;
 -      }
 -      if (!digit)
 -              return (INADDR_NONE);
 -      if (pp >= parts + 4 || val > 0xffU)
 -              return (INADDR_NONE);
 -      if (*cp == '.') {
 -              *pp++ = val, cp++;
 -              goto again;
 -      }
 -      if (*cp && !isspace(*cp&0xff))
 -              return (INADDR_NONE);
 -      *pp++ = val;
 -      n = pp - parts;
 -      if (n > 4U)
 -              return (INADDR_NONE);
 -      for (val = 0, i = 0; i < n; i++) {
 -              val <<= 8;
 -              val |= parts[i] & 0xff;
 +              if (!got_data)
 +                      return (INADDR_NONE);
 +              if (dots != 0)
 +                      res <<= 8;
 +              res |= val;
 +              if (c != '.')
 +                      break;
 +              if (++dots == 4)
 +                      return (INADDR_NONE);
 +              s++;
        }
 -      return (val);
 +      return (c == '\0' ? res : INADDR_NONE);
  }
  
  /*
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-net
To unsubscribe, send any mail to "[email protected]"

Reply via email to