Base class for IP Based Networking Libraries
Dependencies: DnsQuery
Dependents: TempTower BSDInterfaceTests HelloBSDInterface ESP8266InterfaceTests ... more
For a complete getting started guide see the wiki...
Network Socket API
The Network Socket API provides a common interface for using sockets on network devices. The API provides a simple class-based interface that should be familiar to users experienced with other socket APIs. Additionally, the API provides a simple interface for implementing network devices, making it easy to connect hardware agnostic programs to new devices.
Network Interfaces
The NetworkInterface provides an abstract class for network devices that support sockets. Devices should provide a DeviceInterface class that inherits this interface and adds implementation specific methods for using the device. A NetworkInterface must be provided to a Socket constructor to open a socket on the interface. Currently two subclasses are defined for common devices, EthernetInterface
and WiFiInterface.
Sockets
The Socket class is used for managing network sockets. Once opened, the socket provides a pipe through which data can sent and recieved to a specific endpoint. The socket class can be instantiated as either a TCPSocket
or a UDPSocket
which defines the protocol used for the connection.
Diff: SocketAddress.cpp
- Revision:
- 120:6eb542426f15
- Parent:
- 111:df01ca3e89b3
- Child:
- 122:b316a6631ef8
diff -r 96627c4b83d5 -r 6eb542426f15 SocketAddress.cpp --- a/SocketAddress.cpp Wed Apr 20 20:38:00 2016 -0500 +++ b/SocketAddress.cpp Mon May 09 22:40:00 2016 -0500 @@ -144,13 +144,17 @@ SocketAddress::SocketAddress(NetworkStack *iface, const char *host, uint16_t port) { + memset(&_ip_address, 0, sizeof _ip_address); + // Check for valid IP addresses if (host && ipv4_is_valid(host)) { _ip_version = NSAPI_IPv4; ipv4_from_address(_ip_bytes, host); + set_port(port); } else if (host && ipv6_is_valid(host)) { _ip_version = NSAPI_IPv6; ipv4_from_address(_ip_bytes, host); + set_port(port); } else { // DNS lookup int err = iface->gethostbyname(this, host); @@ -166,18 +170,21 @@ SocketAddress::SocketAddress(const char *addr, uint16_t port) { + memset(&_ip_address, 0, sizeof _ip_address); set_ip_address(addr); set_port(port); } SocketAddress::SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port) { + memset(&_ip_address, 0, sizeof _ip_address); set_ip_bytes(bytes, version); set_port(port); } SocketAddress::SocketAddress(const SocketAddress &addr) { + memset(&_ip_address, 0, sizeof _ip_address); set_ip_bytes(addr.get_ip_bytes(), addr.get_ip_version()); set_port(addr.get_port()); }