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

IP Protocol

RFC 791 Internet protocol version 4. More...

Data Structures

struct  pseudo_hdr

Functions

void NutIpInput (NUTDEVICE *dev, NETBUF *nb)
 Process incoming IP datagrams. More...

int NutIpOutput (u_char proto, u_long dest, NETBUF *nb, u_char flags)
 Send IP datagram. More...

u_long inet_addr (const u_char *str)
 Convert decimal dotted ASCII representation into numeric IP address. More...

u_charinet_ntoa (u_long addr)
 Convert numeric IP address into decimal dotted ASCII representation. More...

int NutNetLoadConfig (const char *name)
int NutNetSaveConfig (void)
int NutNetIfSetup (NUTDEVICE *dev, u_long ip_addr, u_long ip_mask, u_long gateway)
int NutNetIfConfig (const char *name, const u_char *mac, u_long ip_addr, u_long ip_mask)
 Configure a network interface. More...

int NutNetAutoConfig (const char *name)
 Configure a network interface using EEPROM values. More...

u_short NutIpChkSumPartial (u_short partial_csum, void *buf, u_short count)
 Calculates a partial IP checksum over a block of data. More...

u_short NutIpChkSum (u_short partial_csum, void *buf, u_short count)
 Calculates an the final IP checksum over a block of data. More...

u_short NutIpPseudoChkSumPartial (u_long src_addr, u_long dest_addr, u_char protocol, u_short len)
 Calculates the partial IP pseudo checksum. More...

u_short NutIpPseudoChkSum (u_long src_addr, u_long dest_addr, u_char protocol, u_short len)
 Calculates the IP pseudo checksum. More...

int NutIpRouteAdd (u_long ip, u_long mask, u_long gate, NUTDEVICE *dev)
 Add a new entry to the IP routing table. More...

NUTDEVICENutIpRouteQuery (u_long ip, u_long *gate)
 Find a device associated with a particular IP route. More...


Variables

CONFNET confnet
RTENTRYrteList
 Linked list of routing entries.


Detailed Description

RFC 791 Internet protocol version 4.

Todo:
Configurable checksum calculation for incoming datagrams.

Version:
2.0.4
Author:
Harald Kipp, egnite Software GmbH

Version:
2.0.4
Author:
Harald Kipp, egnite Software GmbH

Function Documentation

u_short NutIpChkSum ( u_short partial_csum,
void * buf,
u_short count )
 

Calculates an the final IP checksum over a block of data.

Unlike the partial checksum in NutIpChkSumPartial(), this function takes the one's complement of the final result, thus making it the full checksum.

u_short NutIpChkSumPartial ( u_short partial_csum,
void * buf,
u_short count )
 

Calculates a partial IP checksum over a block of data.

Note that this returns the checksum in network byte order, and thus does not need to be converted via hton16(), etc. Of course this means that we mustn't use this value for normal arithmetic!

This is a partial checksum because it doesn't take the 1's complement of the overall sum.

void NutIpInput ( NUTDEVICE * dev,
NETBUF * nb )
 

Process incoming IP datagrams.

Datagrams addressed to other destinations and datagrams whose version number is not 4 are silently discarded.

Note:
This routine is called by the Ethernet layer on incoming IP datagrams. Applications typically do not call this function.
Parameters:
dev   Identifies the device that received this datagram.

int NutIpOutput ( u_char proto,
u_long dest,
NETBUF * nb,
u_char flags )
 

Send IP datagram.

Route an IP datagram to the proper interface.

The datagram may be sent synchronously or asynchronously.

If sent synchronously, the function will not return until the data has been stored in the network device hardware for transmission. If the device is not ready for transmitting a new packet, the calling thread will be suspended until the device becomes ready again. If the hardware address of the target host needs to be resolved the function will be suspended too. If this function returns without any error, the network buffer structure will not be released and may be reused for later retransmission.

If sent asynchronously, the function will not wait for hardware address resolution or a network device becoming ready for transmission. In such cases the network buffer structure will be buffered and tranmitted later in the background. The caller should not make any subsequent use of the network buffer structure.

Parameters:
proto   Protocol type.
dest   Destination IP address. The function will determine the proper network interface by checking the routing table. It will also perform any neccessary hardware address resolution.
nb   Network buffer strucutre containing the datagram. Will be released on asynchronous transmission or in case of an error.
flags   Set to 1 for asynchronous output, 0 otherwise.

Returns:
0 on success, -1 otherwise.

Bug:
Broadcasts to multiple network devices are currently not supported.

u_short NutIpPseudoChkSum ( u_long src_addr,
u_long dest_addr,
u_char protocol,
u_short len )
 

Calculates the IP pseudo checksum.

u_short NutIpPseudoChkSumPartial ( u_long src_addr,
u_long dest_addr,
u_char protocol,
u_short len )
 

Calculates the partial IP pseudo checksum.

int NutIpRouteAdd ( u_long ip,
u_long mask,
u_long gate,
NUTDEVICE * dev )
 

Add a new entry to the IP routing table.

Note, that there is currently no support for removing entries or detecting duplicates. Anyway, newer entries will be found first, because they are inserted in front of older entries. However, this works only for equal masks, i.e. new network routes will never overwrite old host routes.

Parameters:
ip   Network or host IP address to be route. Set 0 for default route.
mask   Mask for this entry. -1 for host routes, 0 for default or net mask for net routes.
gate   Route through this gateway, otherwise 0.
nif   Network interface to use. Not used for gateway routes.

Returns:
0 on success, -1 otherwise.

NUTDEVICE * NutIpRouteQuery ( u_long ip,
u_long * gate )
 

Find a device associated with a particular IP route.

Gateway routes will be automatically resolved up to four levels of redirection.

Parameters:
ip   IP address to find a route for, given in network byte order.
gate   Points to a buffer which optionally receives the IP address of a gateway. The pointer may be NULL, if the caller is not interested in this information.

Returns:
Pointer to the interface structure or NULL if no route was found.

int NutNetAutoConfig ( const char * name )
 

Configure a network interface using EEPROM values.

Loads IP address, netmask and MAC address from EEPROM and calls NutNetIfConfig().

Parameters:
name   Name of the device.

Returns:
0 on success, -1 otherwise.
Examples:
httpd/nutmain.c, portdio/portdio.c, tcpc/tcpc.c, and tcps/tcps.c.

int NutNetIfConfig ( const char * name,
const u_char * mac,
u_long ip_addr,
u_long ip_mask )
 

Configure a network interface.

Associates the given MAC address, IP address and netmask with the network interface.

Parameters:
name   Name of the device.
mac   6-byte Ethernet MAC address to be used.
ip_addr   IP address to be used.
ip_mask   IP network mask to be used.

Returns:
0 on success, -1 otherwise.

u_long inet_addr ( const u_char * str )
 

Convert decimal dotted ASCII representation into numeric IP address.

Parameters:
str   String containing the ASCII representation.

Returns:
IP address in network byte order.
Examples:
tcpc/tcpc.c.

u_char * inet_ntoa ( u_long addr )
 

Convert numeric IP address into decimal dotted ASCII representation.

Note:
This function is not thread safe. Each subsequent call will destroy the previous result. Applications should locally store the result before calling the function again or allowing other threads to call it.
Parameters:
addr   IP address in network byte order.

Returns:
Pointer to a static buffer containing the ASCII representation.


© 2000-2001 by egnite Software GmbH - visit http://www.ethernut.de/