proto.c 976 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. "\057gre",
  16. "\062esp",
  17. "\063ah",
  18. "\072icmpv6",
  19. "\136ipip",
  20. "\377raw",
  21. "\0\0"
  22. };
  23. void endprotoent(void)
  24. {
  25. idx = 0;
  26. }
  27. void setprotoent(int stayopen)
  28. {
  29. idx = 0;
  30. }
  31. struct protoent *getprotoent(void)
  32. {
  33. static struct protoent p;
  34. static const char *aliases;
  35. if (!protos[idx][1]) return NULL;
  36. p.p_proto = protos[idx][0];
  37. p.p_name = (char *)protos[idx++]+1;
  38. p.p_aliases = (char **)&aliases;
  39. return &p;
  40. }
  41. struct protoent *getprotobyname(const char *name)
  42. {
  43. struct protoent *p;
  44. endprotoent();
  45. do p = getprotoent();
  46. while (p && strcmp(name, p->p_name));
  47. return p;
  48. }
  49. struct protoent *getprotobynumber(int num)
  50. {
  51. struct protoent *p;
  52. endprotoent();
  53. do p = getprotoent();
  54. while (p && p->p_proto != num);
  55. return p;
  56. }