Annotation of 43BSDReno/lib/libc/net/inet_network.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that: (1) source distributions retain this entire copyright
                      7:  * notice and comment, and (2) distributions including binaries display
                      8:  * the following acknowledgement:  ``This product includes software
                      9:  * developed by the University of California, Berkeley and its contributors''
                     10:  * in the documentation or other materials provided with the distribution
                     11:  * and in all advertising materials mentioning features or use of this
                     12:  * software. Neither the name of the University nor the names of its
                     13:  * contributors may be used to endorse or promote products derived
                     14:  * from this software without specific prior written permission.
                     15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     18:  */
                     19: 
                     20: #if defined(LIBC_SCCS) && !defined(lint)
                     21: static char sccsid[] = "@(#)inet_network.c     5.6 (Berkeley) 6/1/90";
                     22: #endif /* LIBC_SCCS and not lint */
                     23: 
                     24: #include <sys/types.h>
                     25: #include <netinet/in.h>
                     26: #include <ctype.h>
                     27: 
                     28: /*
                     29:  * Internet network address interpretation routine.
                     30:  * The library routines call this routine to interpret
                     31:  * network numbers.
                     32:  */
                     33: u_long
                     34: inet_network(cp)
                     35:        register char *cp;
                     36: {
                     37:        register u_long val, base, n;
                     38:        register char c;
                     39:        u_long parts[4], *pp = parts;
                     40:        register int i;
                     41: 
                     42: again:
                     43:        val = 0; base = 10;
                     44:        if (*cp == '0')
                     45:                base = 8, cp++;
                     46:        if (*cp == 'x' || *cp == 'X')
                     47:                base = 16, cp++;
                     48:        while (c = *cp) {
                     49:                if (isdigit(c)) {
                     50:                        val = (val * base) + (c - '0');
                     51:                        cp++;
                     52:                        continue;
                     53:                }
                     54:                if (base == 16 && isxdigit(c)) {
                     55:                        val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A'));
                     56:                        cp++;
                     57:                        continue;
                     58:                }
                     59:                break;
                     60:        }
                     61:        if (*cp == '.') {
                     62:                if (pp >= parts + 4)
                     63:                        return (INADDR_NONE);
                     64:                *pp++ = val, cp++;
                     65:                goto again;
                     66:        }
                     67:        if (*cp && !isspace(*cp))
                     68:                return (INADDR_NONE);
                     69:        *pp++ = val;
                     70:        n = pp - parts;
                     71:        if (n > 4)
                     72:                return (INADDR_NONE);
                     73:        for (val = 0, i = 0; i < n; i++) {
                     74:                val <<= 8;
                     75:                val |= parts[i] & 0xff;
                     76:        }
                     77:        return (val);
                     78: }

unix.superglobalmegacorp.com

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