diff --git a/samples/openthread/coap_client/prj.conf b/samples/openthread/coap_client/prj.conf index 91af70c837e2..36184f7f7231 100644 --- a/samples/openthread/coap_client/prj.conf +++ b/samples/openthread/coap_client/prj.conf @@ -28,7 +28,6 @@ CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000 # Network sockets CONFIG_NET_SOCKETS=y -CONFIG_POSIX_API=y CONFIG_NET_SOCKETS_POLL_MAX=4 # Same network Master Key for client and server diff --git a/samples/openthread/coap_client/src/coap_client_utils.c b/samples/openthread/coap_client/src/coap_client_utils.c index 290939b41a41..79d4522edd84 100644 --- a/samples/openthread/coap_client/src/coap_client_utils.c +++ b/samples/openthread/coap_client/src/coap_client_utils.c @@ -125,7 +125,7 @@ static int on_provisioning_reply(const struct coap_packet *response, memcpy(&unique_local_addr.sin6_addr, payload, payload_size); - if (!inet_ntop(AF_INET6, payload, unique_local_addr_str, + if (!zsock_inet_ntop(AF_INET6, payload, unique_local_addr_str, INET6_ADDRSTRLEN)) { LOG_ERR("Received data is not IPv6 address: %d", errno); ret = -errno; diff --git a/samples/openthread/coap_server/prj.conf b/samples/openthread/coap_server/prj.conf index 04c0b360d4c4..448651968caf 100644 --- a/samples/openthread/coap_server/prj.conf +++ b/samples/openthread/coap_server/prj.conf @@ -21,7 +21,6 @@ CONFIG_PM_PARTITION_SIZE_SETTINGS_STORAGE=0x8000 # Network sockets CONFIG_NET_SOCKETS=y -CONFIG_POSIX_API=y CONFIG_NET_SOCKETS_POLL_MAX=4 # Same network Master Key for client and server diff --git a/subsys/net/lib/coap_utils/coap_utils.c b/subsys/net/lib/coap_utils/coap_utils.c index 5f574bdf8194..060eb2f5ea52 100644 --- a/subsys/net/lib/coap_utils/coap_utils.c +++ b/subsys/net/lib/coap_utils/coap_utils.c @@ -24,7 +24,7 @@ LOG_MODULE_REGISTER(coap_utils, CONFIG_COAP_UTILS_LOG_LEVEL); #endif const static int nfds = 1; -static struct pollfd fds; +static struct zsock_pollfd fds; static struct coap_reply replies[COAP_MAX_REPLIES]; static int proto_family; static struct sockaddr *bind_addr; @@ -37,7 +37,7 @@ static int coap_open_socket(void) int sock; while (1) { - sock = socket(proto_family, SOCK_DGRAM, IPPROTO_UDP); + sock = zsock_socket(proto_family, SOCK_DGRAM, IPPROTO_UDP); if (sock < 0) { LOG_ERR("Failed to create socket %d", errno); k_sleep(K_MSEC(COAP_OPEN_SOCKET_SLEEP)); @@ -47,7 +47,7 @@ static int coap_open_socket(void) } if (bind_addr) { - if (bind(sock, bind_addr, sizeof(*bind_addr))) { + if (zsock_bind(sock, bind_addr, sizeof(*bind_addr))) { LOG_ERR("Failed to bind socket, errno: %d", errno); } } @@ -57,7 +57,7 @@ static int coap_open_socket(void) static void coap_close_socket(int socket) { - (void)close(socket); + (void)zsock_close(socket); } static void coap_receive(void) @@ -73,25 +73,25 @@ static void coap_receive(void) while (1) { fds.revents = 0; - if (poll(&fds, nfds, -1) < 0) { + if (zsock_poll(&fds, nfds, -1) < 0) { LOG_ERR("Error in poll:%d", errno); errno = 0; k_sleep(K_MSEC(COAP_POOL_SLEEP)); continue; } - if (fds.revents & POLLERR) { + if (fds.revents & ZSOCK_POLLERR) { LOG_ERR("Error in poll.. waiting a moment."); k_sleep(K_MSEC(COAP_POOL_SLEEP)); continue; } - if (fds.revents & POLLHUP) { + if (fds.revents & ZSOCK_POLLHUP) { LOG_ERR("Error in poll: POLLHUP"); continue; } - if (fds.revents & POLLNVAL) { + if (fds.revents & ZSOCK_POLLNVAL) { LOG_ERR("Error in poll: POLLNVAL - fd not open"); coap_close_socket(fds.fd); @@ -102,13 +102,13 @@ static void coap_receive(void) continue; } - if (!(fds.revents & POLLIN)) { + if (!(fds.revents & ZSOCK_POLLIN)) { LOG_ERR("Unknown poll error"); continue; } from_addr_len = sizeof(from_addr); - len = recvfrom(fds.fd, buf, sizeof(buf) - 1, 0, &from_addr, + len = zsock_recvfrom(fds.fd, buf, sizeof(buf) - 1, 0, &from_addr, &from_addr_len); if (len < 0) { @@ -184,7 +184,7 @@ static int coap_init_request(enum coap_method method, static int coap_send_message(const struct sockaddr *addr, struct coap_packet *request) { - return sendto(fds.fd, request->data, request->offset, 0, addr, + return zsock_sendto(fds.fd, request->data, request->offset, 0, addr, sizeof(*addr)); } @@ -207,7 +207,7 @@ void coap_init(int ip_family, struct sockaddr *addr) bind_addr = addr; } - fds.events = POLLIN; + fds.events = ZSOCK_POLLIN; fds.revents = 0; fds.fd = coap_open_socket();