Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

ip.h

Go to the documentation of this file.
00001 /*!     \file include/net/ip.h
00002  *      \brief IP (Internet Protocol) layer header.
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date Last update: 2003-11-09
00005  *      \note Copyright (&copy;) 2003 Andrea Righi
00006  */
00007 
00008 #ifndef IP_H
00009 #define IP_H
00010 
00011 //! IP version 4.
00012 #define IP_V4                   4
00013 //! IP version 6.
00014 #define IP_V6                   6
00015 
00016 //! Maximum IP frame length.
00017 #define IP_FRAME_LEN            65535
00018 //! Minimum IP header length.
00019 #define IP_HEAD_MIN_LEN         20
00020 //! Default TTL (Time To Live).
00021 #define IP_DEFAULT_TTL          64
00022 
00023 //! ICMP (Internet Control Message Protocol) packet type.
00024 #define IPPROTO_ICMP            1
00025 //! IGMP (Internet Group Message Protocol) packet type.
00026 #define IPPROTO_IGMP            2
00027 //! TCP (Transmition Control Protocol) packet type.
00028 #define IPPROTO_TCP             6
00029 //! UDP (User Datagram Protocol) packet type.
00030 #define IPPROTO_UDP             17
00031 
00032 //! Type of service :: Minimum delay.
00033 #define IP_TOS_MIN_DELAY        0x10
00034 //! Type of service :: Maximum throughput.
00035 #define IP_TOS_MAX_THRU         0x08
00036 //! Type of service :: Maximum rely.
00037 #define IP_TOS_MAX_RELY         0x04
00038 //! Type of service :: Minimum cost.
00039 #define IP_TOS_MIN_COST         0x02
00040 
00041 // Fragment flags                                                       //
00042 //! More Fragments.
00043 #define IP_FLAG_MF              0x2000
00044 //! Don't Fragment.
00045 #define IP_FLAG_DF              0x4000
00046 //! The CE flag.
00047 #define IP_FLAG_CE              0x8000
00048 //! The flag mask.
00049 #define IP_FLAG_MASK            0x1FFF
00050 
00051 /** \ingroup Network
00052  *  \defgroup NetIP IP (Internet Protocol) layer
00053  *  The IP (Internet Protocol) layer.
00054  *  @{
00055  */
00056 
00057 //! Create an IP address in the binary network format
00058 //! from the notation "a.b.c.d".
00059 #define IP_ADDRESS(a, b, c, d)  ((a) | (b) << 8 | (c) << 16 | (d) << 24)
00060 //! Get the 1st most significant byte of a host-format IP address.
00061 #define IP_A(ip)                ((uint8_t) ((ip) >> 24))
00062 //! Get the 2nd most significant byte of a host-format IP address.
00063 #define IP_B(ip)                ((uint8_t) ((ip) >> 16))
00064 //! Get the 3rd most significant byte of a host-format IP address.
00065 #define IP_C(ip)                ((uint8_t) ((ip) >>  8))
00066 //! Get the less significant byte of a host-format IP address.
00067 #define IP_D(ip)                ((uint8_t) ((ip) >>  0))
00068 
00069 //! Loopback IP address.
00070 #define INADDR_LOOPBACK         IP_ADDRESS(127, 0, 0, 1)
00071 //! Null IP address.
00072 #define INADDR_ANY              IP_ADDRESS(0, 0, 0, 0)
00073 //! Broadcast IP address.
00074 #define INADDR_BROADCAST        IP_ADDRESS(255, 255, 255, 255)
00075 
00076 //! IP address type (in binary network format).
00077 typedef uint32_t in_addr_t;
00078 
00079 //! The IP packet structure.
00080 typedef struct ip
00081 {
00082 #if __BYTE_ORDER__ == __LITTLE_ENDIAN__
00083         uint8_t ip_hdr_len:4;   //!< The header length.
00084         uint8_t ip_version:4;   //!< The IP version.
00085 #else
00086         uint8_t ip_version:4;   //!< The IP version.
00087         uint8_t ip_hdr_len:4;   //!< The IP header length.
00088 #endif
00089         //! Type of Service.
00090         uint8_t ip_tos;
00091         //! IP packet length (both data and header).
00092         uint16_t ip_len;
00093 
00094         //! Identification.
00095         uint16_t ip_id;
00096         //! Fragment offset.
00097         uint16_t ip_off;
00098 
00099         //! Time To Live.
00100         uint8_t ip_ttl;
00101         //! The type of the upper-level protocol.
00102         uint8_t ip_proto;
00103         //! IP header checksum.
00104         uint16_t ip_chk;
00105 
00106         //! IP source address (in network format).
00107         uint32_t ip_src;
00108         //! IP destination address (in network format).
00109         uint32_t ip_dst;
00110 } __attribute__ ((packed)) ip_t;
00111 
00112 // --- Prototypes ----------------------------------------------------- //
00113 
00114 uint16_t ip_checksum(const void *buf, size_t hdr_len);
00115 void set_host_ip_net(in_addr_t ip, in_addr_t netmask);
00116 in_addr_t get_host_ip();
00117 in_addr_t get_host_netmask();
00118 in_addr_t get_host_bcast();
00119 void to_ip_layer(ip_t *packet);
00120 int inet_aton(const char *cp, in_addr_t *inp);
00121 int send_ip_packet(uint32_t ip_to, const void *data, size_t len, uint8_t ttl, uint8_t proto);
00122 
00123 /** @} */ // end of NetIP
00124 
00125 #endif

Generated on Fri Feb 20 15:32:16 2004 for Minirighi by doxygen1.2.18