NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
NetworkInterface.cpp@56:19c9e332c0f1, 2016-02-29 (annotated)
- Committer:
- geky
- Date:
- Mon Feb 29 15:23:24 2016 +0000
- Revision:
- 56:19c9e332c0f1
- Parent:
- 52:52a6c4ea7128
- Child:
- 59:badee747a030
Updated DnsQuery
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Christopher Haster |
23:1e86d9fb3d86 | 1 | /* NetworkInterface Base Class |
Christopher Haster |
23:1e86d9fb3d86 | 2 | * Copyright (c) 2015 ARM Limited |
Christopher Haster |
23:1e86d9fb3d86 | 3 | * |
Christopher Haster |
23:1e86d9fb3d86 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Christopher Haster |
23:1e86d9fb3d86 | 5 | * you may not use this file except in compliance with the License. |
Christopher Haster |
23:1e86d9fb3d86 | 6 | * You may obtain a copy of the License at |
Christopher Haster |
23:1e86d9fb3d86 | 7 | * |
Christopher Haster |
23:1e86d9fb3d86 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Christopher Haster |
23:1e86d9fb3d86 | 9 | * |
Christopher Haster |
23:1e86d9fb3d86 | 10 | * Unless required by applicable law or agreed to in writing, software |
Christopher Haster |
23:1e86d9fb3d86 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Christopher Haster |
23:1e86d9fb3d86 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Christopher Haster |
23:1e86d9fb3d86 | 13 | * See the License for the specific language governing permissions and |
Christopher Haster |
23:1e86d9fb3d86 | 14 | * limitations under the License. |
Christopher Haster |
23:1e86d9fb3d86 | 15 | */ |
Christopher Haster |
23:1e86d9fb3d86 | 16 | |
Christopher Haster |
23:1e86d9fb3d86 | 17 | #include "NetworkInterface.h" |
geky | 31:7f15b95f2a1d | 18 | #include "UDPSocket.h" |
geky | 31:7f15b95f2a1d | 19 | #include "DnsQuery.h" |
Christopher Haster |
23:1e86d9fb3d86 | 20 | #include <string.h> |
Christopher Haster |
23:1e86d9fb3d86 | 21 | |
geky | 30:3cc78f5db99d | 22 | NetworkInterface::NetworkInterface() |
Christopher Haster |
52:52a6c4ea7128 | 23 | : _dhcp_enabled(true) |
geky | 30:3cc78f5db99d | 24 | { |
Christopher Haster |
42:49893d13c432 | 25 | memset(_ip_address, 0, NS_IP_SIZE); |
Christopher Haster |
42:49893d13c432 | 26 | memset(_network_mask, 0, NS_IP_SIZE); |
Christopher Haster |
42:49893d13c432 | 27 | memset(_gateway, 0, NS_IP_SIZE); |
Christopher Haster |
23:1e86d9fb3d86 | 28 | } |
Christopher Haster |
23:1e86d9fb3d86 | 29 | |
Christopher Haster |
52:52a6c4ea7128 | 30 | void NetworkInterface::setDHCP(bool enabled) |
Christopher Haster |
39:47138420ea42 | 31 | { |
Christopher Haster |
52:52a6c4ea7128 | 32 | _dhcp_enabled = enabled; |
Christopher Haster |
39:47138420ea42 | 33 | } |
Christopher Haster |
39:47138420ea42 | 34 | |
geky | 30:3cc78f5db99d | 35 | void NetworkInterface::setIPAddress(const char *ip) |
geky | 30:3cc78f5db99d | 36 | { |
Christopher Haster |
23:1e86d9fb3d86 | 37 | strcpy(_ip_address, ip); |
Christopher Haster |
23:1e86d9fb3d86 | 38 | } |
Christopher Haster |
23:1e86d9fb3d86 | 39 | |
geky | 30:3cc78f5db99d | 40 | void NetworkInterface::setNetworkMask(const char *mask) |
geky | 30:3cc78f5db99d | 41 | { |
Christopher Haster |
23:1e86d9fb3d86 | 42 | strcpy(_network_mask, mask); |
Christopher Haster |
23:1e86d9fb3d86 | 43 | } |
Christopher Haster |
23:1e86d9fb3d86 | 44 | |
geky | 30:3cc78f5db99d | 45 | void NetworkInterface::setGateway(const char *gateway) |
geky | 30:3cc78f5db99d | 46 | { |
Christopher Haster |
23:1e86d9fb3d86 | 47 | strcpy(_gateway, gateway); |
Christopher Haster |
23:1e86d9fb3d86 | 48 | } |
Christopher Haster |
23:1e86d9fb3d86 | 49 | |
Christopher Haster |
52:52a6c4ea7128 | 50 | bool NetworkInterface::getDHCP() |
Christopher Haster |
52:52a6c4ea7128 | 51 | { |
Christopher Haster |
52:52a6c4ea7128 | 52 | return _dhcp_enabled; |
Christopher Haster |
52:52a6c4ea7128 | 53 | } |
Christopher Haster |
52:52a6c4ea7128 | 54 | |
geky | 30:3cc78f5db99d | 55 | const char *NetworkInterface::getIPAddress() |
geky | 30:3cc78f5db99d | 56 | { |
Christopher Haster |
39:47138420ea42 | 57 | if (_ip_address[0]) { |
Christopher Haster |
39:47138420ea42 | 58 | return _ip_address; |
Christopher Haster |
39:47138420ea42 | 59 | } else { |
Christopher Haster |
39:47138420ea42 | 60 | return 0; |
Christopher Haster |
39:47138420ea42 | 61 | } |
Christopher Haster |
23:1e86d9fb3d86 | 62 | } |
Christopher Haster |
23:1e86d9fb3d86 | 63 | |
geky | 30:3cc78f5db99d | 64 | const char *NetworkInterface::getNetworkMask() |
geky | 30:3cc78f5db99d | 65 | { |
Christopher Haster |
39:47138420ea42 | 66 | if (_network_mask[0]) { |
Christopher Haster |
39:47138420ea42 | 67 | return _network_mask; |
Christopher Haster |
39:47138420ea42 | 68 | } else { |
Christopher Haster |
39:47138420ea42 | 69 | return 0; |
Christopher Haster |
39:47138420ea42 | 70 | } |
Christopher Haster |
23:1e86d9fb3d86 | 71 | } |
Christopher Haster |
23:1e86d9fb3d86 | 72 | |
geky | 30:3cc78f5db99d | 73 | const char *NetworkInterface::getGateway() |
geky | 30:3cc78f5db99d | 74 | { |
Christopher Haster |
39:47138420ea42 | 75 | if (_gateway[0]) { |
Christopher Haster |
39:47138420ea42 | 76 | return _gateway; |
Christopher Haster |
39:47138420ea42 | 77 | } else { |
Christopher Haster |
39:47138420ea42 | 78 | return 0; |
Christopher Haster |
39:47138420ea42 | 79 | } |
Christopher Haster |
23:1e86d9fb3d86 | 80 | } |
Christopher Haster |
23:1e86d9fb3d86 | 81 | |
geky | 30:3cc78f5db99d | 82 | bool NetworkInterface::isConnected() |
geky | 30:3cc78f5db99d | 83 | { |
Christopher Haster |
23:1e86d9fb3d86 | 84 | return getIPAddress() != 0; |
Christopher Haster |
23:1e86d9fb3d86 | 85 | } |
Christopher Haster |
23:1e86d9fb3d86 | 86 | |
geky | 31:7f15b95f2a1d | 87 | int32_t NetworkInterface::getHostByName(const char *name, char *ip) |
geky | 31:7f15b95f2a1d | 88 | { |
geky | 56:19c9e332c0f1 | 89 | return dnsQuery(this, name, ip); |
geky | 31:7f15b95f2a1d | 90 | } |