@@ -992,6 +992,32 @@ static nsapi_error_t mbed_lwip_socket_bind(nsapi_stack_t *stack, nsapi_socket_t
992
992
return NSAPI_ERROR_PARAMETER ;
993
993
}
994
994
995
+ #if LWIP_IPV6
996
+ if (IP_IS_V6 (ip_addr ) && !ip6_addr_isany (& ip_addr )) {
997
+ const ip_addr_t * local_addr = mbed_lwip_get_ipv6_addr (& lwip_netif );
998
+ if (!local_addr ) {
999
+ return NSAPI_ERROR_PARAMETER ;
1000
+ }
1001
+
1002
+ if (!ip6_addr_cmp (local_addr , & ip_addr )) {
1003
+ return NSAPI_ERROR_PARAMETER ;
1004
+ }
1005
+ }
1006
+ #endif
1007
+
1008
+ #if LWIP_IPV4
1009
+ if (IP_IS_V4 (ip_addr ) && !ip4_addr_isany (& ip_addr )) {
1010
+ const ip_addr_t * local_addr = mbed_lwip_get_ipv4_addr (& lwip_netif );
1011
+ if (!local_addr ) {
1012
+ return NSAPI_ERROR_PARAMETER ;
1013
+ }
1014
+
1015
+ if (!ip4_addr_cmp (local_addr , & ip_addr )) {
1016
+ return NSAPI_ERROR_PARAMETER ;
1017
+ }
1018
+ }
1019
+ #endif
1020
+
995
1021
err_t err = netconn_bind (s -> conn , & ip_addr , port );
996
1022
return mbed_lwip_err_remap (err );
997
1023
}
@@ -1000,6 +1026,10 @@ static nsapi_error_t mbed_lwip_socket_listen(nsapi_stack_t *stack, nsapi_socket_
1000
1026
{
1001
1027
struct lwip_socket * s = (struct lwip_socket * )handle ;
1002
1028
1029
+ if (s -> conn -> pcb .tcp -> local_port == 0 ) {
1030
+ return NSAPI_ERROR_PARAMETER ;
1031
+ }
1032
+
1003
1033
err_t err = netconn_listen_with_backlog (s -> conn , backlog );
1004
1034
return mbed_lwip_err_remap (err );
1005
1035
}
@@ -1028,6 +1058,10 @@ static nsapi_error_t mbed_lwip_socket_accept(nsapi_stack_t *stack, nsapi_socket_
1028
1058
return NSAPI_ERROR_NO_SOCKET ;
1029
1059
}
1030
1060
1061
+ if (s -> conn -> pcb .tcp -> state != LISTEN ) {
1062
+ return NSAPI_ERROR_PARAMETER ;
1063
+ }
1064
+
1031
1065
err_t err = netconn_accept (s -> conn , & ns -> conn );
1032
1066
if (err != ERR_OK ) {
1033
1067
mbed_lwip_arena_dealloc (ns );
0 commit comments