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

IP
[Protocols]

RFC 791 Internet protocol version 4. More...

Data Structures

struct  _ARPENTRY
 ARP entry structure. More...

struct  _ARPENTRY
 ARP entry structure. More...

struct  _PPP_PARAMS
struct  ifnet
 Network interface structure. More...

struct  ifnet
 Network interface structure. More...

struct  ip
 Structure of an internet header. More...

struct  ip
 Structure of an internet header. More...

struct  pseudo_hdr

Defines

#define ATF_COM
 Completed entry.

#define ATF_PERM
 Permanent entry.

#define IPVERSION
 IP protocol version.

#define IP_DF
 Don't fragment flag.

#define IP_MF
 More fragments flag.

#define IP_OFFMASK
 Mask for fragmenting bits.

#define IPOPT_EOL
 End of option list.

#define IPOPT_NOP
 No operation.

#define IPOPT_RR
 Record packet route.

#define IPOPT_TS
 Timestamp.

#define IPOPT_SECURITY
 Provide s,c,h,tcc.

#define IPOPT_LSRR
 Loose source route.

#define IPOPT_SATID
 Satnet id.

#define IPOPT_SSRR
 Strict source route.

#define IPOPT_OPTVAL
 Option identifier offset.

#define IPOPT_OLEN
 Option length offset.

#define IPOPT_OFFSET
 Offset within option.

#define IPOPT_MINOFF
 Minimum offset within option.

#define MAXTTL
 Maximum time to live (seconds).

#define IPDEFTTL
 Default time to live.

#define IPFRAGTTL
 Time to live for fragments.

#define IPTTLDEC
 Subtracted from time to live when forwarding.


Typedefs

typedef _ARPENTRY ARPENTRY
 ARP entry type.

typedef ifnet IFNET
 Network interface type.

typedef ip IPHDR
 Internet header type.


Functions

int NutNetIfConfig (CONST char *name, void *mac_dev, u_long ip_addr, u_long ip_mask)
 Configure a network interface.

int NutNetIfSetup (NUTDEVICE *dev, u_long ip_addr, u_long ip_mask, u_long gateway)
int NutNetLoadConfig (CONST char *name)
 Load network configuration from EEPROM.

int NutNetSaveConfig (void)
 Save network configuration in EEPROM.

int NutNetAutoConfig (CONST char *name)
 Automatically configure a network interface.

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

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

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

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

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

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

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

u_short NutIpPseudoChkSum (u_long src_addr, u_long dest_addr, u_char protocol, u_short len)
 Calculates the 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.

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


Variables

RTENTRYrteList
 Linked list of routing entries.


Detailed Description

RFC 791 Internet protocol version 4.

Todo:
Configurable checksum calculation for incoming datagrams.

Author:
Harald Kipp, egnite Software GmbH

Author:
Harald Kipp, egnite Software GmbH

Typedef Documentation

typedef struct _ARPENTRY ARPENTRY
 

ARP entry type.

typedef struct ifnet IFNET
 

Network interface type.

typedef struct ip IPHDR
 

Internet header type.


Function Documentation

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:
httpd/httpserv.c, inetq/inetq.c, portdio/portdio.c, and tcps/tcps.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.
Examples:
httpd/httpserv.c, inetq/inetq.c, and tcps/tcps.c.

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.

Note:
by Dave Hudson: This doesn't look particularly intuitive at first sight - in fact it probably looks plain wrong. It does work however (take my word for it), but for some explanation the reader is referred to RFC1071 where the maths is explained in detail.

by Harald Kipp: Yes, the GCC version looks wrong. I assume that this will not work for all packet sizes. Not yet confirmed.

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.
nb The network buffer received.

int NutIpOutput u_char    proto,
u_long    dest,
NETBUF   nb
 

Send IP datagram.

Route an IP datagram to the proper interface.

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.

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 structure containing the datagram. This buffer will be released if the function returns an error.
Returns:
0 on success, -1 otherwise.

Bug:
Broadcasts to multiple network devices will fail after the first device returns an error.

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

Calculates the IP pseudo checksum.

u_long 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.
dev Network interface to use.
Returns:
0 on success, -1 otherwise.
Examples:
inetq/inetq.c.

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
 

Automatically configure a network interface.

This function is deprecated. New applications should call NutDhcpIfConfig().

Parameters:
name Name of the device.
Returns:
0 on success, -1 otherwise.
Examples:
rs232d/rs232d.c.

int NutNetIfConfig CONST char *    name,
void *    params,
u_long    ip_addr,
u_long    ip_mask
 

Configure a network interface.

Devices must have been registered by NutRegisterDevice() before calling this function.

For Ethernet devices applications may alternatively call NutNetAutoConfig(), which allows automatic configuration by DHCP or the so called ARP method.

Parameters:
name Name of the device to configure.
params Pointer to interface specific parameters. For PPP interfaces this is a pointer to the PPP_PARAMS structure. For Ethernet interfaces this parameter is ignored.
ip_addr Specified IP address in network byte order. This must be a unique address within the Internet. If you do not directly communicate with other Internet hosts, you can use a locally assigned address. With PPP interfaces this may be set to 0.0.0.0, in which case the remote peer will be queried for an IP address.
ip_mask Specified IP network mask in network byte order. Typical Ethernet networks use 255.255.255.0, which allows upto 254 hosts. For PPP interfaces 255.255.255.255 is the default.
Returns:
0 on success, -1 otherwise.
Examples:
httpd/httpserv.c, inetq/inetq.c, portdio/portdio.c, and tcps/tcps.c.

int NutNetIfSetup NUTDEVICE   dev,
u_long    ip_addr,
u_long    ip_mask,
u_long    gateway
 

Network interface setup.

Parameters:
dev Identifies the network device to setup. This pointer must have been retrieved previously by calling NutDeviceOpen().
ip_addr Specified IP address in network byte order.
ip_mask Specified IP network mask in network byte order.
gateway Optional default gateway.
Returns:
0 on success, -1 otherwise.
Note:
Typical applications do not use this function, but call NutNetIfConfig() or NutNetAutoConfig().

int NutNetLoadConfig CONST char *    name
 

Load network configuration from EEPROM.

If no configuration is available in EEPROM, all configuration parameters are cleared to zero. Except the MAC address, which is set to the Ethernet broadcast address.

Parameters:
name Name of the device.
Returns:
0 if configuration has been read. Otherwise the return value is -1.
Examples:
tcps/tcps.c.

int NutNetSaveConfig void   
 

Save network configuration in EEPROM.

Returns:
Allways 0.
Examples:
tcps/tcps.c.


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