2017-08-01 21:08:58 +08:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief BSD Sockets compatible API definitions
|
|
|
|
*
|
|
|
|
* An API for applications to use BSD Sockets like API.
|
|
|
|
*/
|
|
|
|
|
2017-05-11 18:47:27 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Linaro Limited
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __NET_SOCKET_H
|
|
|
|
#define __NET_SOCKET_H
|
|
|
|
|
2017-08-01 21:08:58 +08:00
|
|
|
/**
|
|
|
|
* @brief BSD Sockets compatible API
|
|
|
|
* @defgroup bsd_sockets BSD Sockets compatible API
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2017-06-11 02:53:03 +08:00
|
|
|
#include <sys/types.h>
|
2017-05-12 21:52:34 +08:00
|
|
|
#include <zephyr/types.h>
|
|
|
|
#include <net/net_ip.h>
|
|
|
|
|
2017-05-11 18:47:27 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-07-18 16:57:51 +08:00
|
|
|
struct zsock_pollfd {
|
|
|
|
int fd;
|
|
|
|
short events;
|
|
|
|
short revents;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Values are compatible with Linux */
|
|
|
|
#define ZSOCK_POLLIN 1
|
|
|
|
#define ZSOCK_POLLOUT 4
|
|
|
|
|
2017-05-11 18:47:27 +08:00
|
|
|
int zsock_socket(int family, int type, int proto);
|
|
|
|
int zsock_close(int sock);
|
2017-06-08 22:14:08 +08:00
|
|
|
int zsock_bind(int sock, const struct sockaddr *addr, socklen_t addrlen);
|
|
|
|
int zsock_connect(int sock, const struct sockaddr *addr, socklen_t addrlen);
|
|
|
|
int zsock_listen(int sock, int backlog);
|
|
|
|
int zsock_accept(int sock, struct sockaddr *addr, socklen_t *addrlen);
|
2017-06-11 02:53:03 +08:00
|
|
|
ssize_t zsock_send(int sock, const void *buf, size_t len, int flags);
|
2017-06-13 03:18:16 +08:00
|
|
|
ssize_t zsock_recv(int sock, void *buf, size_t max_len, int flags);
|
2017-07-11 06:22:40 +08:00
|
|
|
int zsock_fcntl(int sock, int cmd, int flags);
|
2017-07-18 16:57:51 +08:00
|
|
|
int zsock_poll(struct zsock_pollfd *fds, int nfds, int timeout);
|
2017-05-11 18:47:27 +08:00
|
|
|
|
2017-05-12 21:52:34 +08:00
|
|
|
#if defined(CONFIG_NET_SOCKETS_POSIX_NAMES)
|
|
|
|
#define socket zsock_socket
|
|
|
|
#define close zsock_close
|
2017-06-08 22:14:08 +08:00
|
|
|
#define bind zsock_bind
|
|
|
|
#define connect zsock_connect
|
|
|
|
#define listen zsock_listen
|
|
|
|
#define accept zsock_accept
|
2017-06-11 02:53:03 +08:00
|
|
|
#define send zsock_send
|
2017-06-13 03:18:16 +08:00
|
|
|
#define recv zsock_recv
|
2017-07-11 06:22:40 +08:00
|
|
|
#define fcntl zsock_fcntl
|
2017-06-10 00:56:26 +08:00
|
|
|
|
2017-07-18 16:57:51 +08:00
|
|
|
#define poll zsock_poll
|
|
|
|
#define pollfd zsock_pollfd
|
|
|
|
#define POLLIN ZSOCK_POLLIN
|
|
|
|
#define POLLOUT ZSOCK_POLLOUT
|
|
|
|
|
2017-06-10 00:56:26 +08:00
|
|
|
#define inet_ntop net_addr_ntop
|
|
|
|
#define inet_pton net_addr_pton
|
2017-05-12 21:52:34 +08:00
|
|
|
#endif
|
|
|
|
|
2017-05-11 18:47:27 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-08-01 21:08:58 +08:00
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2017-05-11 18:47:27 +08:00
|
|
|
#endif /* __NET_SOCKET_H */
|