]> git.saurik.com Git - apple/xnu.git/blobdiff - libkern/net/inet_aton.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / libkern / net / inet_aton.c
index ff518373eadb399cda7880d96d7adab19717a0a1..73ea8a678ab524fc2f5b7a9b575b3a58f88a03a7 100644 (file)
@@ -33,7 +33,7 @@
 static inline int
 isspace(char c)
 {
-        return (c == ' ' || c == '\t' || c == '\n' || c == '\12');
+       return c == ' ' || c == '\t' || c == '\n' || c == '\12';
 }
 #endif
 
@@ -59,8 +59,9 @@ inet_aton(const char *cp, struct in_addr *addr)
 
                l = strtoul(c, &endptr, 0);
 
-               if (l == ULONG_MAX || (l == 0 && endptr == c))
-                       return (0);
+               if (l == ULONG_MAX || (l == 0 && endptr == c)) {
+                       return 0;
+               }
 
                val = (in_addr_t)l;
 
@@ -70,18 +71,20 @@ inet_aton(const char *cp, struct in_addr *addr)
                 * gone '.12' or something which would get past
                 * the next check.
                 */
-               if (endptr == c)
-                       return (0);
+               if (endptr == c) {
+                       return 0;
+               }
                parts[n] = val;
                c = endptr;
 
                /* Check the next character past the previous number's end */
                switch (*c) {
-               case '.' :
+               case '.':
 
                        /* Make sure we only do 3 dots .. */
-                       if (n == 3)     /* Whoops. Quit. */
-                               return (0);
+                       if (n == 3) {   /* Whoops. Quit. */
+                               return 0;
+                       }
                        n++;
                        c++;
                        break;
@@ -95,44 +98,46 @@ inet_aton(const char *cp, struct in_addr *addr)
                                gotend = 1;
                                break;
                        } else {
-
                                /* Invalid character, then fail. */
-                               return (0);
+                               return 0;
                        }
                }
-
        }
 
        /* Concoct the address according to the number of parts specified. */
        switch (n) {
-       case 0:                         /* a -- 32 bits */
+       case 0:                         /* a -- 32 bits */
 
                /*
                 * Nothing is necessary here.  Overflow checking was
                 * already done in strtoul().
                 */
                break;
-       case 1:                         /* a.b -- 8.24 bits */
-               if (val > 0xffffff || parts[0] > 0xff)
-                       return (0);
+       case 1:                         /* a.b -- 8.24 bits */
+               if (val > 0xffffff || parts[0] > 0xff) {
+                       return 0;
+               }
                val |= parts[0] << 24;
                break;
 
-       case 2:                         /* a.b.c -- 8.8.16 bits */
-               if (val > 0xffff || parts[0] > 0xff || parts[1] > 0xff)
-                       return (0);
+       case 2:                         /* a.b.c -- 8.8.16 bits */
+               if (val > 0xffff || parts[0] > 0xff || parts[1] > 0xff) {
+                       return 0;
+               }
                val |= (parts[0] << 24) | (parts[1] << 16);
                break;
 
-       case 3:                         /* a.b.c.d -- 8.8.8.8 bits */
+       case 3:                         /* a.b.c.d -- 8.8.8.8 bits */
                if (val > 0xff || parts[0] > 0xff || parts[1] > 0xff ||
-                   parts[2] > 0xff)
-                       return (0);
+                   parts[2] > 0xff) {
+                       return 0;
+               }
                val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
                break;
        }
 
-       if (addr != NULL)
+       if (addr != NULL) {
                addr->s_addr = htonl(val);
-       return (1);
+       }
+       return 1;
 }