1: /*
   2:  * Copyright (c) 1983 Regents of the University of California.
   3:  * All rights reserved.  The Berkeley software License Agreement
   4:  * specifies the terms and conditions for redistribution.
   5:  */
   6: 
   7: #if defined(LIBC_SCCS) && !defined(lint)
   8: static char sccsid[] = "@(#)getnetent.c	5.3 (Berkeley) 5/19/86";
   9: #endif LIBC_SCCS and not lint
  10: 
  11: #include <stdio.h>
  12: #include <sys/types.h>
  13: #include <sys/socket.h>
  14: #include <arpa/inet.h>
  15: #include <netdb.h>
  16: #include <ctype.h>
  17: 
  18: #define MAXALIASES  35
  19: 
  20: static char NETDB[] = "/etc/networks";
  21: static FILE *netf = NULL;
  22: static char line[256+1];
  23: static struct netent net;
  24: static char *net_aliases[MAXALIASES];
  25: int _net_stayopen;
  26: static char *any();
  27: 
  28: setnetent(f)
  29:     int f;
  30: {
  31:     if (netf == NULL)
  32:         netf = fopen(NETDB, "r" );
  33:     else
  34:         rewind(netf);
  35:     _net_stayopen |= f;
  36: }
  37: 
  38: endnetent()
  39: {
  40:     if (netf) {
  41:         fclose(netf);
  42:         netf = NULL;
  43:     }
  44:     _net_stayopen = 0;
  45: }
  46: 
  47: struct netent *
  48: getnetent()
  49: {
  50:     char *p;
  51:     register char *cp, **q;
  52: 
  53:     if (netf == NULL && (netf = fopen(NETDB, "r" )) == NULL)
  54:         return (NULL);
  55: again:
  56:     p = fgets(line, sizeof(line)-1, netf);
  57:     if (p == NULL)
  58:         return (NULL);
  59:     if (*p == '#')
  60:         goto again;
  61:     cp = any(p, "#\n");
  62:     if (cp == NULL)
  63:         goto again;
  64:     *cp = '\0';
  65:     net.n_name = p;
  66:     cp = any(p, " \t");
  67:     if (cp == NULL)
  68:         goto again;
  69:     *cp++ = '\0';
  70:     while (*cp == ' ' || *cp == '\t')
  71:         cp++;
  72:     p = any(cp, " \t");
  73:     if (p != NULL)
  74:         *p++ = '\0';
  75:     net.n_net = inet_network(cp);
  76:     net.n_addrtype = AF_INET;
  77:     q = net.n_aliases = net_aliases;
  78:     if (p != NULL)
  79:         cp = p;
  80:     while (cp && *cp) {
  81:         if (*cp == ' ' || *cp == '\t') {
  82:             cp++;
  83:             continue;
  84:         }
  85:         if (q < &net_aliases[MAXALIASES - 1])
  86:             *q++ = cp;
  87:         cp = any(cp, " \t");
  88:         if (cp != NULL)
  89:             *cp++ = '\0';
  90:     }
  91:     *q = NULL;
  92:     return (&net);
  93: }
  94: 
  95: static char *
  96: any(cp, match)
  97:     register char *cp;
  98:     char *match;
  99: {
 100:     register char *mp, c;
 101: 
 102:     while (c = *cp) {
 103:         for (mp = match; *mp; mp++)
 104:             if (*mp == c)
 105:                 return (cp);
 106:         cp++;
 107:     }
 108:     return ((char *)0);
 109: }

Defined functions

any defined in line 95; used 5 times

Defined variables

NETDB defined in line 20; used 2 times
_net_stayopen defined in line 25; used 6 times
line defined in line 22; used 2 times
  • in line 56(2)
net defined in line 23; used 5 times
net_aliases defined in line 24; used 2 times
sccsid defined in line 8; never used

Defined macros

MAXALIASES defined in line 18; used 2 times
Last modified: 1988-08-23
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2745
Valid CSS Valid XHTML 1.0 Strict