Back to index

glibc  2.9
Functions
inet_net.c File Reference
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>

Go to the source code of this file.

Functions

u_int32_t inet_network (const char *cp)

Function Documentation

u_int32_t inet_network ( const char *  cp)

Definition at line 45 of file inet_net.c.

{
       register u_int32_t val, base, n, i;
       register char c;
       u_int32_t parts[4], *pp = parts;
       int digit;

again:
       val = 0; base = 10; digit = 0;
       if (*cp == '0')
              digit = 1, base = 8, cp++;
       if (*cp == 'x' || *cp == 'X')
              digit = 0, base = 16, cp++;
       while ((c = *cp) != 0) {
              if (isdigit(c)) {
                     if (base == 8 && (c == '8' || c == '9'))
                            return (INADDR_NONE);
                     val = (val * base) + (c - '0');
                     cp++;
                     digit = 1;
                     continue;
              }
              if (base == 16 && isxdigit(c)) {
                     val = (val << 4) + (tolower (c) + 10 - 'a');
                     cp++;
                     digit = 1;
                     continue;
              }
              break;
       }
       if (!digit)
              return (INADDR_NONE);
       if (pp >= parts + 4 || val > 0xff)
              return (INADDR_NONE);
       if (*cp == '.') {
              *pp++ = val, cp++;
              goto again;
       }
       if (*cp && !isspace(*cp))
              return (INADDR_NONE);
       if (pp >= parts + 4 || val > 0xff)
              return (INADDR_NONE);
       *pp++ = val;
       n = pp - parts;
       for (val = 0, i = 0; i < n; i++) {
              val <<= 8;
              val |= parts[i] & 0xff;
       }
       return (val);
}

Here is the call graph for this function: