@@ -144,13 +144,17 @@ static void ipv6_to_address(char *addr, const uint8_t *bytes)
144
144
145
145
SocketAddress::SocketAddress (NetworkStack *iface, const char *host, uint16_t port)
146
146
{
147
+ memset (&_ip_address, 0 , sizeof _ip_address);
148
+
147
149
// Check for valid IP addresses
148
150
if (host && ipv4_is_valid (host)) {
149
151
_ip_version = NSAPI_IPv4;
150
152
ipv4_from_address (_ip_bytes, host);
153
+ set_port (port);
151
154
} else if (host && ipv6_is_valid (host)) {
152
155
_ip_version = NSAPI_IPv6;
153
156
ipv4_from_address (_ip_bytes, host);
157
+ set_port (port);
154
158
} else {
155
159
// DNS lookup
156
160
int err = iface->gethostbyname (this , host);
@@ -166,18 +170,21 @@ SocketAddress::SocketAddress(NetworkStack *iface, const char *host, uint16_t por
166
170
167
171
SocketAddress::SocketAddress (const char *addr, uint16_t port)
168
172
{
173
+ memset (&_ip_address, 0 , sizeof _ip_address);
169
174
set_ip_address (addr);
170
175
set_port (port);
171
176
}
172
177
173
178
SocketAddress::SocketAddress (const void *bytes, nsapi_version_t version, uint16_t port)
174
179
{
180
+ memset (&_ip_address, 0 , sizeof _ip_address);
175
181
set_ip_bytes (bytes, version);
176
182
set_port (port);
177
183
}
178
184
179
185
SocketAddress::SocketAddress (const SocketAddress &addr)
180
186
{
187
+ memset (&_ip_address, 0 , sizeof _ip_address);
181
188
set_ip_bytes (addr.get_ip_bytes (), addr.get_ip_version ());
182
189
set_port (addr.get_port ());
183
190
}
@@ -202,10 +209,10 @@ void SocketAddress::set_ip_bytes(const void *bytes, nsapi_version_t version)
202
209
{
203
210
_ip_address[0 ] = ' \0 ' ;
204
211
205
- if (_ip_version == NSAPI_IPv4) {
212
+ if (version == NSAPI_IPv4) {
206
213
_ip_version = NSAPI_IPv4;
207
214
memcpy (_ip_bytes, bytes, NSAPI_IPv4_BYTES);
208
- } else if (_ip_version == NSAPI_IPv6) {
215
+ } else if (version == NSAPI_IPv6) {
209
216
_ip_version = NSAPI_IPv6;
210
217
memcpy (_ip_bytes, bytes, NSAPI_IPv6_BYTES);
211
218
} else {
0 commit comments