22 #ifndef ETCPAL_SOCKET_H_ 
   23 #define ETCPAL_SOCKET_H_ 
   27 #include "etcpal/common.h" 
   28 #include "etcpal/error.h" 
   29 #include "etcpal/inet.h" 
   59 #include "etcpal/os_socket.h"  
   67 #define ETCPAL_MSG_PEEK 0x1 
   79 #define ETCPAL_SOL_SOCKET     0  
   80 #define ETCPAL_IPPROTO_IP     1  
   81 #define ETCPAL_IPPROTO_ICMPV6 2  
   82 #define ETCPAL_IPPROTO_IPV6   3  
   83 #define ETCPAL_IPPROTO_TCP    4  
   84 #define ETCPAL_IPPROTO_UDP    5  
   95 #define ETCPAL_SO_BROADCAST 0   
   96 #define ETCPAL_SO_ERROR     1   
   97 #define ETCPAL_SO_KEEPALIVE 2   
   98 #define ETCPAL_SO_LINGER    3   
   99 #define ETCPAL_SO_RCVBUF    4   
  100 #define ETCPAL_SO_SNDBUF    5   
  101 #define ETCPAL_SO_RCVTIMEO  6   
  102 #define ETCPAL_SO_SNDTIMEO  7   
  103 #define ETCPAL_SO_REUSEADDR 8   
  104 #define ETCPAL_SO_REUSEPORT 9   
  105 #define ETCPAL_SO_TYPE      10  
  118 #define ETCPAL_IP_TTL             11 
  120 #define ETCPAL_IP_MULTICAST_IF    12 
  122 #define ETCPAL_IP_MULTICAST_TTL   13 
  123 #define ETCPAL_IP_MULTICAST_LOOP  14  
  126 #define ETCPAL_IP_ADD_MEMBERSHIP  15 
  129 #define ETCPAL_IP_DROP_MEMBERSHIP 16 
  130 #define ETCPAL_MCAST_JOIN_GROUP   17  
  131 #define ETCPAL_MCAST_LEAVE_GROUP  18  
  132 #define ETCPAL_IPV6_V6ONLY        19  
  172 #define ETCPAL_SHUT_RD   0 
  173 #define ETCPAL_SHUT_WR   1 
  174 #define ETCPAL_SHUT_RDWR 2 
  183 #define ETCPAL_AF_UNSPEC 0u 
  184 #define ETCPAL_AF_INET   1u 
  185 #define ETCPAL_AF_INET6  2u 
  194 #define ETCPAL_SOCK_STREAM 0u 
  195 #define ETCPAL_SOCK_DGRAM  1u 
  227                                  const void*     option_value,
 
  244 #define ETCPAL_POLL_IN      0x1u   
  245 #define ETCPAL_POLL_OUT     0x2u   
  246 #define ETCPAL_POLL_CONNECT 0x4u   
  247 #define ETCPAL_POLL_OOB     0x8u   
  248 #define ETCPAL_POLL_ERR     0x10u  
  254 #define ETCPAL_POLL_VALID_INPUT_EVENT_MASK 0x0fu 
  274                                          void*                new_user_data);
 
  285 #define ETCPAL_AI_PASSIVE     0x01 
  286 #define ETCPAL_AI_CANONNAME   0x02 
  287 #define ETCPAL_AI_NUMERICHOST 0x04 
etcpal_error_t
A set of error codes that can be returned by library functions.
Definition: error.h:49
 
struct EtcPalGroupReq EtcPalGroupReq
Option value for ETCPAL_MCAST_JOIN_GROUP and ETCPAL_MCAST_LEAVE_GROUP.
 
void etcpal_poll_context_deinit(EtcPalPollContext *context)
Invalidate a previously-initialized EtcPalPollContext structure.
 
etcpal_error_t etcpal_setsockopt(etcpal_socket_t id, int level, int option_name, const void *option_value, size_t option_len)
Set an option value on a socket.
 
int etcpal_recvfrom(etcpal_socket_t id, void *buffer, size_t length, int flags, EtcPalSockAddr *address)
Receive data on a socket.
 
etcpal_error_t etcpal_getsockname(etcpal_socket_t id, EtcPalSockAddr *address)
Get socket name.
 
struct EtcPalLinger EtcPalLinger
Option value for ETCPAL_SO_LINGER.
 
etcpal_error_t etcpal_poll_modify_socket(EtcPalPollContext *context, etcpal_socket_t socket, etcpal_poll_events_t new_events, void *new_user_data)
Change the set of events or user data associated with a monitored socket.
 
etcpal_error_t etcpal_listen(etcpal_socket_t id, int backlog)
Listen for connections on a socket.
 
etcpal_error_t etcpal_shutdown(etcpal_socket_t id, int how)
Shut down part of a full-duplex connection.
 
int etcpal_send(etcpal_socket_t id, const void *message, size_t length, int flags)
Send data on a connected socket.
 
etcpal_error_t etcpal_getaddrinfo(const char *hostname, const char *service, const EtcPalAddrinfo *hints, EtcPalAddrinfo *result)
Get address information for a named internet host and/or service.
 
uint32_t etcpal_poll_events_t
Event flags for the etcpal_poll_*() API functions.
Definition: socket.h:57
 
