Contiki 2.6

Simple-udp

The default Contiki UDP API is difficult to use. More...

Functions

int simple_udp_send (struct simple_udp_connection *c, const void *data, uint16_t datalen)
 Send a UDP packet.
int simple_udp_sendto (struct simple_udp_connection *c, const void *data, uint16_t datalen, const uip_ipaddr_t *to)
 Send a UDP packet to a specified IP address.
int simple_udp_register (struct simple_udp_connection *c, uint16_t local_port, uip_ipaddr_t *remote_addr, uint16_t remote_port, simple_udp_callback receive_callback)
 Register a UDP connection.

Detailed Description

The default Contiki UDP API is difficult to use.

The simple-udp module provides a significantly simpler API.


Function Documentation

int simple_udp_register ( struct simple_udp_connection *  c,
uint16_t  local_port,
uip_ipaddr_t remote_addr,
uint16_t  remote_port,
simple_udp_callback  receive_callback 
)

Register a UDP connection.

Parameters:
cA pointer to a struct simple_udp_connection
local_portThe local UDP port in host byte order
remote_addrThe remote IP address
remote_portThe remote UDP port in host byte order
receive_callbackA pointer to a function to be called for incoming packets
Return values:
0If no UDP connection could be allocated
1If the connection was successfully allocated

This function registers a UDP connection and attaches a callback function to it. The callback function will be called for incoming packets. The local UDP port can be set to 0 to indicate that an ephemeral UDP port should be allocated. The remote IP address can be NULL, to indicate that packets from any IP address should be accepted.

Definition at line 136 of file simple-udp.c.

References NULL, PROCESS_CONTEXT_BEGIN, PROCESS_CONTEXT_END, udp_bind, udp_new(), UIP_HTONS, and uip_ipaddr_copy.

int simple_udp_send ( struct simple_udp_connection *  c,
const void *  data,
uint16_t  datalen 
)

Send a UDP packet.

Parameters:
cA pointer to a struct simple_udp_connection
dataA pointer to the data to be sent
datalenThe length of the data

This function sends a UDP packet. The packet will be sent to the IP address and with the UDP ports that were specified when the connection wa registered with simple_udp_register().

See also:
simple_udp_sendto()

Definition at line 80 of file simple-udp.c.

References NULL, and UIP_HTONS.

int simple_udp_sendto ( struct simple_udp_connection *  c,
const void *  data,
uint16_t  datalen,
const uip_ipaddr_t to 
)

Send a UDP packet to a specified IP address.

Parameters:
cA pointer to a struct simple_udp_connection
dataA pointer to the data to be sent
datalenThe length of the data
toThe IP address of the receiver

This function sends a UDP packet to a specified IP address. The packet will be sent with the UDP ports that were specified when the connection wa registered with simple_udp_register().

See also:
simple_udp_send()

Definition at line 105 of file simple-udp.c.

References NULL, and UIP_HTONS.