mn_net_types.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2018 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 #ifndef _MINLIB_BASIC_NET_TYPES_HPP_
19 #define _MINLIB_BASIC_NET_TYPES_HPP_
20 
21 #include "lwip/err.h"
22 #include "lwip/sockets.h"
23 
24 #ifndef UDPLITE_SEND_CSCOV
25 #define UDPLITE_SEND_CSCOV 0x01
26 #endif // UDPLITE_SEND_CSCOV
27 
28 #ifndef UDPLITE_RECV_CSCOV
29 #define UDPLITE_RECV_CSCOV 0x02
30 #endif // UDPLITE_RECV_CSCOV
31 
32 #define SERVICE_PROVIDES_TOS(tos) (mn::net::service_provides) ((tos) & mn::net::service_provides::tos_mask)
33 
34 namespace mn {
35  namespace net {
36 
41  enum class address_family {
45  Unspecified = AF_UNSPEC,
49  inet_v4 = AF_INET,
53  inet_v6 = AF_INET6,
54  };
55 
60  enum class protocol_type : int {
64  unspec = IPPROTO_IP,
68  icmp = IPPROTO_ICMP,
72  tcp = IPPROTO_TCP,
76  udp = IPPROTO_UDP,
77  #if LWIP_IPV6 == 1
81  icmpv6 = IPPROTO_ICMPV6,
82  #endif // LWIP_IPV6
83 
88  udp_lite = IPPROTO_UDPLITE,
92  raw = IPPROTO_RAW
93  };
94 
99  enum class socket_type : int {
103  stream = SOCK_STREAM,
107  dgram = SOCK_DGRAM,
112  raw = SOCK_RAW,
113  };
118  enum class socket_flags : int {
122  none = 0x00,
126  out_of_band = MSG_OOB,
131  peek = MSG_PEEK,
138  wait_all = MSG_WAITALL,
142  non_blocking = MSG_DONTWAIT,
146  more = MSG_MORE,
151  no_signal = MSG_NOSIGNAL,
152  };
157  enum class socket_shutdown_type : uint8_t {
161  read = SHUT_RD,
165  write = SHUT_WR,
169  rw = SHUT_RDWR
170  };
175  enum class socket_option_level : int {
179  socket = SOL_SOCKET,
183  ip = IPPROTO_IP,
184  #if LWIP_IPV6 == 1
188  ipv6 = (int)IPPROTO_IPV6,
189  #endif // LWIP_IPV6
190 
194  tcp = (int)protocol_type::tcp,
198  udp = (int)protocol_type::udp,
203 
204  };
209  enum class socket_option_name : int {
213  debug = SO_DEBUG,
217  acceptconn = SO_ACCEPTCONN,
222  dont_route = SO_DONTROUTE,
226  use_loopback = SO_USELOOPBACK,
230  linger = SO_LINGER,
235  nolinger = SO_DONTLINGER,
240  oob_inline = SO_OOBINLINE,
244  reuse_port = SO_REUSEPORT,
248  reuse_addr = SO_REUSEADDR,
252  sendbuffer = SO_SNDBUF,
256  recivebuffer = SO_RCVBUF,
257 
258  #if LWIP_UDP == 1 && LWIP_UDPLITE == 1
262  udplite_send_cscov = UDPLITE_SEND_CSCOV,
266  udplite_recv_cscov = UDPLITE_RECV_CSCOV,
267  #endif // LWIP_UDP
268 
272  send_lowat = SO_SNDLOWAT,
276  recive_lowat = SO_RCVLOWAT,
280  send_timeout = SO_SNDTIMEO,
284  recive_timeout = SO_RCVTIMEO,
288  error = SO_ERROR,
292  get_type = SO_TYPE,
296  commected_timeout = SO_CONTIMEO,
300  no_check = SO_NO_CHECK,
304  bind_device = SO_BINDTODEVICE,
308  broadcast = SO_BROADCAST,
312  keepalive = SO_KEEPALIVE,
313 
314 
315  /*
316  * @brief Type of Service (TOS) settings should only be set using the Quality of Service API.
317  */
318  tos = IP_TOS,
319  /*
320  * @brief Changes the default value set by the TCP/IP service provider in the TTL field of the IP
321  * header in outgoing datagrams
322  */
323  ttl = IP_TTL,
324 
325 
326  #if LWIP_TCP == 1
331  tcp_nodelay = TCP_NODELAY,
336  tcp_keepalive = TCP_KEEPALIVE,
342  tcp_keepidle = TCP_KEEPIDLE,
348  tcp_keepintvl = TCP_KEEPINTVL,
354  tcp_keepcnt = TCP_KEEPCNT,
355  #endif
356 
357  #ifdef LWIP_MULTICAST_TX_OPTIONS
361  multicast_ttl = IP_MULTICAST_TTL,
365  multicast_if = IP_MULTICAST_IF,
371  multicast_loop = IP_MULTICAST_LOOP,
372  #endif
373 
374  #if ESP_LWIP == 1 && LWIP_IPV6_MLD == 1
378  multicast_ip6_if = IPV6_MULTICAST_IF,
382  multicast_ip6_hops = IPV6_MULTICAST_HOPS,
387  multicast_ip6_loop = IPV6_MULTICAST_LOOP,
391  multicast_ip6_add_membership = IPV6_ADD_MEMBERSHIP,
396  multicast_ip6_drop_membership = IPV6_DROP_MEMBERSHIP,
397  #endif
398 
399  #if LWIP_IGMP == 1
403  igmp_add_membership = IP_ADD_MEMBERSHIP,
408  igmp_drop_membership = IP_DROP_MEMBERSHIP,
409  #endif // LWIP_IGMP
410  };
411 
416  tos_mask = IPTOS_TOS_MASK,
417  low_delay = IPTOS_LOWDELAY,
418  through_put = IPTOS_THROUGHPUT,
419  reliability = IPTOS_RELIABILITY,
420  low_cost = IPTOS_LOWCOST,
421  min_cost = IPTOS_MINCOST,
422  };
429  enum class ioctl_request_type {
430  available = FIONREAD,
431  non_blocking = FIONBIO,
432  };
433 
434 
435  }
436 }
437 
438 #endif
439 
#define UDPLITE_SEND_CSCOV
Definition: mn_net_types.hpp:25
#define UDPLITE_RECV_CSCOV
Definition: mn_net_types.hpp:29
socket_shutdown_type
Commands for lwip_shutdown.
Definition: mn_net_types.hpp:157
@ rw
receptions and transmissions will be disallowed
@ read
receptions will be disallowed
@ write
transmissions will be disallowed
protocol_type
Defines socket protoco types for creating.
Definition: mn_net_types.hpp:60
@ udp
The User Datagram Protocol (UDP)
@ raw
Raw sockets allow new IPv4 protocols to be implemented in user space.
@ udp_lite
This is an implementation of the Lightweight User Datagram Protocol (UDP-Lite), as described in RFC 3...
@ tcp
The Transmission Control Protocol (TCP).
socket_type
Defines socket socket types for creating.
Definition: mn_net_types.hpp:99
@ raw
A socket type that provides a raw socket that allows an application to manipulate the next upper-laye...
@ stream
Socket type for stream (tcp)
@ dgram
Socket type for datagram (udp for example)
address_family
Defines socket address types for creating.
Definition: mn_net_types.hpp:41
@ Unspecified
The address family is unspecified.
@ inet_v4
The Internet Protocol version 4 (IPv4) address family.
@ inet_v6
The Internet Protocol version 6 (IPv6) address family.
socket_option_name
Items for socket option name for the mn_socket::set_options and mn_socket::get_options.
Definition: mn_net_types.hpp:209
@ recive_timeout
Sets the timeout, in milliseconds, for blocking receive calls.
@ sendbuffer
Specifies the total per-socket buffer space reserved for sends.
@ commected_timeout
Unimplemented: connect timeout.
@ send_lowat
This option sets the minimum number of bytes to process for socket output operations.
@ reuse_addr
Allows the socket to be bound to an address that is already in use.
@ recive_lowat
This option sets the minimum number of bytes to process for socket input operations.
@ oob_inline
Indicates that out-of-bound data should be returned in-line with regular data. This option is only va...
@ keepalive
Enables sending keep-alive packets for a socket connection.
@ get_type
Returns the socket type for the given socket (socket_type::stream or socket_type::dgram)
@ use_loopback
Use the local loopback address when sending data from this socket.
@ acceptconn
Returns whether a socket is in listening mode.
@ send_timeout
Sets the timeout, in milliseconds, for blocking send calls.
@ recivebuffer
Specifies the total per-socket buffer space reserved for receives.
@ debug
Enables debug output.
@ dont_route
Sets whether outgoing data should be sent on interface the socket is bound to and not a routed on som...
@ broadcast
Configures a socket for sending broadcast data.
@ nolinger
Does not block close waiting for unsent data to be sent. Setting this option is equivalent to setting...
@ reuse_port
Allows the socket to be bound to an port that is already in use.
@ no_check
don't create UDP checksum
@ linger
Lingers on close if unsent data is present.
socket_option_level
Items for socket option levels for the mn_socket::set_options and mn_socket::get_options.
Definition: mn_net_types.hpp:175
@ socket
options for socket level
@ udp
options for UDP level
@ ip
options for IPv4 level
@ udp_lite
options for UDPLite level
@ tcp
options for TCP level
ioctl_request_type
Commands for ioctlsocket(), taken from the BSD file fcntl.h. lwip_ioctl only supports FIONREAD and FI...
Definition: mn_net_types.hpp:429
socket_flags
Specifies socket send and receive behaviors.
Definition: mn_net_types.hpp:118
@ no_signal
Requests not to send any data on errors on stream oriented sockets when the other end breaks the conn...
@ none
Use no flags for this call.
@ peek
Peeks at the incoming data. The data is copied into the buffer, but is not removed from the input que...
@ non_blocking
Nonblocking i/o for this operation only.
@ more
Sender will send more.
@ out_of_band
Processes Out Of Band (OOB) data.
service_provides
Definition: mn_net_types.hpp:415
@ tos_mask
Definition: mn_net_types.hpp:416
@ min_cost
Definition: mn_net_types.hpp:421
@ low_cost
Definition: mn_net_types.hpp:420
@ reliability
Definition: mn_net_types.hpp:419
@ through_put
Definition: mn_net_types.hpp:418
@ low_delay
Definition: mn_net_types.hpp:417
Definition: mn_allocator_typetraits.hpp:25