NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
Diff: NetworkInterface.cpp
- Branch:
- api-changes
- Revision:
- 23:1e86d9fb3d86
- Child:
- 28:163fbe3263f4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NetworkInterface.cpp Thu Feb 18 04:05:09 2016 -0600 @@ -0,0 +1,65 @@ +/* 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. + */ + +#include "NetworkInterface.h" +#include <stdlib.h> +#include <string.h> + +#define IP_SIZE 16 + +NetworkInterface::NetworkInterface() + : _ip_address(0) + , _network_mask(0) + , _gateway(0) { +} + +NetworkInterface::~NetworkInterface() { + if (_ip_address) free(_ip_address); + if (_network_mask) free(_network_mask); + if (_gateway) free(_gateway); +} + +void NetworkInterface::setIPAddress(const char *ip) { + _ip_address = (char*)malloc(IP_SIZE); + strcpy(_ip_address, ip); +} + +void NetworkInterface::setNetworkMask(const char *mask) { + _network_mask = (char*)malloc(IP_SIZE); + strcpy(_network_mask, mask); +} + +void NetworkInterface::setGateway(const char *gateway) { + _gateway = (char*)malloc(IP_SIZE); + strcpy(_gateway, gateway); +} + +const char *NetworkInterface::getIPAddress() { + return _ip_address; +} + +const char *NetworkInterface::getNetworkMask() { + return _network_mask; +} + +const char *NetworkInterface::getGateway() { + return _gateway; +} + +bool NetworkInterface::isConnected() { + return getIPAddress() != 0; +} +