Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef _NETINET_IP_H
  2. #define _NETINET_IP_H
  3.  
  4. #include <inttypes.h>
  5. #include <endian.h>
  6. #include <netinet/in.h>
  7.  
  8. __BEGIN_DECLS
  9.  
  10. #define IPVERSION       4               /* IP version number */
  11. #define IP_MAXPACKET    65535           /* maximum packet size */
  12.  
  13. #define IPTOS_TOS_MASK          0x1E
  14. #define IPTOS_TOS(tos)          ((tos)&IPTOS_TOS_MASK)
  15. #define IPTOS_LOWDELAY          0x10
  16. #define IPTOS_THROUGHPUT        0x08
  17. #define IPTOS_RELIABILITY       0x04
  18. #define IPTOS_MINCOST           0x02
  19. #define IPTOS_LOWCOST           IPTOS_MINCOST
  20.  
  21. #define IPTOS_PREC_MASK         0xE0
  22. #define IPTOS_PREC(tos)         ((tos)&IPTOS_PREC_MASK)
  23. #define IPTOS_PREC_NETCONTROL           0xe0
  24. #define IPTOS_PREC_INTERNETCONTROL      0xc0
  25. #define IPTOS_PREC_CRITIC_ECP           0xa0
  26. #define IPTOS_PREC_FLASHOVERRIDE        0x80
  27. #define IPTOS_PREC_FLASH                0x60
  28. #define IPTOS_PREC_IMMEDIATE            0x40
  29. #define IPTOS_PREC_PRIORITY             0x20
  30. #define IPTOS_PREC_ROUTINE              0x00
  31.  
  32.  
  33. /* IP options */
  34. #define IPOPT_COPY              0x80
  35. #define IPOPT_CLASS_MASK        0x60
  36. #define IPOPT_NUMBER_MASK       0x1f
  37.  
  38. #define IPOPT_COPIED(o)         ((o)&IPOPT_COPY)
  39. #define IPOPT_CLASS(o)          ((o)&IPOPT_CLASS_MASK)
  40. #define IPOPT_NUMBER(o)         ((o)&IPOPT_NUMBER_MASK)
  41.  
  42. #define IPOPT_CONTROL           0x00
  43. #define IPOPT_RESERVED1         0x20
  44. #define IPOPT_MEASUREMENT       0x40
  45. #define IPOPT_RESERVED2         0x60
  46.  
  47. #define IPOPT_END       (0 |IPOPT_CONTROL)
  48. #define IPOPT_NOOP      (1 |IPOPT_CONTROL)
  49. #define IPOPT_SEC       (2 |IPOPT_CONTROL|IPOPT_COPY)
  50. #define IPOPT_LSRR      (3 |IPOPT_CONTROL|IPOPT_COPY)
  51. #define IPOPT_TIMESTAMP (4 |IPOPT_MEASUREMENT)
  52. #define IPOPT_RR        (7 |IPOPT_CONTROL)
  53. #define IPOPT_SID       (8 |IPOPT_CONTROL|IPOPT_COPY)
  54. #define IPOPT_SSRR      (9 |IPOPT_CONTROL|IPOPT_COPY)
  55. #define IPOPT_RA        (20|IPOPT_CONTROL|IPOPT_COPY)
  56.  
  57. #define IPVERSION       4
  58. #define MAXTTL          255
  59. #define IPDEFTTL        64
  60.  
  61. /* struct timestamp, struct route and MAX_ROUTES are removed.
  62.  
  63.    REASONS: it is clear that nobody used them because:
  64.    - MAX_ROUTES value was wrong.
  65.    - "struct route" was wrong.
  66.    - "struct timestamp" had fatally misaligned bitfields and was completely unusable.
  67.  */
  68.  
  69. #define IPOPT_OPTVAL 0
  70. #define IPOPT_OLEN   1
  71. #define IPOPT_OFFSET 2
  72. #define IPOPT_MINOFF 4
  73. #define MAX_IPOPTLEN 40
  74. #define IPOPT_NOP IPOPT_NOOP
  75. #define IPOPT_EOL IPOPT_END
  76. #define IPOPT_TS  IPOPT_TIMESTAMP
  77.  
  78. #define IPOPT_TS_TSONLY         0               /* timestamps only */
  79. #define IPOPT_TS_TSANDADDR      1               /* timestamps and addresses */
  80. #define IPOPT_TS_PRESPEC        3               /* specified modules only */
  81.  
  82. struct iphdr {                          /* size 20/0x14 */
  83. #if __BYTE_ORDER == __LITTLE_ENDIAN
  84.   unsigned int ihl:4, version:4;        /* offset 0; version=ip version (4) */
  85. #else
  86.   unsigned int version:4, ihl:4;        /* offset 0; ihl=ip header length, measured in words (5) */
  87. #endif
  88.   unsigned char tos;                    /* offset 1 */
  89.   unsigned short tot_len;               /* offset 2; total bytes in packet in network byte order */
  90.   unsigned short id;                    /* offset 4 */
  91.   unsigned short frag_off;              /* offset 6 */
  92.   unsigned char ttl;                    /* offset 8 */
  93.   unsigned char protocol;               /* offset 9; 1=ICMP, 6=TCP, 17=UDP (see netinet/in.h) */
  94.   unsigned short check;                 /* offset 10/0xa */
  95.   unsigned int saddr;                   /* offset 12/0xc */
  96.   unsigned int daddr;                   /* offset 16/0x10 */
  97.   /*The options start here. */
  98. };
  99.  
  100. struct ip {
  101. #if __BYTE_ORDER == __LITTLE_ENDIAN
  102.   unsigned int ip_hl:4;         /* header length */
  103.   unsigned int ip_v:4;          /* version */
  104. #endif
  105. #if __BYTE_ORDER == __BIG_ENDIAN
  106.   unsigned int ip_v:4;          /* version */
  107.   unsigned int ip_hl:4;         /* header length */
  108. #endif
  109.   unsigned char ip_tos;         /* type of service */
  110.   unsigned short ip_len;                /* total length */
  111.   unsigned short ip_id;         /* identification */
  112.   unsigned short ip_off;                /* fragment offset field */
  113. #define IP_RF 0x8000                    /* reserved fragment flag */
  114. #define IP_DF 0x4000                    /* dont fragment flag */
  115. #define IP_MF 0x2000                    /* more fragments flag */
  116. #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
  117.   unsigned char ip_ttl;         /* time to live */
  118.   unsigned char ip_p;                   /* protocol */
  119.   unsigned short ip_sum;                /* checksum */
  120.   struct in_addr ip_src, ip_dst;        /* source and dest address */
  121. };
  122.  
  123. __END_DECLS
  124.  
  125. #endif
  126.