Annotation of 42BSD/lib/libc/inet/inet_network.c, revision 1.1.1.1

1.1       root        1: /*     @(#)inet_network.c      4.2     10/7/82 */
                      2: 
                      3: #include <sys/types.h>
                      4: #include <ctype.h>
                      5: 
                      6: /*
                      7:  * Internet network address interpretation routine.
                      8:  * The library routines call this routine to interpret
                      9:  * network numbers.
                     10:  */
                     11: u_long
                     12: inet_network(cp)
                     13:        register char *cp;
                     14: {
                     15:        register u_long val, base, n;
                     16:        register char c;
                     17:        u_long parts[4], *pp = parts;
                     18:        register int i;
                     19: 
                     20: again:
                     21:        val = 0; base = 10;
                     22:        if (*cp == '0')
                     23:                base = 8, cp++;
                     24:        if (*cp == 'x' || *cp == 'X')
                     25:                base = 16, cp++;
                     26:        while (c = *cp) {
                     27:                if (isdigit(c)) {
                     28:                        val = (val * base) + (c - '0');
                     29:                        cp++;
                     30:                        continue;
                     31:                }
                     32:                if (base == 16 && isxdigit(c)) {
                     33:                        val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
                     34:                        cp++;
                     35:                        continue;
                     36:                }
                     37:                break;
                     38:        }
                     39:        if (*cp == '.') {
                     40:                if (pp >= parts + 4)
                     41:                        return (-1);
                     42:                *pp++ = val, cp++;
                     43:                goto again;
                     44:        }
                     45:        if (*cp && !isspace(*cp))
                     46:                return (-1);
                     47:        *pp++ = val;
                     48:        n = pp - parts;
                     49:        if (n > 4)
                     50:                return (-1);
                     51:        for (val = 0, i = 0; i < n; i++) {
                     52:                val <<= 8;
                     53:                val |= parts[i] & 0xff;
                     54:        }
                     55:        return (val);
                     56: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.