proto.c 918 B

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