NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
Revision 39:47138420ea42, committed 2016-02-22
- Comitter:
- Christopher Haster
- Date:
- Mon Feb 22 21:50:15 2016 -0600
- Branch:
- api-changes
- Parent:
- 38:157fb2ab965f
- Child:
- 40:11d4a94df3f7
- Commit message:
- Added proper handling of missing ip/port
Changed in this revision
--- a/NetworkInterface.cpp Mon Feb 22 20:51:09 2016 -0600 +++ b/NetworkInterface.cpp Mon Feb 22 21:50:15 2016 -0600 @@ -26,6 +26,13 @@ memset(_gateway, 0, SOCK_IP_SIZE); } +void NetworkInterface::useDHCP() +{ + memset(_ip_address, 0, SOCK_IP_SIZE); + memset(_network_mask, 0, SOCK_IP_SIZE); + memset(_gateway, 0, SOCK_IP_SIZE); +} + void NetworkInterface::setIPAddress(const char *ip) { strcpy(_ip_address, ip); @@ -43,17 +50,29 @@ const char *NetworkInterface::getIPAddress() { - return _ip_address; + if (_ip_address[0]) { + return _ip_address; + } else { + return 0; + } } const char *NetworkInterface::getNetworkMask() { - return _network_mask; + if (_network_mask[0]) { + return _network_mask; + } else { + return 0; + } } const char *NetworkInterface::getGateway() { - return _gateway; + if (_gateway[0]) { + return _gateway; + } else { + return 0; + } } bool NetworkInterface::isConnected()
--- a/NetworkInterface.h Mon Feb 22 20:51:09 2016 -0600 +++ b/NetworkInterface.h Mon Feb 22 21:50:15 2016 -0600 @@ -34,7 +34,7 @@ * DHCP is enabled by default * @return 0 on success */ - virtual int32_t useDHCP() = 0; + virtual int32_t useDHCP(); /** Set the static IP address of the network interface * @param ip Static IP address, copied internally
--- a/Socket.cpp Mon Feb 22 20:51:09 2016 -0600 +++ b/Socket.cpp Mon Feb 22 21:50:15 2016 -0600 @@ -63,7 +63,11 @@ const char *Socket::getIPAddress() const { - return _ip_address; + if (_ip_address[0]) { + return _ip_address; + } else { + return 0; + } } uint16_t Socket::getPort() const @@ -96,7 +100,7 @@ setPort(port); } - if (!_ip_address[0] || !_port) { + if (!getIPAddress() || !getPort()) { return -3; }