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

##### Functions

    endhostent        X
    gethostent        X
    sethostent        X
    sethostfile       X

##### Variables

    _host_file        X
    _host_stayopen    X

##### Macros

    MAXADDRSIZE       X
    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[] = "@(#)gethostent.c	5.3 (Berkeley) 3/9/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: #include <ndbm.h>
      18:
      19: /*
      20:  * Internet version.
      21:  */
      22: #define MAXALIASES  20
      23: #define MAXADDRSIZE (sizeof (u_long))
      24:
      25: static FILE *hostf = NULL;
      26: static char line[160+1];
      27: static char hostaddr[MAXADDRSIZE];
      28: static struct hostent host;
      29: static char *host_aliases[MAXALIASES];
      30: static char *host_addrs[] = {
      31:     hostaddr,
      32:     NULL
      33: };
      34:
      35: /*
      36:  * The following is shared with gethostnamadr.c
      37:  */
      38: char    *_host_file = "/etc/hosts";
      39: int _host_stayopen;
      40: DBM *_host_db;  /* set by gethostbyname(), gethostbyaddr() */
      41:
      42: static char *any();
      43:
      44: sethostent(f)
      45:     int f;
      46: {
      47:     if (hostf != NULL)
      48:         rewind(hostf);
      49:     _host_stayopen |= f;
      50: }
      51:
      52: endhostent()
      53: {
      54:     if (hostf) {
      55:         fclose(hostf);
      56:         hostf = NULL;
      57:     }
      58:     if (_host_db) {
      59:         dbm_close(_host_db);
      60:         _host_db = (DBM *)NULL;
      61:     }
      62:     _host_stayopen = 0;
      63: }
      64:
      65: struct hostent *
      66: gethostent()
      67: {
      68:     char *p;
      69:     register char *cp, **q;
      70:
      71:     if (hostf == NULL && (hostf = fopen(_host_file, "r" )) == NULL)
      72:         return (NULL);
      73: again:
      74:     if ((p = fgets(line, sizeof(line)-1, hostf)) == NULL)
      75:         return (NULL);
      76:     if (*p == '#')
      77:         goto again;
      78:     cp = any(p, "#\n");
      79:     if (cp == NULL)
      80:         goto again;
      81:     *cp = '\0';
      82:     cp = any(p, " \t");
      83:     if (cp == NULL)
      84:         goto again;
      85:     *cp++ = '\0';
      86:     /* THIS STUFF IS INTERNET SPECIFIC */
      87:     host.h_addr_list = host_addrs;
      88:     *((u_long *)host.h_addr) = inet_addr(p);
      89:     host.h_length = sizeof (u_long);
      90:     host.h_addrtype = AF_INET;
      91:     while (*cp == ' ' || *cp == '\t')
      92:         cp++;
      93:     host.h_name = cp;
      94:     q = host.h_aliases = host_aliases;
      95:     cp = any(cp, " \t");
      96:     if (cp != NULL)
      97:         *cp++ = '\0';
      98:     while (cp && *cp) {
      99:         if (*cp == ' ' || *cp == '\t') {
     100:             cp++;
     101:             continue;
     102:         }
     103:         if (q < &host_aliases[MAXALIASES - 1])
     104:             *q++ = cp;
     105:         cp = any(cp, " \t");
     106:         if (cp != NULL)
     107:             *cp++ = '\0';
     108:     }
     109:     *q = NULL;
     110:     return (&host);
     111: }
     112:
     113: sethostfile(file)
     114:     char *file;
     115: {
     116:     _host_file = file;
     117: }
     118:
     119: static char *
     120: any(cp, match)
     121:     register char *cp;
     122:     char *match;
     123: {
     124:     register char *mp, c;
     125:
     126:     while (c = *cp) {
     127:         for (mp = match; *mp; mp++)
     128:             if (*mp == c)
     129:                 return (cp);
     130:         cp++;
     131:     }
     132:     return ((char *)0);
     133: }

#### Defined functions

any defined in line 119; used 5 times

- in line 42, 78-82(2), 95, 105

endhostent defined in line 52; never used
gethostent defined in line 65; used 6 times

- in /usr/include/netdb.h line 57
- in /usr/src/games/hunt/hunt.c line 392
- in /usr/src/include/netdb.h line 55
- in /usr/src/lib/libc/net/hosttable/gethnamadr.c line 99, 135
- in /usr/src/usr.sbin/mkhosts/mkhosts.c line 63

sethostent defined in line 44; never used
sethostfile defined in line 113; never used

#### Defined variables

_host_file defined in line 38; used 4 times

- in line 71, 116
- in /usr/src/lib/libc/net/hosttable/gethnamadr.c line 97, 133

_host_stayopen defined in line 39; used 2 times

- in line 49, 62

host defined in line 28; used 7 times

- in line 87-94(6), 110

host_addrs defined in line 30; used 1 times

- in line 87

host_aliases defined in line 29; used 2 times

- in line 94, 103

hostaddr defined in line 27; used 1 times

- in line 31

line defined in line 26; used 2 times

- in line 74(2)

sccsid defined in line 8; never used

#### Defined macros

MAXADDRSIZE defined in line 23; used 1 times

- in line 27

MAXALIASES defined in line 22; used 2 times

- in line 29, 103

Last modified: 1989-10-07 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1752 |