ip.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #pragma src "/sys/src/libip"
  2. #pragma lib "libip.a"
  3. enum
  4. {
  5. IPaddrlen= 16,
  6. IPv4addrlen= 4,
  7. IPv4off= 12,
  8. IPllen= 4,
  9. };
  10. /*
  11. * for reading /net/ipifc
  12. */
  13. typedef struct Ipifc Ipifc;
  14. typedef struct Iplifc Iplifc;
  15. typedef struct Ipv6rp Ipv6rp;
  16. /* local address */
  17. struct Iplifc
  18. {
  19. Iplifc *next;
  20. /* per address on the ip interface */
  21. uchar ip[IPaddrlen];
  22. uchar mask[IPaddrlen];
  23. uchar net[IPaddrlen]; /* ip & mask */
  24. ulong preflt; /* preferred lifetime */
  25. ulong validlt; /* valid lifetime */
  26. };
  27. /* default values, one per stack */
  28. struct Ipv6rp
  29. {
  30. int mflag;
  31. int oflag;
  32. int maxraint;
  33. int minraint;
  34. int linkmtu;
  35. int reachtime;
  36. int rxmitra;
  37. int ttl;
  38. int routerlt;
  39. };
  40. /* actual interface */
  41. struct Ipifc
  42. {
  43. Ipifc *next;
  44. Iplifc *lifc;
  45. /* per ip interface */
  46. int index; /* number of interface in ipifc dir */
  47. char dev[64];
  48. uchar sendra6; /* on == send router adv */
  49. uchar recvra6; /* on == rcv router adv */
  50. int mtu;
  51. ulong pktin;
  52. ulong pktout;
  53. ulong errin;
  54. ulong errout;
  55. Ipv6rp rp;
  56. };
  57. /*
  58. * user level udp headers with cntrol message "oldheaders".
  59. * this is now considered obsolete.
  60. */
  61. enum
  62. {
  63. OUdphdrsize= 36, /* size of a OUdphdr */
  64. };
  65. typedef struct OUdphdr OUdphdr;
  66. struct OUdphdr
  67. {
  68. uchar raddr[IPaddrlen]; /* remote address and port */
  69. uchar laddr[IPaddrlen]; /* local address and port */
  70. uchar rport[2];
  71. uchar lport[2];
  72. };
  73. /*
  74. * user level udp headers with cntrol message "headers"
  75. */
  76. enum
  77. {
  78. Udphdrsize= 52, /* size of a Udphdr */
  79. };
  80. typedef struct Udphdr Udphdr;
  81. struct Udphdr
  82. {
  83. uchar raddr[IPaddrlen]; /* remote address */
  84. uchar laddr[IPaddrlen]; /* local address */
  85. uchar ifcaddr[IPaddrlen]; /* address of ifc message was received from
  86. (only useful on reception) */
  87. uchar rport[2]; /* remove port */
  88. uchar lport[2]; /* local port */
  89. };
  90. uchar* defmask(uchar*);
  91. void maskip(uchar*, uchar*, uchar*);
  92. int eipfmt(Fmt*);
  93. int isv4(uchar*);
  94. ulong parseip(uchar*, char*);
  95. ulong parseipmask(uchar*, char*);
  96. char* v4parseip(uchar*, char*);
  97. char* v4parsecidr(uchar*, uchar*, char*);
  98. int parseether(uchar*, char*);
  99. int myipaddr(uchar*, char*);
  100. int myetheraddr(uchar*, char*);
  101. int equivip(uchar*, uchar*);
  102. Ipifc* readipifc(char*, Ipifc*, int);
  103. void hnputl(void*, uint);
  104. void hnputs(void*, ushort);
  105. uint nhgetl(void*);
  106. ushort nhgets(void*);
  107. ushort ptclbsum(uchar*, int);
  108. int v6tov4(uchar*, uchar*);
  109. void v4tov6(uchar*, uchar*);
  110. #define ipcmp(x, y) memcmp(x, y, IPaddrlen)
  111. #define ipmove(x, y) memmove(x, y, IPaddrlen)
  112. extern uchar IPv4bcast[IPaddrlen];
  113. extern uchar IPv4bcastobs[IPaddrlen];
  114. extern uchar IPv4allsys[IPaddrlen];
  115. extern uchar IPv4allrouter[IPaddrlen];
  116. extern uchar IPnoaddr[IPaddrlen];
  117. extern uchar v4prefix[IPaddrlen];
  118. extern uchar IPallbits[IPaddrlen];
  119. #define CLASS(p) ((*(uchar*)(p))>>6)
  120. #pragma varargck type "I" uchar*
  121. #pragma varargck type "V" uchar*
  122. #pragma varargck type "E" uchar*
  123. #pragma varargck type "M" uchar*