etcpal_error_t etcpal_getsockopt(etcpal_socket_t id, int level, int option_name, void *option_value, size_t *option_len)
Get an option value for a socket.
 
bool etcpal_nextaddr(EtcPalAddrinfo *ai)
Get the next address from the list returned by etcpal_getaddrinfo().
 
etcpal_error_t etcpal_getblocking(etcpal_socket_t id, bool *blocking)
Get the current blocking behavior of a socket.
 
etcpal_error_t etcpal_setblocking(etcpal_socket_t id, bool blocking)
Change the blocking behavior of a socket.
 
void etcpal_poll_remove_socket(EtcPalPollContext *context, etcpal_socket_t socket)
Remove a monitored socket from an EtcPalPollContext.
 
etcpal_error_t etcpal_bind(etcpal_socket_t id, const EtcPalSockAddr *address)
Bind a name to a socket.
 
etcpal_error_t etcpal_accept(etcpal_socket_t id, EtcPalSockAddr *address, etcpal_socket_t *conn_sock)
Accept a connection on a socket.
 
void etcpal_freeaddrinfo(EtcPalAddrinfo *ai)
Free an addrinfo list returned by etcpal_getaddrinfo().
 
PLATFORM_DEFINED EtcPalPollContext
A structure that holds context information for poll operations on multiple sockets.
Definition: socket.dox:285
 
etcpal_error_t etcpal_poll_add_socket(EtcPalPollContext *context, etcpal_socket_t socket, etcpal_poll_events_t events, void *user_data)
Add a new socket to an EtcPalPollContext.
 
etcpal_error_t etcpal_connect(etcpal_socket_t id, const EtcPalSockAddr *address)
Initiate a connection on a socket.
 
struct EtcPalPollEvent EtcPalPollEvent
A description of an event that occurred on a socket, for usage with etcpal_poll_wait().
 
etcpal_error_t etcpal_close(etcpal_socket_t id)
Close a socket.
 
int etcpal_recv(etcpal_socket_t id, void *buffer, size_t length, int flags)
Receive data on a connected socket.
 
etcpal_error_t etcpal_socket(unsigned int family, unsigned int type, etcpal_socket_t *id)
Create a socket.
 
etcpal_error_t etcpal_poll_wait(EtcPalPollContext *context, EtcPalPollEvent *event, int timeout_ms)
Wait for an event on a set of sockets defined by an EtcPalPollContext.
 
etcpal_error_t etcpal_getpeername(etcpal_socket_t id, EtcPalSockAddr *address)
Get the name of the connected peer socket.
 
struct EtcPalAddrinfo EtcPalAddrinfo
A structure containing name and address information about an internet host.
 
PLATFORM_DEFINED etcpal_socket_t
A socket handle.
Definition: socket.dox:11
 
int etcpal_sendto(etcpal_socket_t id, const void *message, size_t length, int flags, const EtcPalSockAddr *dest_addr)
Send data on a socket.
 
etcpal_error_t etcpal_poll_context_init(EtcPalPollContext *context)
Create a new context for waiting on events on multiple sockets.
 
struct EtcPalMreq EtcPalMreq
Option value for ETCPAL_IP_ADD_MEMBERSHIP and ETCPAL_IP_DROP_MEMBERSHIP.
 
A structure containing name and address information about an internet host.
Definition: socket.h:295
 
EtcPalSockAddr ai_addr
Address of host.
Definition: socket.h:301
 
int ai_socktype
i.e.
Definition: socket.h:298
 
int ai_family
i.e.
Definition: socket.h:297
 
int ai_protocol
i.e.
Definition: socket.h:299
 
int ai_flags
i.e.
Definition: socket.h:296
 
char * ai_canonname
Canonical name for host.
Definition: socket.h:300
 
void * pd[2]
Used by internal platform logic; don't touch.
Definition: socket.h:302
 
Option value for ETCPAL_MCAST_JOIN_GROUP and ETCPAL_MCAST_LEAVE_GROUP.
Definition: socket.h:160
 
unsigned int ifindex
Index of network interface on which to join the multicast group (see Network Interface Indexes).
Definition: socket.h:163
 
EtcPalIpAddr group
Multicast group to join.
Definition: socket.h:165
 
An IP address.
Definition: inet.h:75
 
Option value for ETCPAL_SO_LINGER.
Definition: socket.h:144
 
int linger
Linger time in seconds.
Definition: socket.h:146
 
int onoff
0 = off, nonzero = on
Definition: socket.h:145
 
Option value for ETCPAL_IP_ADD_MEMBERSHIP and ETCPAL_IP_DROP_MEMBERSHIP.
Definition: socket.h:151
 
EtcPalIpAddr group
Multicast group to join.
Definition: socket.h:155
 
EtcPalIpAddr netint
Address of network interface on which to join the multicast group.
Definition: socket.h:153
 
A description of an event that occurred on a socket, for usage with etcpal_poll_wait().
Definition: socket.h:258
 
void * user_data
The user data that was given when this socket was added.
Definition: socket.h:262
 
etcpal_error_t err
More information about an error that occurred on the socket.
Definition: socket.h:261
 
etcpal_poll_events_t events
Event(s) that occurred on the socket.
Definition: socket.h:260
 
etcpal_socket_t socket
Socket which had activity.
Definition: socket.h:259
 
An IP address with associated interface and port.
Definition: inet.h:311