try to make display narrower
[unix-history] / usr / src / lib / libc / net / getprotoent.c
CommitLineData
8ea4199d
DF
1/*
2 * Copyright (c) 1983 Regents of the University of California.
6b2f9dd0
KB
3 * All rights reserved.
4 *
269a7923 5 * %sccs.include.redist.c%
8ea4199d
DF
6 */
7
2ce81398 8#if defined(LIBC_SCCS) && !defined(lint)
24fac7d8 9static char sccsid[] = "@(#)getprotoent.c 5.8 (Berkeley) %G%";
6b2f9dd0 10#endif /* LIBC_SCCS and not lint */
eef09c7b 11
1a58f155 12#include <sys/types.h>
eef09c7b
SL
13#include <sys/socket.h>
14#include <netdb.h>
24fac7d8
KB
15#include <stdio.h>
16#include <stdlib.h>
17#include <string.h>
eef09c7b
SL
18
19#define MAXALIASES 35
20
eef09c7b
SL
21static FILE *protof = NULL;
22static char line[BUFSIZ+1];
23static struct protoent proto;
24static char *proto_aliases[MAXALIASES];
5442f2c7 25int _proto_stayopen;
eef09c7b 26
24fac7d8 27void
eef09c7b
SL
28setprotoent(f)
29 int f;
30{
31 if (protof == NULL)
29eb0a7d 32 protof = fopen(_PATH_PROTOCOLS, "r" );
eef09c7b
SL
33 else
34 rewind(protof);
5442f2c7 35 _proto_stayopen |= f;
eef09c7b
SL
36}
37
24fac7d8 38void
eef09c7b
SL
39endprotoent()
40{
5442f2c7 41 if (protof) {
eef09c7b
SL
42 fclose(protof);
43 protof = NULL;
44 }
5442f2c7 45 _proto_stayopen = 0;
eef09c7b
SL
46}
47
48struct protoent *
49getprotoent()
50{
51 char *p;
52 register char *cp, **q;
53
29eb0a7d 54 if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL)
eef09c7b
SL
55 return (NULL);
56again:
57 if ((p = fgets(line, BUFSIZ, protof)) == NULL)
58 return (NULL);
59 if (*p == '#')
60 goto again;
24fac7d8 61 cp = strpbrk(p, "#\n");
eef09c7b
SL
62 if (cp == NULL)
63 goto again;
64 *cp = '\0';
65 proto.p_name = p;
24fac7d8 66 cp = strpbrk(p, " \t");
eef09c7b
SL
67 if (cp == NULL)
68 goto again;
69 *cp++ = '\0';
70 while (*cp == ' ' || *cp == '\t')
71 cp++;
24fac7d8 72 p = strpbrk(cp, " \t");
eef09c7b
SL
73 if (p != NULL)
74 *p++ = '\0';
75 proto.p_proto = atoi(cp);
9243aabf
SL
76 q = proto.p_aliases = proto_aliases;
77 if (p != NULL) {
78 cp = p;
463dee20 79 while (cp && *cp) {
9243aabf
SL
80 if (*cp == ' ' || *cp == '\t') {
81 cp++;
82 continue;
83 }
84 if (q < &proto_aliases[MAXALIASES - 1])
85 *q++ = cp;
24fac7d8 86 cp = strpbrk(cp, " \t");
463dee20 87 if (cp != NULL)
9243aabf 88 *cp++ = '\0';
eef09c7b 89 }
eef09c7b
SL
90 }
91 *q = NULL;
92 return (&proto);
93}