1 /** 2 * @file 3 * netconn API (to be used from non-TCPIP threads) 4 */ 5 6 /* 7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 8 * All rights reserved. 9 * 10 * Redistribution and use in source and binary forms, with or without modification, 11 * are permitted provided that the following conditions are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright notice, 14 * this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright notice, 16 * this list of conditions and the following disclaimer in the documentation 17 * and/or other materials provided with the distribution. 18 * 3. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 30 * OF SUCH DAMAGE. 31 * 32 * This file is part of the lwIP TCP/IP stack. 33 * 34 * Author: Adam Dunkels <adam@sics.se> 35 * 36 */ 37 #ifndef LWIP_HDR_API_H 38 #define LWIP_HDR_API_H 39 40 #include "lwip/opt.h" 41 42 #if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ 43 /* Note: Netconn API is always available when sockets are enabled - 44 * sockets are implemented on top of them */ 45 46 #include "lwip/arch.h" 47 #include "lwip/netbuf.h" 48 #include "lwip/sys.h" 49 #include "lwip/ip_addr.h" 50 #include "lwip/err.h" 51 #include "lwip/filter.h" 52 53 #if defined (__cplusplus) && __cplusplus 54 extern "C" { 55 #endif 56 57 /* Throughout this file, IP_add and port numbers are expected to be in 58 * the same byte order as in the corresponding pcb. 59 */ 60 /* Flags for netconn_write (u8_t) */ 61 #define NETCONN_NOFLAG 0x00 62 #define NETCONN_NOCOPY 0x00 /* Only for source code compatibility */ 63 #define NETCONN_COPY 0x01 64 #define NETCONN_MORE 0x02 65 #define NETCONN_DONTBLOCK 0x04 66 67 /* Flags for struct netconn.flags (u8_t) */ 68 /* 69 * TCP: when data passed to netconn_write doesn't fit into the send buffer, 70 * this temporarily stores whether to wake up the original application task 71 * if data couldn't be sent in the first try. 72 */ 73 #define NETCONN_FLAG_WRITE_DELAYED 0x01 74 /* Should this netconn avoid blocking? */ 75 #define NETCONN_FLAG_NON_BLOCKING 0x02 76 /* Was the last connect action a non-blocking one? */ 77 #define NETCONN_FLAG_IN_NONBLOCKING_CONNECT 0x04 78 /* If this is set, a TCP netconn must call netconn_recved() to update 79 the TCP receive window (done automatically if not set). */ 80 #define NETCONN_FLAG_NO_AUTO_RECVED 0x08 81 /* If a nonblocking write has been rejected before, poll_tcp needs to 82 check if the netconn is writable again */ 83 #define NETCONN_FLAG_CHECK_WRITESPACE 0x10 84 #if LWIP_IPV6 85 /* If this flag is set then only IPv6 communication is allowed on the 86 netconn. As per RFC#3493 this features defaults to OFF allowing 87 dual-stack usage by default. */ 88 #define NETCONN_FLAG_IPV6_V6ONLY 0x20 89 #endif /* LWIP_IPV6 */ 90 91 #if LWIP_NETBUF_RECVINFO 92 /** Received packet info will be recorded for this netconn */ 93 #define NETCONN_FLAG_PKTINFO 0x40 94 #endif /* LWIP_NETBUF_RECVINFO */ 95 96 /* Helpers to process several netconn_types by the same code */ 97 #define NETCONNTYPE_GROUP(t) ((t)&0xF0) 98 #define NETCONNTYPE_DATAGRAM(t) ((t)&0xE0) 99 #if LWIP_IPV6 100 #define NETCONN_TYPE_IPV6 0x08 101 #define NETCONNTYPE_ISIPV6(t) (((t)&NETCONN_TYPE_IPV6) != 0) 102 #define NETCONNTYPE_ISUDPLITE(t) (((t)&0xF3) == NETCONN_UDPLITE) 103 #define NETCONNTYPE_ISUDPNOCHKSUM(t) (((t)&0xF3) == NETCONN_UDPNOCHKSUM) 104 #else /* LWIP_IPV6 */ 105 #define NETCONNTYPE_ISIPV6(t) (0) 106 #define NETCONNTYPE_ISUDPLITE(t) ((t) == NETCONN_UDPLITE) 107 #define NETCONNTYPE_ISUDPNOCHKSUM(t) ((t) == NETCONN_UDPNOCHKSUM) 108 #endif /* LWIP_IPV6 */ 109 110 /* @ingroup netconn_common 111 * Protocol family and type of the netconn 112 */ 113 enum netconn_type { 114 NETCONN_INVALID = 0, 115 /* TCP IPv4 */ 116 NETCONN_TCP = 0x10, 117 #if LWIP_IPV6 118 /* TCP IPv6 */ 119 NETCONN_TCP_IPV6 = NETCONN_TCP | NETCONN_TYPE_IPV6 /* 0x18 */, 120 #endif /* LWIP_IPV6 */ 121 /* UDP IPv4 */ 122 NETCONN_UDP = 0x20, 123 /* UDP IPv4 lite */ 124 NETCONN_UDPLITE = 0x21, 125 /* UDP IPv4 no checksum */ 126 NETCONN_UDPNOCHKSUM = 0x22, 127 128 #if LWIP_IPV6 129 /* UDP IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ 130 NETCONN_UDP_IPV6 = NETCONN_UDP | NETCONN_TYPE_IPV6 /* 0x28 */, 131 /* UDP IPv6 lite (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ 132 NETCONN_UDPLITE_IPV6 = NETCONN_UDPLITE | NETCONN_TYPE_IPV6 /* 0x29 */, 133 /* UDP IPv6 no checksum (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ 134 NETCONN_UDPNOCHKSUM_IPV6 = NETCONN_UDPNOCHKSUM | NETCONN_TYPE_IPV6 /* 0x2a */, 135 #endif /* LWIP_IPV6 */ 136 137 /* Raw connection IPv4 */ 138 NETCONN_RAW = 0x40 139 #if LWIP_IPV6 /* Raw connection IPv6 (dual-stack by default, unless you call @ref netconn_set_ipv6only) */ 140 , NETCONN_RAW_IPV6 = NETCONN_RAW | NETCONN_TYPE_IPV6 /* 0x48 */ 141 #endif /* LWIP_IPV6 */ 142 #if PF_PKT_SUPPORT 143 , NETCONN_PKT_RAW = 0x80 144 #endif 145 , NETCONN_TYPE_LAST = 0xFFFFFFFF 146 }; 147 148 /* Current state of the netconn. Non-TCP netconns are always 149 * in state NETCONN_NONE! */ 150 enum netconn_state { 151 NETCONN_NONE, 152 NETCONN_WRITE, 153 NETCONN_LISTEN, 154 NETCONN_CONNECT, 155 NETCONN_CLOSE, 156 NETCONN_CLOSED, 157 NETCONN_STATE_LAST = 0xFFFFFFFF 158 }; 159 160 /* Used to inform the callback function about changes 161 * 162 * Event explanation: 163 * 164 * In the netconn implementation, there are three ways to block a client: 165 * 166 * - accept mbox (sys_arch_mbox_fetch(&conn->acceptmbox, &accept_ptr, 0); in netconn_accept()) 167 * - receive mbox (sys_arch_mbox_fetch(&conn->recvmbox, &buf, 0); in netconn_recv_data()) 168 * - send queue is full (sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0); in lwip_netconn_do_write()) 169 * 170 * The events have to be seen as events signaling the state of these mboxes/semaphores. For non-blocking 171 * connections, you need to know in advance whether a call to a netconn function call would block or not, 172 * and these events tell you about that. 173 * 174 * RCVPLUS events say: Safe to perform a potentially blocking call call once more. 175 * They are counted in sockets - three RCVPLUS events for accept mbox means you are safe 176 * to call netconn_accept 3 times without being blocked. 177 * Same thing for receive mbox. 178 * 179 * RCVMINUS events say: Your call to to a possibly blocking function is "acknowledged". 180 * Socket implementation decrements the counter. 181 * 182 * For TX, there is no need to count, its merely a flag. SENDPLUS means you may send something. 183 * SENDPLUS occurs when enough data was delivered to peer so netconn_send() can be called again. 184 * A SENDMINUS event occurs when the next call to a netconn_send() would be blocking. 185 */ 186 enum netconn_evt { 187 NETCONN_EVT_RCVPLUS, 188 NETCONN_EVT_RCVMINUS, 189 NETCONN_EVT_SENDPLUS, 190 NETCONN_EVT_SENDMINUS, 191 NETCONN_EVT_ERROR 192 }; 193 194 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) 195 /* Used for netconn_leave_group() and netconn_leave_group_netif */ 196 enum netconn_igmp { 197 NETCONN_JOIN, 198 NETCONN_LEAVE 199 }; 200 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ 201 202 enum netconn_shutdown { 203 NON_SHUTDOWN = 0, 204 RCV_SHUTDOWN, 205 SND_SHUTDOWN, 206 SHUTDOWN_MASK, 207 NCS_LAST_FLAG = 0xFFFFFFFF 208 }; 209 210 #if LWIP_DNS 211 /* Used for netconn_gethostbyname_addrtype(), these should match the DNS_ADDRTYPE defines in dns.h */ 212 /** @cond liteos */ 213 /** Try to resolve hostname to an IPv4 address only. */ 214 #define NETCONN_DNS_IPV4 0 215 /** Try to resolve hostname to an IPv6 address only. */ 216 #define NETCONN_DNS_IPV6 1 217 /** Try to resolve hostname to an IPv4 address. If some failure happens or if no A records are received, 218 then try to resolve the hostname to an IPv6 address. If NETCONN_DNS_DEFAULT 219 is not defined, then NETCONN_DNS_IPV4_IPV6 will be taken as default. */ 220 #define NETCONN_DNS_IPV4_IPV6 2 221 /** Try to resolve hostname to an IPv6 address. If some failure happens or if no AAAA records are received, 222 then try to resolve the hostname to an IPv4 address. */ 223 #define NETCONN_DNS_IPV6_IPV4 3 224 225 #if LWIP_IPV4 && LWIP_IPV6 226 /** NETCONN_DNS_DEFAULT can be set to any one of the following values which describes the default DNS Resolution 227 behaviour for netconn_gethostbyname_addrtype(). 228 @ endcond */ 229 #ifndef NETCONN_DNS_DEFAULT 230 #define NETCONN_DNS_DEFAULT NETCONN_DNS_IPV4_IPV6 231 #endif /* NETCONN_DNS_DEFAULT */ 232 #elif LWIP_IPV4 233 #define NETCONN_DNS_DEFAULT NETCONN_DNS_IPV4 234 #else 235 #define NETCONN_DNS_DEFAULT NETCONN_DNS_IPV6 236 #endif /* LWIP_IPV4 && LWIP_IPV6 */ 237 #endif /* LWIP_DNS */ 238 #define NETCONN_MBOX_ACTIVE 1 239 #define NETCONN_MBOX_DELETING 2 240 /* forward-declare some structs to avoid to include their headers */ 241 struct ip_pcb; 242 struct tcp_pcb; 243 struct udp_pcb; 244 struct raw_pcb; 245 struct netconn; 246 struct api_msg; 247 248 /* A callback prototype to inform about events for a netconn */ 249 typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u32_t len); 250 251 /* A netconn descriptor */ 252 struct netconn { 253 /* type of the netconn (TCP, UDP or RAW) */ 254 enum netconn_type type; /* read only */ 255 /* current state of the netconn */ 256 enum netconn_state state; /* accessed only in tcipthread only */ 257 /* the lwIP internal protocol control block */ 258 union { 259 struct ip_pcb *ip; 260 struct tcp_pcb *tcp; 261 struct udp_pcb *udp; 262 struct raw_pcb *raw; 263 #if PF_PKT_SUPPORT 264 struct raw_pcb *pkt_raw; 265 #endif 266 } pcb; 267 268 #define net_tcp_pcb pcb.tcp 269 #define net_tcp_state pcb.tcp->state 270 #define net_udp_pcb pcb.udp 271 #define net_raw_pcb pcb.raw 272 #define net_ip_pcb pcb.ip 273 274 /* the last error this netconn had */ 275 err_t last_err; /* write in tcipthread, and read in application thread */ 276 #if !LWIP_NETCONN_SEM_PER_THREAD 277 /* sem that is used to synchronously execute functions in the core context */ 278 sys_sem_t op_completed; 279 #endif 280 /* mbox where received packets are stored until they are fetched 281 by the netconn application thread (can grow quite big) */ 282 sys_mbox_t recvmbox; 283 #if LWIP_TCP 284 /* mbox where new connections are stored until processed 285 by the application thread */ 286 sys_mbox_t acceptmbox; 287 #endif /* LWIP_TCP */ 288 289 /* mbox state, used for close event in parallel to recv and send events */ 290 atomic_t mbox_state; 291 292 /* only used for socket layer */ 293 #if LWIP_SOCKET 294 int socket; 295 #endif /* LWIP_SOCKET */ 296 #if LWIP_SO_SNDTIMEO 297 /* timeout to wait for sending data (which means enqueueing data for sending 298 in internal buffers) in milliseconds */ 299 s32_t send_timeout; 300 #endif /* LWIP_SO_RCVTIMEO */ 301 #if LWIP_SO_RCVTIMEO 302 /* timeout in milliseconds to wait for new data to be received 303 (or connections to arrive for listening netconns) */ 304 int recv_timeout; 305 #endif /* LWIP_SO_RCVTIMEO */ 306 #if LWIP_SO_RCVBUF 307 /* maximum amount of bytes queued in recvmbox 308 not used for TCP: adjust TCP_WND instead! */ 309 int recv_bufsize; 310 /* number of bytes currently in recvmbox to be received, 311 tested against recv_bufsize to limit bytes on recvmbox 312 for UDP and RAW, used for FIONREAD */ 313 int recv_avail; 314 #endif /* LWIP_SO_RCVBUF */ 315 /* 316 * number of bytes left on last recv, for non-stream connections, this value was the buffer_len 317 * on last peek operation; for stream connection, this value was either the bytes count 318 * not copied to application on last recv or the buffer_len on last peek operation 319 */ 320 u32_t lrcv_left; 321 #if LWIP_SO_LINGER 322 /* values <0 mean linger is disabled, values > 0 are seconds to linger */ 323 s32_t linger; 324 #endif /* LWIP_SO_LINGER */ 325 /* flags holding more netconn-internal state, see NETCONN_FLAG_* defines */ 326 u32_t flags; 327 #if LWIP_TCP 328 /* TCP: when data passed to netconn_write doesn't fit into the send buffer, 329 this temporarily stores how much is already sent. */ 330 size_t write_offset; 331 /* TCP: when data passed to netconn_write doesn't fit into the send buffer, 332 this temporarily stores the message. 333 Also used during connect and close. */ 334 struct api_msg *current_msg; 335 #endif /* LWIP_TCP */ 336 337 #if LWIP_SO_PRIORITY 338 prio_t priority; 339 #endif /* LWIP_SO_PRIORITY */ 340 341 /* A callback function that is informed about events for this netconn */ 342 netconn_callback callback; 343 atomic_t tcp_connected; 344 enum netconn_shutdown shutdown; 345 #if LWIP_SOCK_FILTER 346 struct sock_fprog sk_filter; 347 #endif 348 349 #if LWIP_TCP 350 struct pbuf *refused_data; 351 ip_addr_t remote_ip; 352 u16_t remote_port; 353 /** record pending error state after recving RST */ 354 u16_t pending_error; 355 #endif 356 }; 357 358 /* Register an Network connection event */ 359 #define API_EVENT(c, e, l) if (c->callback) { \ 360 (*c->callback)(c, e, l); \ 361 } 362 363 364 /* Set conn->mbox_state to state */ 365 #define NETCONN_SET_SAFE_MBOX_STATE(conn, state) do { \ 366 (void)atomic_set(&(conn)->mbox_state, state); \ 367 } while (0); 368 369 #define NETCONN_SET_SAFE_ERR_VAL(conn, err) do { \ 370 SYS_ARCH_DECL_PROTECT(netconn_set_safe_err_lev); \ 371 SYS_ARCH_PROTECT(netconn_set_safe_err_lev); \ 372 if (!ERR_IS_FATAL((conn)->last_err)) { \ 373 (conn)->last_err = err; \ 374 } \ 375 SYS_ARCH_UNPROTECT(netconn_set_safe_err_lev); \ 376 } while (0); 377 378 /* Set conn->last_err to err but don't overwrite fatal errors */ 379 #define NETCONN_SET_SAFE_ERR(conn, err) do { \ 380 if ((conn) != NULL) { \ 381 NETCONN_SET_SAFE_ERR_VAL(conn, err); \ 382 } \ 383 } while (0); 384 385 /* Network connection functions: */ 386 387 /* @ingroup netconn_common 388 * Create new netconn connection 389 * @param t @ref netconn_type */ 390 #define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL) 391 #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c) 392 #if PF_PKT_SUPPORT 393 struct netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u16_t proto, netconn_callback callback); 394 #else 395 struct netconn *netconn_new_with_proto_and_callback(enum netconn_type t, u8_t proto, netconn_callback callback); 396 #endif 397 398 int netconn_mbox_is_active(struct netconn *conn); 399 400 err_t netconn_initiate_delete(struct netconn *conn); 401 402 void netconn_finish_delete(struct netconn *conn); 403 404 err_t netconn_getconninfo(struct netconn *conn, void *conn_info); 405 406 err_t netconn_delete(struct netconn *conn); 407 /* Get the type of a netconn (as enum netconn_type). */ 408 #define NETCONN_TYPE(conn) (conn->type) 409 410 err_t netconn_getaddr(struct netconn *conn, ip_addr_t *addr, 411 u16_t *port, u8_t local); 412 413 #if LWIP_TCP 414 void netconn_trygetaddr(struct netconn *conn, ip_addr_t *addr, u16_t *port); 415 #endif 416 417 /* @ingroup netconn_common */ 418 #define netconn_peer(c, i, p) netconn_getaddr(c, i, p, 0) 419 /* @ingroup netconn_common */ 420 #define netconn_addr(c, i, p) netconn_getaddr(c, i, p, 1) 421 422 #if PF_PKT_SUPPORT 423 err_t netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port, u8_t ifindex); 424 #else 425 err_t netconn_bind(struct netconn *conn, const ip_addr_t *addr, u16_t port); 426 #endif 427 428 err_t netconn_connect(struct netconn *conn, const ip_addr_t *addr, u16_t port); 429 err_t netconn_disconnect (struct netconn *conn); 430 err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog); 431 /* @ingroup netconn_tcp */ 432 #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG) 433 err_t netconn_accept(struct netconn *conn, struct netconn **new_conn); 434 err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf); 435 err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf); 436 err_t netconn_sendto(struct netconn *conn, struct netbuf *buf, 437 const ip_addr_t *addr, u16_t port); 438 err_t netconn_send(struct netconn *conn, struct netbuf *buf); 439 err_t netconn_write_partly(struct netconn *conn, const void *dataptr, size_t size, 440 u8_t apiflags, size_t *bytes_written); 441 /* @ingroup netconn_tcp */ 442 #define netconn_write(conn, dataptr, size, apiflags) \ 443 netconn_write_partly(conn, dataptr, size, apiflags, NULL) 444 err_t netconn_close(struct netconn *conn); 445 err_t netconn_shutdown(struct netconn *conn, u8_t shut_rx, u8_t shut_tx); 446 447 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) 448 /* Internal function */ 449 err_t netconn_leave_group(struct netconn *conn, const ip_addr_t *multiaddr, 450 const ip_addr_t *netif_addr, enum netconn_igmp join_or_leave); 451 /* Stack needs to support to leave group for ipv6 multicast */ 452 err_t netconn_leave_group_netif(struct netconn *conn, const ip_addr_t *multiaddr, 453 u8_t if_idx, enum netconn_igmp join_or_leave); 454 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */ 455 #if LWIP_DNS 456 #if LWIP_IPV4 && LWIP_IPV6 457 err_t netconn_gethostbyname_addrtype(const char *name, ip_addr_t *addr, u32_t *count, u8_t dns_addrtype); 458 #define netconn_gethostbyname(name, addr, count) netconn_gethostbyname_addrtype(name, addr, count, NETCONN_DNS_DEFAULT) 459 #else /* LWIP_IPV4 && LWIP_IPV6 */ 460 err_t netconn_gethostbyname(const char *name, ip_addr_t *addr, u32_t *count); 461 #define netconn_gethostbyname_addrtype(name, addr, count, dns_addrtype) netconn_gethostbyname(name, addr, count) 462 #endif /* LWIP_IPV4 && LWIP_IPV6 */ 463 #endif /* LWIP_DNS */ 464 465 #if LWIP_DNS_REVERSE 466 err_t netconn_getnameinfo(ip_addr_t *addr, char *hostname); 467 #endif /* LWIP_DNS_REVERSE */ 468 469 #define netconn_err(conn) ((conn)->last_err) 470 #define netconn_recv_bufsize(conn) ((conn)->recv_bufsize) 471 472 /* Set the blocking status of netconn calls (@todo: write/send is missing) */ 473 #define netconn_set_nonblocking(conn, val) do { \ 474 if (val) { \ 475 (conn)->flags |= NETCONN_FLAG_NON_BLOCKING; \ 476 } else { \ 477 (conn)->flags &= (u8_t)~NETCONN_FLAG_NON_BLOCKING; } \ 478 } while (0) 479 /* Get the blocking status of netconn calls (@todo: write/send is missing) */ 480 #define netconn_is_nonblocking(conn) (((conn)->flags & NETCONN_FLAG_NON_BLOCKING) != 0) 481 482 #if LWIP_IPV6 483 /* @ingroup netconn_common 484 * TCP: Set the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) 485 */ 486 #define netconn_set_ipv6only(conn, val) do { \ 487 if (val) { \ 488 (conn)->flags |= NETCONN_FLAG_IPV6_V6ONLY; \ 489 } else { \ 490 (conn)->flags &= (u8_t)~NETCONN_FLAG_IPV6_V6ONLY; } \ 491 } while (0) 492 /* @ingroup netconn_common 493 * TCP: Get the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) 494 */ 495 #define netconn_get_ipv6only(conn) (((conn)->flags & NETCONN_FLAG_IPV6_V6ONLY) != 0) 496 #endif /* LWIP_IPV6 */ 497 498 #if LWIP_SO_SNDTIMEO 499 /* Set the send timeout in milliseconds */ 500 #define netconn_set_sendtimeout(conn, timeout) ((conn)->send_timeout = (timeout)) 501 /* Get the send timeout in milliseconds */ 502 #define netconn_get_sendtimeout(conn) ((conn)->send_timeout) 503 #endif /* LWIP_SO_SNDTIMEO */ 504 #if LWIP_SO_RCVTIMEO 505 /* Set the receive timeout in milliseconds */ 506 #define netconn_set_recvtimeout(conn, timeout) ((conn)->recv_timeout = (timeout)) 507 /* Get the receive timeout in milliseconds */ 508 #define netconn_get_recvtimeout(conn) ((conn)->recv_timeout) 509 #endif /* LWIP_SO_RCVTIMEO */ 510 #if LWIP_SO_RCVBUF 511 /* Set the receive buffer in bytes */ 512 #define netconn_set_recvbufsize(conn, recvbufsize) ((conn)->recv_bufsize = (recvbufsize)) 513 /* Get the receive buffer in bytes */ 514 #define netconn_get_recvbufsize(conn) ((conn)->recv_bufsize) 515 #endif /* LWIP_SO_RCVBUF */ 516 517 #if LWIP_NETCONN_SEM_PER_THREAD 518 void netconn_thread_init(void); 519 void netconn_thread_cleanup(void); 520 #else /* LWIP_NETCONN_SEM_PER_THREAD */ 521 #define netconn_thread_init() 522 #define netconn_thread_cleanup() 523 #endif /* LWIP_NETCONN_SEM_PER_THREAD */ 524 525 #if defined (__cplusplus) && __cplusplus 526 } 527 #endif 528 529 #endif /* LWIP_NETCONN || LWIP_SOCKET */ 530 531 #endif /* LWIP_HDR_API_H */ 532