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[] = "@(#)getprotoent.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 PROTODB[] = "/etc/protocols";
  20: static FILE *protof = NULL;
  21: static char line[BUFSIZ+1];
  22: static struct protoent proto;
  23: static char *proto_aliases[MAXALIASES];
  24: static char *any();
  25: int _proto_stayopen;
  26: 
  27: setprotoent(f)
  28:     int f;
  29: {
  30:     if (protof == NULL)
  31:         protof = fopen(PROTODB, "r" );
  32:     else
  33:         rewind(protof);
  34:     _proto_stayopen |= f;
  35: }
  36: 
  37: endprotoent()
  38: {
  39:     if (protof) {
  40:         fclose(protof);
  41:         protof = NULL;
  42:     }
  43:     _proto_stayopen = 0;
  44: }
  45: 
  46: struct protoent *
  47: getprotoent()
  48: {
  49:     char *p;
  50:     register char *cp, **q;
  51: 
  52:     if (protof == NULL && (protof = fopen(PROTODB, "r" )) == NULL)
  53:         return (NULL);
  54: again:
  55:     if ((p = fgets(line, BUFSIZ, protof)) == NULL)
  56:         return (NULL);
  57:     if (*p == '#')
  58:         goto again;
  59:     cp = any(p, "#\n");
  60:     if (cp == NULL)
  61:         goto again;
  62:     *cp = '\0';
  63:     proto.p_name = p;
  64:     cp = any(p, " \t");
  65:     if (cp == NULL)
  66:         goto again;
  67:     *cp++ = '\0';
  68:     while (*cp == ' ' || *cp == '\t')
  69:         cp++;
  70:     p = any(cp, " \t");
  71:     if (p != NULL)
  72:         *p++ = '\0';
  73:     proto.p_proto = atoi(cp);
  74:     q = proto.p_aliases = proto_aliases;
  75:     if (p != NULL) {
  76:         cp = p;
  77:         while (cp && *cp) {
  78:             if (*cp == ' ' || *cp == '\t') {
  79:                 cp++;
  80:                 continue;
  81:             }
  82:             if (q < &proto_aliases[MAXALIASES - 1])
  83:                 *q++ = cp;
  84:             cp = any(cp, " \t");
  85:             if (cp != NULL)
  86:                 *cp++ = '\0';
  87:         }
  88:     }
  89:     *q = NULL;
  90:     return (&proto);
  91: }
  92: 
  93: static char *
  94: any(cp, match)
  95:     register char *cp;
  96:     char *match;
  97: {
  98:     register char *mp, c;
  99: 
 100:     while (c = *cp) {
 101:         for (mp = match; *mp; mp++)
 102:             if (*mp == c)
 103:                 return (cp);
 104:         cp++;
 105:     }
 106:     return ((char *)0);
 107: }

Defined functions

any defined in line 93; used 5 times

Defined variables

PROTODB defined in line 19; used 2 times
_proto_stayopen defined in line 25; used 6 times
line defined in line 21; used 1 times
  • in line 55
proto defined in line 22; used 4 times
proto_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: 1034
Valid CSS Valid XHTML 1.0 Strict