diff options
author | Rich Felker <dalias@aerifal.cx> | 2011-02-12 00:22:29 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2011-02-12 00:22:29 -0500 |
commit | 0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 (patch) | |
tree | 6eaef0d8a720fa3da580de87b647fff796fe80b3 /src/network/proto.c | |
download | musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.gz |
initial check-in, version 0.5.0v0.5.0
Diffstat (limited to 'src/network/proto.c')
-rw-r--r-- | src/network/proto.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/network/proto.c b/src/network/proto.c new file mode 100644 index 00000000..8c25c53a --- /dev/null +++ b/src/network/proto.c @@ -0,0 +1,58 @@ +#include <netdb.h> +#include <stdio.h> +#include <string.h> + +/* do we really need all these?? */ + +static int idx; +static const unsigned char protos[][6] = { + "\000ip", + "\001icmp", + "\002igmp", + "\003ggp", + "\006tcp", + "\014pup", + "\021udp", + "\026idp", + "\377raw" + "\0\0" +}; + +void endprotoent(void) +{ + idx = 0; +} + +void setprotoent(int stayopen) +{ + idx = 0; +} + +struct protoent *getprotoent(void) +{ + static struct protoent p; + static const char *aliases; + if (!protos[idx][1]) return NULL; + p.p_proto = protos[idx][0]; + p.p_name = (char *)protos[idx++]+1; + p.p_aliases = (char **)&aliases; + return &p; +} + +struct protoent *getprotobyname(const char *name) +{ + struct protoent *p; + endprotoent(); + do p = getprotoent(); + while (p && strcmp(name, p->p_name)); + return p; +} + +struct protoent *getprotobynumber(int num) +{ + struct protoent *p; + endprotoent(); + do p = getprotoent(); + while (p && p->p_proto != num); + return p; +} |