Annotation of 43BSDReno/lib/libc/net/getnetent.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[] = "@(#)getnetent.c        5.7 (Berkeley) 6/1/90";
                     22: #endif /* LIBC_SCCS and not lint */
                     23: 
                     24: #include <stdio.h>
                     25: #include <sys/types.h>
                     26: #include <sys/socket.h>
                     27: #include <netdb.h>
                     28: #include <ctype.h>
                     29: 
                     30: #define        MAXALIASES      35
                     31: 
                     32: static FILE *netf = NULL;
                     33: static char line[BUFSIZ+1];
                     34: static struct netent net;
                     35: static char *net_aliases[MAXALIASES];
                     36: int _net_stayopen;
                     37: static char *any();
                     38: 
                     39: setnetent(f)
                     40:        int f;
                     41: {
                     42:        if (netf == NULL)
                     43:                netf = fopen(_PATH_NETWORKS, "r" );
                     44:        else
                     45:                rewind(netf);
                     46:        _net_stayopen |= f;
                     47: }
                     48: 
                     49: endnetent()
                     50: {
                     51:        if (netf) {
                     52:                fclose(netf);
                     53:                netf = NULL;
                     54:        }
                     55:        _net_stayopen = 0;
                     56: }
                     57: 
                     58: struct netent *
                     59: getnetent()
                     60: {
                     61:        char *p;
                     62:        register char *cp, **q;
                     63: 
                     64:        if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL)
                     65:                return (NULL);
                     66: again:
                     67:        p = fgets(line, BUFSIZ, netf);
                     68:        if (p == NULL)
                     69:                return (NULL);
                     70:        if (*p == '#')
                     71:                goto again;
                     72:        cp = any(p, "#\n");
                     73:        if (cp == NULL)
                     74:                goto again;
                     75:        *cp = '\0';
                     76:        net.n_name = p;
                     77:        cp = any(p, " \t");
                     78:        if (cp == NULL)
                     79:                goto again;
                     80:        *cp++ = '\0';
                     81:        while (*cp == ' ' || *cp == '\t')
                     82:                cp++;
                     83:        p = any(cp, " \t");
                     84:        if (p != NULL)
                     85:                *p++ = '\0';
                     86:        net.n_net = inet_network(cp);
                     87:        net.n_addrtype = AF_INET;
                     88:        q = net.n_aliases = net_aliases;
                     89:        if (p != NULL) 
                     90:                cp = p;
                     91:        while (cp && *cp) {
                     92:                if (*cp == ' ' || *cp == '\t') {
                     93:                        cp++;
                     94:                        continue;
                     95:                }
                     96:                if (q < &net_aliases[MAXALIASES - 1])
                     97:                        *q++ = cp;
                     98:                cp = any(cp, " \t");
                     99:                if (cp != NULL)
                    100:                        *cp++ = '\0';
                    101:        }
                    102:        *q = NULL;
                    103:        return (&net);
                    104: }
                    105: 
                    106: static char *
                    107: any(cp, match)
                    108:        register char *cp;
                    109:        char *match;
                    110: {
                    111:        register char *mp, c;
                    112: 
                    113:        while (c = *cp) {
                    114:                for (mp = match; *mp; mp++)
                    115:                        if (*mp == c)
                    116:                                return (cp);
                    117:                cp++;
                    118:        }
                    119:        return ((char *)0);
                    120: }

unix.superglobalmegacorp.com

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