Detailed Description

TCP/IP support in Contiki is implemented using the uIP TCP/IP stack.

For sending and receiving data, Contiki uses the functions provided by the uIP module, but Contiki adds a set of functions for connection management. The connection management functions make sure that the uIP TCP/IP connections are connected to the correct process.

Contiki also includes an optional protosocket library that provides an API similar to the BSD socket API.

Define Documentation

#define udp_bind

(

conn,

port

)

uip_udp_bind(conn, port)

Bind a UDP connection to a local port.

This function binds a UDP connection to a specified local port.

When a connection is created with udp_new(), it gets a local port number assigned automatically. If the application needs to bind the connection to a specified local port, this function should be used.

Note:

The port number must be provided in network byte order so a conversion with UIP_HTONS() usually is necessary.

Parameters:

conn

A pointer to the UDP connection that is to be bound.

port

The port number in network byte order to which to bind the connection.

Function Documentation

This function attaches the current process to a TCP connection. Each TCP connection must be attached to a process in order for the process to be able to receive and send data. Additionally, this function can add a pointer with connection state to the connection.

Parameters:

conn

A pointer to the TCP connection.

appstate

An opaque pointer that will be passed to the process whenever an event occurs on the connection.

This function opens a TCP connection to the specified port at the host specified with an IP address. Additionally, an opaque pointer can be attached to the connection. This pointer will be sent together with uIP events to the process.

Note:

The port number must be provided in network byte order so a conversion with UIP_HTONS() usually is necessary.

This function will only create the connection. The connection is not opened directly. uIP will try to open the connection the next time the uIP stack is scheduled by Contiki.

Parameters:

ripaddr

Pointer to the IP address of the remote host.

port

Port number in network byte order.

appstate

Pointer to application defined data.

Returns:

A pointer to the newly created connection, or NULL if memory could not be allocated for the connection.

CCIF void tcp_listen

(

uint16_t

port

)

Open a TCP port.

This function opens a TCP port for listening. When a TCP connection request occurs for the port, the process will be sent a tcpip_event with the new connection request.

Note:

Port numbers must always be given in network byte order. The functions UIP_HTONS() and uip_htons() can be used to convert port numbers from host byte order to network byte order.

Port numbers must always be given in network byte order. The functions UIP_HTONS() and uip_htons() can be used to convert port numbers from host byte order to network byte order.

Parameters:

port

The port number in network byte order.

CCIF void tcpip_input

(

void

)

Deliver an incoming packet to the TCP/IP stack.

This function is called by network device drivers to deliver an incoming packet to the TCP/IP stack. The incoming packet must be present in the uip_buf buffer, and the length of the packet must be in the global uip_len variable.

This function causes uIP to poll the specified TCP connection. The function is used when the application has data that is to be sent immediately and do not wish to wait for the periodic uIP polling mechanism.

This function causes uIP to poll the specified UDP connection. The function is used when the application has data that is to be sent immediately and do not wish to wait for the periodic uIP polling mechanism.

This function attaches the current process to a UDP connection. Each UDP connection must have a process attached to it in order for the process to be able to receive and send data over the connection. Additionally, this function can add a pointer with connection state to the connection.

Parameters:

conn

A pointer to the UDP connection.

appstate

An opaque pointer that will be passed to the process whenever an event occurs on the connection.