From 094cdf1c7b1f842209c9d4a35f70bf5ac715fc2f Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Fri, 4 Mar 2016 23:06:33 +0100 Subject: [PATCH] netconn: Create API macros to get/set IPV6ONLY flag --- src/api/api_msg.c | 4 ++-- src/api/sockets.c | 8 ++++---- src/include/lwip/api.h | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 14f1a8e7..80f4f75c 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -1087,7 +1087,7 @@ lwip_netconn_do_bind(struct api_msg_msg *msg) * and NETCONN_FLAG_IPV6_V6ONLY is NOT set, use IP_ANY_TYPE to bind */ if (ip_addr_cmp(ipaddr, IP6_ADDR_ANY) && - ((msg->conn->flags & NETCONN_FLAG_IPV6_V6ONLY) == 0)) { + (netconn_get_ipv6only(msg->conn) == 0)) { /* change PCB type to IPADDR_TYPE_ANY */ IP_SET_TYPE_VAL(msg->conn->pcb.ip->local_ip, IPADDR_TYPE_ANY); IP_SET_TYPE_VAL(msg->conn->pcb.ip->remote_ip, IPADDR_TYPE_ANY); @@ -1289,7 +1289,7 @@ lwip_netconn_do_listen(struct api_msg_msg *msg) * and NETCONN_FLAG_IPV6_V6ONLY is NOT set, use IP_ANY_TYPE to listen */ if (ip_addr_cmp(&msg->conn->pcb.ip->local_ip, IP6_ADDR_ANY) && - ((msg->conn->flags & NETCONN_FLAG_IPV6_V6ONLY) == 0)) { + (netconn_get_ipv6only(msg->conn) == 0)) { /* change PCB type to IPADDR_TYPE_ANY */ IP_SET_TYPE_VAL(msg->conn->pcb.tcp->local_ip, IPADDR_TYPE_ANY); IP_SET_TYPE_VAL(msg->conn->pcb.tcp->remote_ip, IPADDR_TYPE_ANY); diff --git a/src/api/sockets.c b/src/api/sockets.c index 0f01fa2d..102ec747 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -2110,7 +2110,7 @@ lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *opt if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) { return ENOPROTOOPT; } - *(int*)optval = ((sock->conn->flags & NETCONN_FLAG_IPV6_V6ONLY) ? 1 : 0); + *(int*)optval = (netconn_get_ipv6only(sock->conn) ? 1 : 0); LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IPV6, IPV6_V6ONLY) = %d\n", s, *(int *)optval)); break; @@ -2505,12 +2505,12 @@ lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_ /* @todo: this does not work for datagram sockets, yet */ LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_TCP); if (*(const int*)optval) { - sock->conn->flags |= NETCONN_FLAG_IPV6_V6ONLY; + netconn_set_ipv6only(sock->conn, 1); } else { - sock->conn->flags &= ~NETCONN_FLAG_IPV6_V6ONLY; + netconn_set_ipv6only(sock->conn, 0); } LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IPV6, IPV6_V6ONLY, ..) -> %d\n", - s, ((sock->conn->flags & NETCONN_FLAG_IPV6_V6ONLY) ? 1 : 0))); + s, (netconn_get_ipv6only(sock->conn) ? 1 : 0))); break; default: LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IPV6, UNIMPL: optname=0x%x, ..)\n", diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h index 9ef9e78a..da872171 100644 --- a/src/include/lwip/api.h +++ b/src/include/lwip/api.h @@ -315,6 +315,16 @@ err_t netconn_gethostbyname(const char *name, ip_addr_t *addr); /** TCP: Get the no-auto-recved status of netconn calls (see NETCONN_FLAG_NO_AUTO_RECVED) */ #define netconn_get_noautorecved(conn) (((conn)->flags & NETCONN_FLAG_NO_AUTO_RECVED) != 0) +#if LWIP_IPV6 +/** TCP: Set the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) */ +#define netconn_set_ipv6only(conn, val) do { if(val) { \ + (conn)->flags |= NETCONN_FLAG_IPV6_V6ONLY; \ +} else { \ + (conn)->flags &= ~ NETCONN_FLAG_IPV6_V6ONLY; }} while(0) +/** TCP: Get the IPv6 ONLY status of netconn calls (see NETCONN_FLAG_IPV6_V6ONLY) */ +#define netconn_get_ipv6only(conn) (((conn)->flags & NETCONN_FLAG_IPV6_V6ONLY) != 0) +#endif /* LWIP_IPV6 */ + #if LWIP_SO_SNDTIMEO /** Set the send timeout in milliseconds */ #define netconn_set_sendtimeout(conn, timeout) ((conn)->send_timeout = (timeout))