proto.c 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <netdb.h>
  2. #include <string.h>
  3. /* do we really need all these?? */
  4. static int idx;
  5. static const unsigned char protos[][8] = {
  6. "\000ip",
  7. "\001icmp",
  8. "\002igmp",
  9. "\003ggp",
  10. "\006tcp",
  11. "\014pup",
  12. "\021udp",
  13. "\026idp",
  14. "\051ipv6",
  15. "\072icmpv6",
  16. "\377raw",
  17. "\0\0"
  18. };
  19. void endprotoent(void)
  20. {
  21. idx = 0;
  22. }
  23. void setprotoent(int stayopen)
  24. {
  25. idx = 0;
  26. }
  27. struct protoent *getprotoent(void)
  28. {
  29. static struct protoent p;
  30. static const char *aliases;
  31. if (!protos[idx][1]) return NULL;
  32. p.p_proto = protos[idx][0];
  33. p.p_name = (char *)protos[idx++]+1;
  34. p.p_aliases = (char **)&aliases;
  35. return &p;
  36. }
  37. struct protoent *getprotobyname(const char *name)
  38. {
  39. struct protoent *p;
  40. endprotoent();
  41. do p = getprotoent();
  42. while (p && strcmp(name, p->p_name));
  43. return p;
  44. }
  45. struct protoent *getprotobynumber(int num)
  46. {
  47. struct protoent *p;
  48. endprotoent();
  49. do p = getprotoent();
  50. while (p && p->p_proto != num);
  51. return p;
  52. }