linux.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Special compatibility definitions for linux.
  3. *
  4. * On the linux platform, several IP-related structures have
  5. * different names. Also some of the structure fields have
  6. * other names, although the layout is (obviously) fixed.
  7. * Several constants are not defined in the standard files.
  8. *
  9. * @(#)linux.h e07@nikhef.nl (Eric Wassenaar) 960301
  10. *
  11. * XXX [src] - This is a complete ripoff from the fping program
  12. */
  13. #if defined(linux)
  14. #include <endian.h> /* to get the proper BYTE_ORDER */
  15. #if !defined(BYTE_ORDER) || (BYTE_ORDER != BIG_ENDIAN && \
  16. BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != PDP_ENDIAN)
  17. error "Undefined or invalid BYTE_ORDER";
  18. #endif
  19. /*
  20. * Structure of an ip header, without options.
  21. */
  22. #define IPVERSION 4
  23. struct ip {
  24. #if (BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN)
  25. u_char ip_hl:4, /* header length */
  26. ip_v:4; /* version */
  27. #else
  28. u_char ip_v:4, /* version */
  29. ip_hl:4; /* header length */
  30. #endif
  31. u_char ip_tos; /* type of service */
  32. short ip_len; /* total length */
  33. u_short ip_id; /* identification */
  34. short ip_off; /* fragment offset field */
  35. #define IP_DF 0x4000 /* dont fragment flag */
  36. #define IP_MF 0x2000 /* more fragments flag */
  37. u_char ip_ttl; /* time to live */
  38. u_char ip_p; /* protocol */
  39. u_short ip_sum; /* checksum */
  40. struct in_addr ip_src, ip_dst; /* source and dest address */
  41. };
  42. #define IP_MAXPACKET 65535 /* maximum packet size */
  43. /*
  44. * Structure of an icmp header.
  45. */
  46. struct icmp {
  47. u_char icmp_type; /* type of message, see below */
  48. u_char icmp_code; /* type sub code */
  49. u_short icmp_cksum; /* ones complement cksum of struct */
  50. union {
  51. u_char ih_pptr; /* ICMP_PARAMPROB */
  52. struct in_addr ih_gwaddr; /* ICMP_REDIRECT */
  53. struct ih_idseq {
  54. n_short icd_id;
  55. n_short icd_seq;
  56. } ih_idseq;
  57. int ih_void;
  58. } icmp_hun;
  59. #define icmp_pptr icmp_hun.ih_pptr
  60. #define icmp_gwaddr icmp_hun.ih_gwaddr
  61. #define icmp_id icmp_hun.ih_idseq.icd_id
  62. #define icmp_seq icmp_hun.ih_idseq.icd_seq
  63. #define icmp_void icmp_hun.ih_void
  64. union {
  65. struct id_ts {
  66. n_time its_otime;
  67. n_time its_rtime;
  68. n_time its_ttime;
  69. } id_ts;
  70. struct id_ip {
  71. struct ip idi_ip;
  72. /* options and then 64 bits of data */
  73. } id_ip;
  74. u_long id_mask;
  75. char id_data[1];
  76. } icmp_dun;
  77. #define icmp_otime icmp_dun.id_ts.its_otime
  78. #define icmp_rtime icmp_dun.id_ts.its_rtime
  79. #define icmp_ttime icmp_dun.id_ts.its_ttime
  80. #define icmp_ip icmp_dun.id_ip.idi_ip
  81. #define icmp_mask icmp_dun.id_mask
  82. #define icmp_data icmp_dun.id_data
  83. };
  84. #define ICMP_MINLEN 8 /* abs minimum */
  85. /*
  86. * Definition of icmp type and code field values.
  87. */
  88. #define ICMP_ECHOREPLY 0 /* echo reply */
  89. #define ICMP_UNREACH 3 /* dest unreachable, codes: */
  90. #define ICMP_UNREACH_NET 0 /* bad net */
  91. #define ICMP_UNREACH_HOST 1 /* bad host */
  92. #define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */
  93. #define ICMP_UNREACH_PORT 3 /* bad port */
  94. #define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */
  95. #define ICMP_UNREACH_SRCFAIL 5 /* src route failed */
  96. #define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */
  97. #define ICMP_REDIRECT 5 /* shorter route, codes: */
  98. #define ICMP_REDIRECT_NET 0 /* for network */
  99. #define ICMP_REDIRECT_HOST 1 /* for host */
  100. #define ICMP_REDIRECT_TOSNET 2 /* for tos and net */
  101. #define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */
  102. #define ICMP_ECHO 8 /* echo service */
  103. #define ICMP_TIMXCEED 11 /* time exceeded, codes: */
  104. #define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */
  105. #define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */
  106. #define ICMP_PARAMPROB 12 /* ip header bad */
  107. #define ICMP_TSTAMP 13 /* timestamp request */
  108. #define ICMP_TSTAMPREPLY 14 /* timestamp reply */
  109. #define ICMP_IREQ 15 /* information request */
  110. #define ICMP_IREQREPLY 16 /* information reply */
  111. #define ICMP_MASKREQ 17 /* address mask request */
  112. #define ICMP_MASKREPLY 18 /* address mask reply */
  113. /*
  114. * Definitions needed for the udp header structure.
  115. */
  116. #define uh_sport source
  117. #define uh_dport dest
  118. #define uh_ulen len
  119. #define uh_sum check
  120. #endif /* linux */