ip.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. typedef struct Udphdr Udphdr;
  2. struct Udphdr
  3. {
  4. uchar d[6]; /* Ethernet destination */
  5. uchar s[6]; /* Ethernet source */
  6. uchar type[2]; /* Ethernet packet type */
  7. uchar vihl; /* Version and header length */
  8. uchar tos; /* Type of service */
  9. uchar length[2]; /* packet length */
  10. uchar id[2]; /* Identification */
  11. uchar frag[2]; /* Fragment information */
  12. /* Udp pseudo ip really starts here */
  13. uchar ttl;
  14. uchar udpproto; /* Protocol */
  15. uchar udpplen[2]; /* Header plus data length */
  16. uchar udpsrc[4]; /* Ip source */
  17. uchar udpdst[4]; /* Ip destination */
  18. uchar udpsport[2]; /* Source port */
  19. uchar udpdport[2]; /* Destination port */
  20. uchar udplen[2]; /* data length */
  21. uchar udpcksum[2]; /* Checksum */
  22. };
  23. typedef struct Etherhdr Etherhdr;
  24. struct Etherhdr
  25. {
  26. uchar d[6];
  27. uchar s[6];
  28. uchar type[2];
  29. /* Now we have the ip fields */
  30. uchar vihl; /* Version and header length */
  31. uchar tos; /* Type of service */
  32. uchar length[2]; /* packet length */
  33. uchar id[2]; /* Identification */
  34. uchar frag[2]; /* Fragment information */
  35. uchar ttl; /* Time to live */
  36. uchar proto; /* Protocol */
  37. uchar cksum[2]; /* Header checksum */
  38. uchar src[4]; /* Ip source */
  39. uchar dst[4]; /* Ip destination */
  40. };
  41. enum
  42. {
  43. IP_VER = 0x40,
  44. IP_HLEN = 0x05,
  45. UDP_EHSIZE = 22,
  46. UDP_PHDRSIZE = 12,
  47. UDP_HDRSIZE = 20,
  48. ETHER_HDR = 14,
  49. IP_UDPPROTO = 17,
  50. ET_IP = 0x800,
  51. Bcastip = 0xffffffff,
  52. BPportsrc = 68,
  53. BPportdst = 67,
  54. TFTPport = 69,
  55. Timeout = 5000, /* milliseconds */
  56. Bootrequest = 1,
  57. Bootreply = 2,
  58. Tftp_READ = 1,
  59. Tftp_WRITE = 2,
  60. Tftp_DATA = 3,
  61. Tftp_ACK = 4,
  62. Tftp_ERROR = 5,
  63. Segsize = 512,
  64. TFTPSZ = Segsize+10,
  65. };
  66. typedef struct Bootp Bootp;
  67. struct Bootp
  68. {
  69. uchar op; /* opcode */
  70. uchar htype; /* hardware type */
  71. uchar hlen; /* hardware address len */
  72. uchar hops; /* hops */
  73. uchar xid[4]; /* a random number */
  74. uchar secs[2]; /* elapsed since client started booting */
  75. uchar pad[2];
  76. uchar ciaddr[4]; /* client IP address (client tells server) */
  77. uchar yiaddr[4]; /* client IP address (server tells client) */
  78. uchar siaddr[4]; /* server IP address */
  79. uchar giaddr[4]; /* gateway IP address */
  80. uchar chaddr[16]; /* client hardware address */
  81. char sname[64]; /* server host name (optional) */
  82. char file[128]; /* boot file name */
  83. char vend[128]; /* vendor-specific goo */
  84. };
  85. typedef struct Netaddr Netaddr;
  86. struct Netaddr
  87. {
  88. ulong ip;
  89. ushort port;
  90. char ea[Eaddrlen];
  91. };
  92. extern int eipfmt(Fmt*);