Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DnsQuery
Dependents: WizFi310_TCP_Echo_Server_Example
Fork of NetworkSocketAPI by
NetworkInterface.h
- Committer:
- Christopher Haster
- Date:
- 2016-02-25
- Revision:
- 57:3c873fab4207
- Parent:
- 55:7ff3586d7af4
- Child:
- 59:badee747a030
File content as of revision 57:3c873fab4207:
/* NetworkInterface Base Class
* Copyright (c) 2015 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef NETWORK_INTERFACE_H
#define NETWORK_INTERFACE_H
#include "SocketInterface.h"
#include "stdint.h"
/** Maximum storage needed for IP address and MAC addresses
*/
#define NS_IP_SIZE 16
#define NS_MAC_SIZE 18
/** Inexhaustive enum of standardized error codes
*/
enum ns_error_t {
NS_ERROR_TIMEOUT = -3001,
NS_ERROR_NO_CONNECTION = -3002,
NS_ERROR_NO_SOCKET = -3003,
NS_ERROR_NO_ADDRESS = -3004,
NS_ERROR_NO_MEMORY = -3005,
NS_ERROR_DNS_FAILURE = -3006,
NS_ERROR_DHCP_FAILURE = -3007,
NS_ERROR_AUTH_FAILURE = -3008,
NS_ERROR_DEVICE_ERROR = -3009
};
/** NetworkInterface class
* Common interface that is shared between all hardware that
* can connect to a network over IP.
*/
class NetworkInterface
{
public:
virtual ~NetworkInterface() {};
/** Enables or disables DHCP
* @note DHCP resolution does not occur until connect
* @note DHCP is enabled by default
* @param enable Enables DHCP if true
*/
virtual void setDHCP(bool enable);
/** Set the static IP address of the network interface
* @param ip Static IP address, copied internally
*/
virtual void setIPAddress(const char *ip);
/** Set the static network mask of the network interface
* @param mask Static network mask, copied internally
*/
virtual void setNetworkMask(const char *mask);
/** Set the static gateway of the network interface
* @param gateway Gateway address, copied internally
*/
virtual void setGateway(const char *gateway);
/** Checks if DHCP is enabled
* @return True if DHCP is enabled
*/
virtual bool getDHCP();
/** Get the IP address
* @return IP address of the interface
*/
virtual const char *getIPAddress();
/** Get the network mask
* @return Network mask of the interface
*/
virtual const char *getNetworkMask();
/** Get the gateway
* @return Gateway address of the interface
*/
virtual const char *getGateway();
/** Get the current MAC address
* @return String MAC address of the interface
*/
virtual const char *getMACAddress() = 0;
/** Get the current status of the interface
* @return true if connected
*/
virtual bool isConnected();
/** Looks up the specified host's IP address
* @param name URL of host
* @param ip Buffer to hold IP address, must be at least SOCK_IP_SIZE
* @return 0 on success
*/
virtual int32_t getHostByName(const char *name, char *ip);
protected:
NetworkInterface();
friend class Socket;
/** Internally create a socket
* @param proto The type of socket to open, NS_TCP or NS_UDP
* @return The allocated socket
*/
virtual SocketInterface *createSocket(ns_protocol_t proto) = 0;
/** Internally destroy a socket
* @param socket An allocated SocketInterface
* @returns 0 on success
*/
virtual void destroySocket(SocketInterface *socket) = 0;
private:
bool _dhcp_enabled;
char _ip_address[NS_IP_SIZE];
char _network_mask[NS_IP_SIZE];
char _gateway[NS_IP_SIZE];
};
#endif
