Skip to content

Commit 7d9b5e6

Browse files
gekyc1728p9
authored andcommitted
Small bug fixes
mirrored from: https://developer.mbed.org/teams/NetworkSocketAPI/code/NetworkSocketAPI/ - Fix bug with SocketAddress init per @c1728p9 - Fix issue with not passing interface through accept call - Fix port issue in SocketAddress constructor
1 parent 8304124 commit 7d9b5e6

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

net/NetworkSocketAPI/SocketAddress.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,17 @@ static void ipv6_to_address(char *addr, const uint8_t *bytes)
144144

145145
SocketAddress::SocketAddress(NetworkStack *iface, const char *host, uint16_t port)
146146
{
147+
memset(&_ip_address, 0, sizeof _ip_address);
148+
147149
// Check for valid IP addresses
148150
if (host && ipv4_is_valid(host)) {
149151
_ip_version = NSAPI_IPv4;
150152
ipv4_from_address(_ip_bytes, host);
153+
set_port(port);
151154
} else if (host && ipv6_is_valid(host)) {
152155
_ip_version = NSAPI_IPv6;
153156
ipv4_from_address(_ip_bytes, host);
157+
set_port(port);
154158
} else {
155159
// DNS lookup
156160
int err = iface->gethostbyname(this, host);
@@ -166,18 +170,21 @@ SocketAddress::SocketAddress(NetworkStack *iface, const char *host, uint16_t por
166170

167171
SocketAddress::SocketAddress(const char *addr, uint16_t port)
168172
{
173+
memset(&_ip_address, 0, sizeof _ip_address);
169174
set_ip_address(addr);
170175
set_port(port);
171176
}
172177

173178
SocketAddress::SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port)
174179
{
180+
memset(&_ip_address, 0, sizeof _ip_address);
175181
set_ip_bytes(bytes, version);
176182
set_port(port);
177183
}
178184

179185
SocketAddress::SocketAddress(const SocketAddress &addr)
180186
{
187+
memset(&_ip_address, 0, sizeof _ip_address);
181188
set_ip_bytes(addr.get_ip_bytes(), addr.get_ip_version());
182189
set_port(addr.get_port());
183190
}
@@ -202,10 +209,10 @@ void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version)
202209
{
203210
_ip_address[0] = '\0';
204211

205-
if (_ip_version == NSAPI_IPv4) {
212+
if (version == NSAPI_IPv4) {
206213
_ip_version = NSAPI_IPv4;
207214
memcpy(_ip_bytes, bytes, NSAPI_IPv4_BYTES);
208-
} else if (_ip_version == NSAPI_IPv6) {
215+
} else if (version == NSAPI_IPv6) {
209216
_ip_version = NSAPI_IPv6;
210217
memcpy(_ip_bytes, bytes, NSAPI_IPv6_BYTES);
211218
} else {

net/NetworkSocketAPI/TCPServer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ int TCPServer::accept(TCPSocket *connection)
6161
void *socket;
6262
int err = _iface->socket_accept(&socket, _socket);
6363
if (!err) {
64+
connection->_iface = _iface;
6465
connection->_socket = socket;
6566
}
6667

0 commit comments

Comments
 (0)