19#if defined(WITH_CONTIKI)
21#include "contiki-net.h"
23extern struct process libcoap_io_process;
31 addr = uip_ds6_get_global(ADDR_PREFERRED);
33 coap_log_err(
"coap_socket_bind_udp: called before getting an IPv6 address\n");
36 PROCESS_CONTEXT_BEGIN(&libcoap_io_process);
37 sock->udp_conn = udp_new(NULL, 0, sock);
38 PROCESS_CONTEXT_END(&libcoap_io_process);
39 if (!sock->udp_conn) {
40 coap_log_err(
"coap_socket_bind_udp: udp_new returned NULL\n");
43 udp_bind(sock->udp_conn, listen_addr->port);
44 uip_ipaddr_copy(&bound_addr->
addr, &addr->ipaddr);
45 bound_addr->port = sock->udp_conn->lport;
59 coap_log_warn(
"coap_socket_connect_udp: ignoring local_if parameter\n");
61 addr = uip_ds6_get_global(ADDR_PREFERRED);
63 coap_log_err(
"coap_socket_connect_udp: called before getting an IPv6 address\n");
66 PROCESS_CONTEXT_BEGIN(&libcoap_io_process);
67 sock->udp_conn = udp_new(&server->
addr, server->port ? server->port : default_port, sock);
68 PROCESS_CONTEXT_END(&libcoap_io_process);
69 if (!sock->udp_conn) {
70 coap_log_err(
"coap_socket_connect_udp: udp_new returned NULL\n");
73 uip_ipaddr_copy(&local_addr->
addr, &addr->ipaddr);
74 local_addr->port = sock->udp_conn->lport;
75 uip_ipaddr_copy(&remote_addr->
addr, &server->
addr);
76 remote_addr->port = sock->udp_conn->rport;
93 uip_udp_remove(sock->udp_conn);
94 sock->udp_conn = NULL;
106 ssize_t bytes_written = 0;
109 bytes_written = (ssize_t)datalen;
111 uip_udp_packet_sendto(sock->udp_conn, data, datalen,
113 bytes_written = datalen;
116 if (bytes_written < 0) {
120 return bytes_written;
140 sock->
flags &= ~COAP_SOCKET_CAN_READ;
150 coap_log_warn(
"Received message does not fit within buffer\n");
165#pragma GCC diagnostic ignored "-Wunused-function"
int coap_debug_send_packet(void)
Check to see whether a packet should be sent or not.
const char * coap_socket_strerror(void)
#define COAP_RXBUFFER_SIZE
#define COAP_SOCKET_CAN_READ
non blocking socket can now read without blocking
#define COAP_SOCKET_CONNECTED
the socket is connected
#define COAP_SOCKET_EMPTY
coap_socket_flags_t values
Library specific build wrapper for coap_internal.h.
int coap_socket_connect_udp(coap_socket_t *sock, const coap_address_t *local_if, const coap_address_t *server, int default_port, coap_address_t *local_addr, coap_address_t *remote_addr)
Create a new UDP socket and 'connect' it to the address tuple.
ssize_t coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet)
Function interface for reading data.
ssize_t coap_socket_send(coap_socket_t *sock, coap_session_t *session, const uint8_t *data, size_t datalen)
Function interface for data transmission.
int coap_socket_bind_udp(coap_socket_t *sock, const coap_address_t *listen_addr, coap_address_t *bound_addr)
Create a new UDP socket and then listen for new incoming UDP sessions to the specified IP address and...
void coap_socket_dgrm_close(coap_socket_t *sock)
Function interface to close off a datagram socket.
#define coap_log_warn(...)
#define coap_log_err(...)
#define coap_log_crit(...)
ssize_t coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len)
Function interface for data stream receiving off a socket.
ssize_t coap_socket_write(coap_socket_t *sock, const uint8_t *data, size_t data_len)
Function interface for data stream sending off a socket.
coap_address_t remote
remote address and port
coap_address_t local
local address and port
Multi-purpose address abstraction.
union coap_address_t::@0 addr
size_t length
length of payload
coap_addr_tuple_t addr_info
local and remote addresses
unsigned char * payload
payload
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
coap_addr_tuple_t addr_info
remote/local address info
coap_socket_flags_t flags
1 or more of COAP_SOCKET* flag values