ip.h 2.8 KB

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