Don't give an error message on unknown options
[unix-history] / usr / src / lib / libc / net / getprotoent.c
CommitLineData
5e649950 1/* getprotoent.c 4.2 82/10/05 */
eef09c7b
SL
2
3#include <stdio.h>
4#include <sys/socket.h>
5#include <netdb.h>
6#include <ctype.h>
7
8#define MAXALIASES 35
9
10static char *PROTODB = "/usr/lib/protocols";
11static FILE *protof = NULL;
12static char line[BUFSIZ+1];
13static struct protoent proto;
14static char *proto_aliases[MAXALIASES];
15static int stayopen = 0;
eef09c7b
SL
16static char *any();
17
18setprotoent(f)
19 int f;
20{
21 if (protof == NULL)
22 protof = fopen(PROTODB, "r" );
23 else
24 rewind(protof);
25 stayopen |= f;
26}
27
28endprotoent()
29{
30 if (protof && !stayopen) {
31 fclose(protof);
32 protof = NULL;
33 }
34}
35
36struct protoent *
37getprotoent()
38{
39 char *p;
40 register char *cp, **q;
41
42 if (protof == NULL && (protof = fopen(PROTODB, "r" )) == NULL)
43 return (NULL);
44again:
45 if ((p = fgets(line, BUFSIZ, protof)) == NULL)
46 return (NULL);
47 if (*p == '#')
48 goto again;
49 cp = any(p, "#\n");
50 if (cp == NULL)
51 goto again;
52 *cp = '\0';
53 proto.p_name = p;
54 cp = any(p, " \t");
55 if (cp == NULL)
56 goto again;
57 *cp++ = '\0';
58 while (*cp == ' ' || *cp == '\t')
59 cp++;
60 p = any(cp, " \t");
61 if (p != NULL)
62 *p++ = '\0';
63 proto.p_proto = atoi(cp);
64 proto.p_aliases = proto_aliases;
65 cp = p;
66 q = proto_aliases;
67 while (*cp) {
68 if (*cp == ' ' || *cp == '\t') {
69 cp++;
70 continue;
71 }
72 if (q < &proto_aliases[MAXALIASES - 1])
73 *q++ = cp;
74 cp = any(cp, " \t");
75 if (*cp != NULL)
76 *cp++ = '\0';
77 }
78 *q = NULL;
79 return (&proto);
80}
81
82static char *
83any(cp, match)
84 register char *cp;
85 char *match;
86{
87 register char *mp, c;
88
89 while (c = *cp) {
90 for (mp = match; *mp; mp++)
91 if (*mp == c)
92 return (cp);
93 cp++;
94 }
95 return ((char *)0);
96}