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

Defined functions

any defined in line 94; used 5 times

Defined variables

NETDB defined in line 19; used 2 times
_net_stayopen defined in line 24; used 6 times
line defined in line 21; used 1 times
  • in line 55
net defined in line 22; used 5 times
net_aliases defined in line 23; used 2 times
sccsid defined in line 8; never used

Defined macros

MAXALIASES defined in line 17; used 2 times
Last modified: 1986-05-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1182
Valid CSS Valid XHTML 1.0 Strict