/* * Copyright (c) 1983 Regents of the University of California. * All rights reserved. * * %sccs.include.redist.c% */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)getnetent.c 5.8 (Berkeley) 02/24/91"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include #include #include #include #define MAXALIASES 35 static FILE *netf; static char line[BUFSIZ+1]; static struct netent net; static char *net_aliases[MAXALIASES]; int _net_stayopen; void setnetent(f) int f; { if (netf == NULL) netf = fopen(_PATH_NETWORKS, "r" ); else rewind(netf); _net_stayopen |= f; } void endnetent() { if (netf) { fclose(netf); netf = NULL; } _net_stayopen = 0; } struct netent * getnetent() { char *p; register char *cp, **q; if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) return (NULL); again: p = fgets(line, BUFSIZ, netf); if (p == NULL) return (NULL); if (*p == '#') goto again; cp = strpbrk(p, "#\n"); if (cp == NULL) goto again; *cp = '\0'; net.n_name = p; cp = strpbrk(p, " \t"); if (cp == NULL) goto again; *cp++ = '\0'; while (*cp == ' ' || *cp == '\t') cp++; p = strpbrk(cp, " \t"); if (p != NULL) *p++ = '\0'; net.n_net = inet_network(cp); net.n_addrtype = AF_INET; q = net.n_aliases = net_aliases; if (p != NULL) cp = p; while (cp && *cp) { if (*cp == ' ' || *cp == '\t') { cp++; continue; } if (q < &net_aliases[MAXALIASES - 1]) *q++ = cp; cp = strpbrk(cp, " \t"); if (cp != NULL) *cp++ = '\0'; } *q = NULL; return (&net); }