Skip to content

Commit b2834b9

Browse files
committed
NanostackInterface: Allow binding to address
These days Nanostack does let you bind to an address - permit this. (Remembering to check it is an IPv6 address).
1 parent 8e5391a commit b2834b9

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

features/nanostack/FEATURE_NANOSTACK/nanostack-interface/NanostackInterface.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,12 +809,23 @@ int NanostackInterface::socket_bind(void *handle, const SocketAddress &address)
809809
return NSAPI_ERROR_NO_SOCKET;
810810
}
811811

812+
const void *addr_field;
813+
switch (address.get_ip_version()) {
814+
case NSAPI_IPv6:
815+
addr_field = address.get_ip_bytes();
816+
break;
817+
case NSAPI_UNSPEC:
818+
addr_field = &ns_in6addr_any;
819+
break;
820+
default:
821+
return NSAPI_ERROR_UNSUPPORTED;
822+
}
812823

813824
nanostack_lock();
814825

815826
ns_address_t ns_address;
816827
ns_address.type = ADDRESS_IPV6;
817-
memset(ns_address.address, 0, sizeof ns_address.address);
828+
memcpy(ns_address.address, addr_field, sizeof ns_address.address);
818829
ns_address.identifier = address.get_port();
819830
int ret = NSAPI_ERROR_DEVICE_ERROR;
820831
if (0 == ::socket_bind(socket->socket_id, &ns_address)) {

0 commit comments

Comments
 (0)