Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# Network Stack (netstack.c)
[Network Library]

## Detailed Description

     #include "net/netstack.h"

Description
  This library co-ordinates the various pieces of a typical IP network stack into one unit. Included are handling for ARP, ICMP, and IP packets. UDP and TCP packets are processed and passed to the user.

This is an example of how to use the various network libraries, and is meant to be useful out-of-the-box for most users. However, some users may find it restrictive and write their own handlers instead. This stack implementation is by no means the only way to use the various network libraries.

Note:
  This is NOT a full-blown TCP/IP stack. It merely handles lower level stack functions so that UDP and TCP packets can be sent and received easily. End-to-end TCP functionality may be added in a future version. Until then, I can recommend using other embedded TCP/IP stacks like Adam Dunkel's uIP.

## Defines
#define | NETSTACK_BUFFERSIZE (576+ETH_HEADER_LEN)
## Functions
void | netstackInit (uint32_t ipaddress, uint32_t netmask, uint32_t gatewayip)
u08 * | netstackGetBuffer (void)
| netstackGetBuffer returns a pointer to the common receive/process/transmit buffer.
int | netstackService (void)
void | netstackIPProcess (unsigned int len, ip_hdr *packet)
void | netstackUDPIPProcess (unsigned int len, udpip_hdr *packet) __attribute__((weak))
void | netstackTCPIPProcess (unsigned int len, tcpip_hdr *packet) __attribute__((weak))

## Define Documentation

#define NETSTACK_BUFFERSIZE (576+ETH_HEADER_LEN)

| NET_BUFFERSIZE is the common receive/process/transmit buffer. You may override the default NET_BUFFERSIZE by defining an alternate value in global.h. Network packets larger than NET_BUFFERSIZE will not be accepted. Definition at line 53 of file netstack.h.

## Function Documentation

void netstackInit | ( | uint32_t | ipaddress,
|  | uint32_t | netmask,
|  | uint32_t | gatewayip
| ) |

| netstackInit prepares the network interface for use and should be called once at the beginning of the user program. Note: Use ipSetAddress() to change network parameters in mid-run. Definition at line 24 of file netstack.c.

void netstackIPProcess | ( | unsigned int | len,
|  | ip_hdr * | packet
| ) |

| netstackIPProcess handles distribution of IP received packets. Definition at line 93 of file netstack.c.

int netstackService | ( | void |  | ) |

| netstackService should be called in the main loop of the user program. The function will process one received network packet per call. The return value is the length of the packet processed, or zero if no packet was processed. Definition at line 48 of file netstack.c.

void netstackTCPIPProcess | ( | unsigned int | len,
|  | tcpip_hdr * | packet
| ) |

| This weakly-defined function is the default handler for incoming TCP/IP packets. Users should define this same function in user code (same name and arguments) to override this default handler and get access to the received packets. Definition at line 141 of file netstack.c.

void netstackUDPIPProcess | ( | unsigned int | len,
|  | udpip_hdr * | packet
| ) |

| This weakly-defined function is the default handler for incoming UDP/IP packets. Users should define this same function in user code (same name and arguments) to override this default handler and get access to the received packets. Definition at line 133 of file netstack.c.