@@ -33,16 +33,13 @@ L3IPInterface::~ L3IPInterface()
33
33
_stack.remove_l3ip_interface (&_interface);
34
34
}
35
35
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)
37
37
{
38
38
_dhcp = false ;
39
39
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;
46
43
47
44
return NSAPI_ERROR_OK;
48
45
}
@@ -53,8 +50,6 @@ nsapi_error_t L3IPInterface::set_dhcp(bool dhcp)
53
50
return NSAPI_ERROR_OK;
54
51
}
55
52
56
-
57
-
58
53
nsapi_error_t L3IPInterface::connect ()
59
54
{
60
55
if (!_interface) {
@@ -67,9 +62,9 @@ nsapi_error_t L3IPInterface::connect()
67
62
}
68
63
69
64
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 ,
73
68
DEFAULT_STACK,
74
69
_blocking);
75
70
}
@@ -85,7 +80,7 @@ nsapi_error_t L3IPInterface::disconnect()
85
80
nsapi_error_t L3IPInterface::get_ip_address (SocketAddress *address)
86
81
{
87
82
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 ;
89
84
return NSAPI_ERROR_OK;
90
85
}
91
86
@@ -95,7 +90,7 @@ nsapi_error_t L3IPInterface::get_ip_address(SocketAddress *address)
95
90
nsapi_error_t L3IPInterface::get_netmask (SocketAddress *address)
96
91
{
97
92
if (_interface && _interface->get_netmask (address) == NSAPI_ERROR_OK) {
98
- strncpy ( _netmask, address-> get_ip_address (), sizeof (_netmask)) ;
93
+ _netmask = *address ;
99
94
return NSAPI_ERROR_OK;
100
95
}
101
96
@@ -106,7 +101,7 @@ nsapi_error_t L3IPInterface::get_gateway(SocketAddress *address)
106
101
{
107
102
return NSAPI_ERROR_NO_CONNECTION;
108
103
if (_interface && _interface->get_gateway (address) == NSAPI_ERROR_OK) {
109
- strncpy ( _gateway, address-> get_ip_address (), sizeof (_gateway)) ;
104
+ _gateway = *address ;
110
105
return NSAPI_ERROR_OK;
111
106
}
112
107
0 commit comments