@@ -33,16 +33,13 @@ L3IPInterface::~ L3IPInterface()
3333 _stack.remove_l3ip_interface (&_interface);
3434}
3535
36- nsapi_error_t L3IPInterface::set_network (const char * ip_address, const char * netmask, const char * gateway)
36+ nsapi_error_t L3IPInterface::set_network (const SocketAddress & ip_address, const SocketAddress & netmask, const SocketAddress & gateway)
3737{
3838 _dhcp = false ;
3939
40- strncpy (_ip_address, ip_address ? ip_address : " " , sizeof (_ip_address));
41- _ip_address[sizeof (_ip_address) - 1 ] = ' \0 ' ;
42- strncpy (_netmask, netmask ? netmask : " " , sizeof (_netmask));
43- _netmask[sizeof (_netmask) - 1 ] = ' \0 ' ;
44- strncpy (_gateway, gateway ? gateway : " " , sizeof (_gateway));
45- _gateway[sizeof (_gateway) - 1 ] = ' \0 ' ;
40+ _ip_address = ip_address;
41+ _netmask = netmask;
42+ _gateway = gateway;
4643
4744 return NSAPI_ERROR_OK;
4845}
@@ -53,8 +50,6 @@ nsapi_error_t L3IPInterface::set_dhcp(bool dhcp)
5350 return NSAPI_ERROR_OK;
5451}
5552
56-
57-
5853nsapi_error_t L3IPInterface::connect ()
5954{
6055 if (!_interface) {
@@ -67,9 +62,9 @@ nsapi_error_t L3IPInterface::connect()
6762 }
6863
6964 return _interface->bringup (_dhcp,
70- _ip_address[ 0 ] ? _ip_address : 0 ,
71- _netmask[ 0 ] ? _netmask : 0 ,
72- _gateway[ 0 ] ? _gateway : 0 ,
65+ _ip_address ? _ip_address. get_ip_address () : 0 ,
66+ _netmask ? _netmask. get_ip_address () : 0 ,
67+ _gateway ? _gateway. get_ip_address () : 0 ,
7368 DEFAULT_STACK,
7469 _blocking);
7570}
@@ -85,7 +80,7 @@ nsapi_error_t L3IPInterface::disconnect()
8580nsapi_error_t L3IPInterface::get_ip_address (SocketAddress *address)
8681{
8782 if (_interface && _interface->get_ip_address (address) == NSAPI_ERROR_OK) {
88- strncpy ( _ip_address, address-> get_ip_address (), sizeof (_ip_address)) ;
83+ _ip_address = *address ;
8984 return NSAPI_ERROR_OK;
9085 }
9186
@@ -95,7 +90,7 @@ nsapi_error_t L3IPInterface::get_ip_address(SocketAddress *address)
9590nsapi_error_t L3IPInterface::get_netmask (SocketAddress *address)
9691{
9792 if (_interface && _interface->get_netmask (address) == NSAPI_ERROR_OK) {
98- strncpy ( _netmask, address-> get_ip_address (), sizeof (_netmask)) ;
93+ _netmask = *address ;
9994 return NSAPI_ERROR_OK;
10095 }
10196
@@ -106,7 +101,7 @@ nsapi_error_t L3IPInterface::get_gateway(SocketAddress *address)
106101{
107102 return NSAPI_ERROR_NO_CONNECTION;
108103 if (_interface && _interface->get_gateway (address) == NSAPI_ERROR_OK) {
109- strncpy ( _gateway, address-> get_ip_address (), sizeof (_gateway)) ;
104+ _gateway = *address ;
110105 return NSAPI_ERROR_OK;
111106 }
112107
0 commit comments