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).
pull/3165/head
Kevin Bracey 2016-10-31 10:17:29 +02:00
parent 8e5391ab85
commit b2834b9aa6
1 changed files with 12 additions and 1 deletions

View File

@ -809,12 +809,23 @@ int NanostackInterface::socket_bind(void *handle, const SocketAddress &address)
return NSAPI_ERROR_NO_SOCKET;
}
const void *addr_field;
switch (address.get_ip_version()) {
case NSAPI_IPv6:
addr_field = address.get_ip_bytes();
break;
case NSAPI_UNSPEC:
addr_field = &ns_in6addr_any;
break;
default:
return NSAPI_ERROR_UNSUPPORTED;
}
nanostack_lock();
ns_address_t ns_address;
ns_address.type = ADDRESS_IPV6;
memset(ns_address.address, 0, sizeof ns_address.address);
memcpy(ns_address.address, addr_field, sizeof ns_address.address);
ns_address.identifier = address.get_port();
int ret = NSAPI_ERROR_DEVICE_ERROR;
if (0 == ::socket_bind(socket->socket_id, &ns_address)) {