ip.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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
  59. */
  60. enum
  61. {
  62. Udphdrsize= 36, /* size of a Udphdr */
  63. };
  64. typedef struct Udphdr Udphdr;
  65. struct Udphdr
  66. {
  67. uchar raddr[IPaddrlen]; /* remote address and port */
  68. uchar laddr[IPaddrlen]; /* local address and port */
  69. uchar rport[2];
  70. uchar lport[2];
  71. };
  72. uchar* defmask(uchar*);
  73. void maskip(uchar*, uchar*, uchar*);
  74. int eipfmt(Fmt*);
  75. int isv4(uchar*);
  76. ulong parseip(uchar*, char*);
  77. ulong parseipmask(uchar*, char*);
  78. char* v4parseip(uchar*, char*);
  79. char* v4parsecidr(uchar*, uchar*, char*);
  80. int parseether(uchar*, char*);
  81. int myipaddr(uchar*, char*);
  82. int myetheraddr(uchar*, char*);
  83. int equivip(uchar*, uchar*);
  84. Ipifc* readipifc(char*, Ipifc*, int);
  85. void hnputl(void*, uint);
  86. void hnputs(void*, ushort);
  87. uint nhgetl(void*);
  88. ushort nhgets(void*);
  89. ushort ptclbsum(uchar*, int);
  90. int v6tov4(uchar*, uchar*);
  91. void v4tov6(uchar*, uchar*);
  92. #define ipcmp(x, y) memcmp(x, y, IPaddrlen)
  93. #define ipmove(x, y) memmove(x, y, IPaddrlen)
  94. extern uchar IPv4bcast[IPaddrlen];
  95. extern uchar IPv4bcastobs[IPaddrlen];
  96. extern uchar IPv4allsys[IPaddrlen];
  97. extern uchar IPv4allrouter[IPaddrlen];
  98. extern uchar IPnoaddr[IPaddrlen];
  99. extern uchar v4prefix[IPaddrlen];
  100. extern uchar IPallbits[IPaddrlen];
  101. #define CLASS(p) ((*(uchar*)(p))>>6)
  102. #pragma varargck type "I" uchar*
  103. #pragma varargck type "V" uchar*
  104. #pragma varargck type "E" uchar*
  105. #pragma varargck type "M" uchar*