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

ip.h File Reference

IP (Internet Protocol) layer header. More...

Go to the source code of this file.

Data Structures

struct  ip
 The IP packet structure. More...


Defines

#define IP_V4   4
 IP version 4.

#define IP_V6   6
 IP version 6.

#define IP_FRAME_LEN   65535
 Maximum IP frame length.

#define IP_HEAD_MIN_LEN   20
 Minimum IP header length.

#define IP_DEFAULT_TTL   64
 Default TTL (Time To Live).

#define IPPROTO_ICMP   1
 ICMP (Internet Control Message Protocol) packet type.

#define IPPROTO_IGMP   2
 IGMP (Internet Group Message Protocol) packet type.

#define IPPROTO_TCP   6
 TCP (Transmition Control Protocol) packet type.

#define IPPROTO_UDP   17
 UDP (User Datagram Protocol) packet type.

#define IP_TOS_MIN_DELAY   0x10
 Type of service :: Minimum delay.

#define IP_TOS_MAX_THRU   0x08
 Type of service :: Maximum throughput.

#define IP_TOS_MAX_RELY   0x04
 Type of service :: Maximum rely.

#define IP_TOS_MIN_COST   0x02
 Type of service :: Minimum cost.

#define IP_FLAG_MF   0x2000
 More Fragments.

#define IP_FLAG_DF   0x4000
 Don't Fragment.

#define IP_FLAG_CE   0x8000
 The CE flag.

#define IP_FLAG_MASK   0x1FFF
 The flag mask.

#define IP_ADDRESS(a, b, c, d)   ((a) | (b) << 8 | (c) << 16 | (d) << 24)
 Create an IP address in the binary network format from the notation "a.b.c.d".

#define IP_A(ip)   ((uint8_t) ((ip) >> 24))
 Get the 1st most significant byte of a host-format IP address.

#define IP_B(ip)   ((uint8_t) ((ip) >> 16))
 Get the 2nd most significant byte of a host-format IP address.

#define IP_C(ip)   ((uint8_t) ((ip) >> 8))
 Get the 3rd most significant byte of a host-format IP address.

#define IP_D(ip)   ((uint8_t) ((ip) >> 0))
 Get the less significant byte of a host-format IP address.

#define INADDR_LOOPBACK   IP_ADDRESS(127, 0, 0, 1)
 Loopback IP address.

#define INADDR_ANY   IP_ADDRESS(0, 0, 0, 0)
 Null IP address.

#define INADDR_BROADCAST   IP_ADDRESS(255, 255, 255, 255)
 Broadcast IP address.


Typedefs

typedef uint32_t in_addr_t
 IP address type (in binary network format).

typedef ip ip_t
 The IP packet structure.


Functions

uint16_t ip_checksum (const void *buf, size_t hdr_len)
 Calculate the IP header checksum.
Parameters:
buf  The IP header content.
hdr_len  The IP header length.
Returns:
The result of the checksum.


void set_host_ip_net (in_addr_t ip, in_addr_t netmask)
 Set the IP and netmask for this host.
Parameters:
ip  The IP address in network format.
netmask  The netmask in network format.


in_addr_t get_host_ip ()
 Get the IP address of this host.
Returns:
The IP address expressed in network format.


in_addr_t get_host_netmask ()
 Get the netmask of this host.
Returns:
The netmask expressed in network format.


in_addr_t get_host_bcast ()
 Get the broadcast address of the local network.
Returns:
The broadcast address of this local network expressed in network format.


void to_ip_layer (ip_t *packet)
 Process an IP packet received from the ethernet layer.
Parameters:
packet  The IP packet.


int inet_aton (const char *cp, in_addr_t *inp)
 Converts an internet IP addres from number-and-dot string notation into binary data network byte order.
Parameters:
cp  The string of the number-and-dot notation IP address.
inp  The destination where the binary network byte order address will be put.
Returns:
Nonzero if the address is valid, zero if not.


int send_ip_packet (uint32_t ip_to, const void *data, size_t len, uint8_t ttl, uint8_t proto)
 Send an IP packet to the ethernet layer.
Parameters:
ip_to  The IP destination address in network format.
data  The buffer of data to be sent.
len  The size of the buffer to be sent.
ttl  TTL (Time To Live).
proto  The upper-layer protocol type.
Returns:
  • The number of bytes sent in case of success;
  • -EMSGSIZE the packet is too big to be sent;
  • -ENOMEM cannot allocate the packet structure;
  • -ENETUNREACH destination address not found;.



Detailed Description

IP (Internet Protocol) layer header.

Author:
Andrea Righi <drizzt@inwind.it>
Date:
Last update: 2003-11-09
Note:
Copyright (©) 2003 Andrea Righi

Definition in file ip.h.


Define Documentation

#define IP_DEFAULT_TTL   64
 

Default TTL (Time To Live).

Definition at line 21 of file ip.h.

#define IP_FLAG_CE   0x8000
 

The CE flag.

Definition at line 47 of file ip.h.

#define IP_FLAG_DF   0x4000
 

Don't Fragment.

Definition at line 45 of file ip.h.

#define IP_FLAG_MASK   0x1FFF
 

The flag mask.

Definition at line 49 of file ip.h.

#define IP_FLAG_MF   0x2000
 

More Fragments.

Definition at line 43 of file ip.h.

#define IP_FRAME_LEN   65535
 

Maximum IP frame length.

Definition at line 17 of file ip.h.

#define IP_HEAD_MIN_LEN   20
 

Minimum IP header length.

Definition at line 19 of file ip.h.

#define IP_TOS_MAX_RELY   0x04
 

Type of service :: Maximum rely.

Definition at line 37 of file ip.h.

#define IP_TOS_MAX_THRU   0x08
 

Type of service :: Maximum throughput.

Definition at line 35 of file ip.h.

#define IP_TOS_MIN_COST   0x02
 

Type of service :: Minimum cost.

Definition at line 39 of file ip.h.

#define IP_TOS_MIN_DELAY   0x10
 

Type of service :: Minimum delay.

Definition at line 33 of file ip.h.

#define IP_V4   4
 

IP version 4.

Definition at line 12 of file ip.h.

#define IP_V6   6
 

IP version 6.

Definition at line 14 of file ip.h.

#define IPPROTO_ICMP   1
 

ICMP (Internet Control Message Protocol) packet type.

Definition at line 24 of file ip.h.

#define IPPROTO_IGMP   2
 

IGMP (Internet Group Message Protocol) packet type.

Definition at line 26 of file ip.h.

#define IPPROTO_TCP   6
 

TCP (Transmition Control Protocol) packet type.

Definition at line 28 of file ip.h.

#define IPPROTO_UDP   17
 

UDP (User Datagram Protocol) packet type.

Definition at line 30 of file ip.h.


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