# 2.11BSD#431 - /usr/src/lib/libc/net/getpent.c

##### Functions

    endprotoent       X
    getprotoent       X
    setprotoent       X

##### Variables

    _proto_stayopen   X

##### Macros

    MAXALIASES        X

       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[256+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, sizeof(line)-1, 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

- in line 24, 59-64(2), 70, 84

endprotoent defined in line 37; used 4 times

- in /usr/src/lib/libc/net/getpname.c line 32
- in /usr/src/lib/libc/net/getproto.c line 26
- in /usr/src/usr.sbin/named/named/db_load.c line 943
- in /usr/src/usr.sbin/named/tools/nslookup/list.c line 762

getprotoent defined in line 46; used 5 times

- in /usr/include/netdb.h line 60
- in /usr/src/include/netdb.h line 58
- in /usr/src/lib/libc/net/getpname.c line 23
- in /usr/src/lib/libc/net/getproto.c line 22
- in /usr/src/usr.sbin/named/named/db_load.c line 932

setprotoent defined in line 27; used 4 times

- in /usr/src/lib/libc/net/getpname.c line 22
- in /usr/src/lib/libc/net/getproto.c line 21
- in /usr/src/usr.sbin/named/named/db_load.c line 931
- in /usr/src/usr.sbin/named/tools/nslookup/list.c line 737

#### Defined variables

PROTODB defined in line 19; used 2 times

- in line 31, 52

_proto_stayopen defined in line 25; used 6 times

- in line 34, 43
- in /usr/src/lib/libc/net/getpname.c line 22, 31
- in /usr/src/lib/libc/net/getproto.c line 21-25(2)

line defined in line 21; used 2 times

- in line 55(2)

proto defined in line 22; used 4 times

- in line 63, 73-74(2), 90

proto_aliases defined in line 23; used 2 times

- in line 74, 82

sccsid defined in line 8; never used

#### Defined macros

MAXALIASES defined in line 17; used 2 times

- in line 23, 82

Last modified: 1988-08-23 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 703 |