diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2015-01-17 15:17:35 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2015-01-17 15:17:35 -0600 |
commit | 4848dd3d3c775335518ee7bebd09eec2444e4475 (patch) | |
tree | 9c6afa23183fcee4094a18b0d6cb6000fd7355f8 /nuttx/net/tcp | |
parent | ffb5807d85fcdbf26083043d172d82187403e7bb (diff) | |
download | px4-nuttx-4848dd3d3c775335518ee7bebd09eec2444e4475.tar.gz px4-nuttx-4848dd3d3c775335518ee7bebd09eec2444e4475.tar.bz2 px4-nuttx-4848dd3d3c775335518ee7bebd09eec2444e4475.zip |
Networking: Straighten up use if IPv6/IPv4 in TCP connection logic
Diffstat (limited to 'nuttx/net/tcp')
-rw-r--r-- | nuttx/net/tcp/tcp.h | 11 | ||||
-rw-r--r-- | nuttx/net/tcp/tcp_conn.c | 51 |
2 files changed, 41 insertions, 21 deletions
diff --git a/nuttx/net/tcp/tcp.h b/nuttx/net/tcp/tcp.h index 70e11369b..53c7f7257 100644 --- a/nuttx/net/tcp/tcp.h +++ b/nuttx/net/tcp/tcp.h @@ -1,7 +1,7 @@ /**************************************************************************** * net/tcp/tcp.h * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Redistribution and use in source and binary forms, with or without @@ -269,6 +269,7 @@ extern "C" /* Defined in tcp_conn.c ****************************************************/ +struct sockaddr; /* Forward reference */ struct tcp_iphdr_s; /* Forward reference */ /**************************************************************************** @@ -393,13 +394,7 @@ int tcp_bind(FAR struct tcp_conn_s *conn, * ****************************************************************************/ -#ifdef CONFIG_NET_IPv6 -int tcp_connect(FAR struct tcp_conn_s *conn, - FAR const struct sockaddr_in6 *addr); -#else -int tcp_connect(FAR struct tcp_conn_s *conn, - FAR const struct sockaddr_in *addr); -#endif +int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr); /* Defined in tcp_ipselect.c ************************************************/ /**************************************************************************** diff --git a/nuttx/net/tcp/tcp_conn.c b/nuttx/net/tcp/tcp_conn.c index a150ac2ac..a8283278b 100644 --- a/nuttx/net/tcp/tcp_conn.c +++ b/nuttx/net/tcp/tcp_conn.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/tcp/tcp_conn.c * - * Copyright (C) 2007-2011, 2013-2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2011, 2013-2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt <gnutt@nuttx.org> * * Large parts of this file were leveraged from uIP logic: @@ -739,13 +739,7 @@ int tcp_bind(FAR struct tcp_conn_s *conn, * ****************************************************************************/ -#ifdef CONFIG_NET_IPv6 -int tcp_connect(FAR struct tcp_conn_s *conn, - FAR const struct sockaddr_in6 *addr) -#else -int tcp_connect(FAR struct tcp_conn_s *conn, - FAR const struct sockaddr_in *addr) -#endif +int tcp_connect(FAR struct tcp_conn_s *conn, FAR const struct sockaddr *addr) { net_lock_t flags; int port; @@ -787,7 +781,6 @@ int tcp_connect(FAR struct tcp_conn_s *conn, conn->tcpstateflags = TCP_SYN_SENT; tcp_initsequence(conn->sndseq); - conn->mss = MIN_IPv4_TCP_INITIAL_MSS; conn->unacked = 1; /* TCP length of the SYN is one. */ conn->nrtx = 0; conn->timer = 1; /* Send the SYN next time around. */ @@ -801,13 +794,45 @@ int tcp_connect(FAR struct tcp_conn_s *conn, conn->sent = 0; #endif - /* The sockaddr port is 16 bits and already in network order */ + /* Save values that are specific to the IP address domain */ - conn->rport = addr->sin_port; +#ifdef CONFIG_NET_IPv4 +#ifdef CONFIG_NET_IPv6 + if (conn->domain == PF_INET) +#endif + { + FAR const struct sockaddr_in *inaddr = + (FAR const struct sockaddr_in *)addr; + + /* Save MSS and the port from the sockaddr (already in network order) */ + + conn->mss = MIN_IPv4_TCP_INITIAL_MSS; + conn->rport = inaddr->sin_port; - /* The sockaddr address is 32-bits in network order. */ + /* The sockaddr address is 32-bits in network order. */ + + net_ipv4addr_copy(conn->u.ipv4.raddr, inaddr->sin_addr.s_addr); + } +#endif /* CONFIG_NET_IPv4 */ - net_ipv4addr_copy(conn->u.ipv4.raddr, addr->sin_addr.s_addr); +#ifdef CONFIG_NET_IPv6 +#ifdef CONFIG_NET_IPv4 + else +#endif + { + FAR const struct sockaddr_in6 *inaddr = + (FAR const struct sockaddr_in6 *)addr; + + /* Save MSS and the port from the sockaddr (already in network order) */ + + conn->mss = MIN_IPv6_TCP_INITIAL_MSS; + conn->rport = inaddr->sin_port; + + /* The sockaddr address is 32-bits in network order. */ + + net_ipv6addr_copy(conn->u.ipv6.raddr, inaddr->sin6_addr.s6_addr16); + } +#endif /* CONFIG_NET_IPv6 */ #ifdef CONFIG_NET_TCP_READAHEAD /* Initialize the list of TCP read-ahead buffers */ |