proto.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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[] = {
  6. "\000ip\0"
  7. "\001icmp\0"
  8. "\002igmp\0"
  9. "\003ggp\0"
  10. "\004ipencap\0"
  11. "\005st\0"
  12. "\006tcp\0"
  13. "\010egp\0"
  14. "\014pup\0"
  15. "\021udp\0"
  16. "\024hmp\0"
  17. "\026xns-idp\0"
  18. "\033rdp\0"
  19. "\035iso-tp4\0"
  20. "\044xtp\0"
  21. "\045ddp\0"
  22. "\046idpr-cmtp\0"
  23. "\051ipv6\0"
  24. "\053ipv6-route\0"
  25. "\054ipv6-frag\0"
  26. "\055idrp\0"
  27. "\056rsvp\0"
  28. "\057gre\0"
  29. "\062esp\0"
  30. "\063ah\0"
  31. "\071skip\0"
  32. "\072ipv6-icmp\0"
  33. "\073ipv6-nonxt\0"
  34. "\074ipv6-opts\0"
  35. "\111rspf\0"
  36. "\121vmtp\0"
  37. "\131ospf\0"
  38. "\136ipip\0"
  39. "\142encap\0"
  40. "\147pim\0"
  41. "\377raw"
  42. };
  43. void endprotoent(void)
  44. {
  45. idx = 0;
  46. }
  47. void setprotoent(int stayopen)
  48. {
  49. idx = 0;
  50. }
  51. struct protoent *getprotoent(void)
  52. {
  53. static struct protoent p;
  54. static const char *aliases;
  55. if (idx >= sizeof protos) return NULL;
  56. p.p_proto = protos[idx];
  57. p.p_name = (char *)&protos[idx+1];
  58. p.p_aliases = (char **)&aliases;
  59. idx += strlen(p.p_name) + 2;
  60. return &p;
  61. }
  62. struct protoent *getprotobyname(const char *name)
  63. {
  64. struct protoent *p;
  65. endprotoent();
  66. do p = getprotoent();
  67. while (p && strcmp(name, p->p_name));
  68. return p;
  69. }
  70. struct protoent *getprotobynumber(int num)
  71. {
  72. struct protoent *p;
  73. endprotoent();
  74. do p = getprotoent();
  75. while (p && p->p_proto != num);
  76. return p;
  77. }