32 #include "contiki-net.h"
33 #include "udp-socket.h"
37 PROCESS(udp_socket_process,
"UDP socket process");
41 #define UIP_IP_BUF ((struct uip_udpip_hdr *)&uip_buf[UIP_LLH_LEN])
48 static uint8_t inited = 0;
56 udp_socket_register(
struct udp_socket *c,
58 udp_socket_input_callback_t input_callback)
66 c->input_callback = input_callback;
73 if(c->udp_conn ==
NULL) {
80 udp_socket_close(
struct udp_socket *c)
85 if(c->udp_conn !=
NULL) {
93 udp_socket_bind(
struct udp_socket *c,
96 if(c ==
NULL || c->udp_conn ==
NULL) {
105 udp_socket_connect(
struct udp_socket *c,
106 uip_ipaddr_t *remote_addr,
107 uint16_t remote_port)
109 if(c ==
NULL || c->udp_conn ==
NULL) {
113 if(remote_addr !=
NULL) {
116 c->udp_conn->rport =
UIP_HTONS(remote_port);
121 udp_socket_send(
struct udp_socket *c,
122 const void *data, uint16_t datalen)
124 if(c ==
NULL || c->udp_conn ==
NULL) {
128 uip_udp_packet_send(c->udp_conn, data, datalen);
133 udp_socket_sendto(
struct udp_socket *c,
134 const void *data, uint16_t datalen,
135 const uip_ipaddr_t *to,
138 if(c ==
NULL || c->udp_conn ==
NULL) {
142 if(c->udp_conn !=
NULL) {
143 uip_udp_packet_sendto(c->udp_conn, data, datalen,
152 struct udp_socket *c;
164 c = (
struct udp_socket *)data;
181 if(c->input_callback !=
NULL) {
183 c->input_callback(c, c->ptr,
#define PROCESS_CURRENT()
Get a pointer to the currently running process.
#define PROCESS_BEGIN()
Define the beginning of a process.
CCIF struct uip_udp_conn * udp_new(const uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
Create a new UDP connection.
#define uip_newdata()
Is new incoming data available?
#define uip_udp_remove(conn)
Remove a UDP connection.
#define NULL
The null pointer.
#define UIP_BUFSIZE
The size of the uIP packet buffer.
#define UIP_HTONS(n)
Convert 16-bit quantity from host byte order to network byte order.
#define UIP_IP_BUF
Pointer to IP header.
#define PROCESS_THREAD(name, ev, data)
Define the body of a process.
#define PROCESS_END()
Define the end of a process.
#define uip_ipaddr_copy(dest, src)
Copy an IP address from one place to another.
#define PROCESS_WAIT_EVENT()
Wait for an event to be posted to the process.
#define PROCESS(name, strname)
Declare a process.
#define uip_datalen()
The length of any incoming data that is currently available (if available) in the uip_appdata buffer...
process_event_t tcpip_event
The uIP event.
void process_start(struct process *p, process_data_t data)
Start a process.
#define udp_bind(conn, port)
Bind a UDP connection to a local port.
#define PROCESS_CONTEXT_BEGIN(p)
Switch context to another process.
uip_appdata
Pointer to the application data in the packet buffer.
#define PROCESS_CONTEXT_END(p)
End a context switch.