NetworkSocketAPI
Dependents: HelloWizFi250Interface
Fork of NetworkSocketAPI by
NetworkInterface.cpp@42:49893d13c432, 2016-02-23 (annotated)
- Committer:
- Christopher Haster
- Date:
- Tue Feb 23 05:07:02 2016 -0600
- Branch:
- api-changes
- Revision:
- 42:49893d13c432
- Parent:
- 41:3ec1c97e9bbf
- Child:
- 43:09ea32f2eb54
Standardized some C++ style things
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 |
41:3ec1c97e9bbf | 23 | : _timeout(15000) |
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 |
39:47138420ea42 | 30 | void NetworkInterface::useDHCP() |
Christopher Haster |
39:47138420ea42 | 31 | { |
Christopher Haster |
42:49893d13c432 | 32 | memset(_ip_address, 0, NS_IP_SIZE); |
Christopher Haster |
42:49893d13c432 | 33 | memset(_network_mask, 0, NS_IP_SIZE); |
Christopher Haster |
42:49893d13c432 | 34 | memset(_gateway, 0, NS_IP_SIZE); |
Christopher Haster |
39:47138420ea42 | 35 | } |
Christopher Haster |
39:47138420ea42 | 36 | |
geky | 30:3cc78f5db99d | 37 | void NetworkInterface::setIPAddress(const char *ip) |
geky | 30:3cc78f5db99d | 38 | { |
Christopher Haster |
23:1e86d9fb3d86 | 39 | strcpy(_ip_address, ip); |
Christopher Haster |
23:1e86d9fb3d86 | 40 | } |
Christopher Haster |
23:1e86d9fb3d86 | 41 | |
geky | 30:3cc78f5db99d | 42 | void NetworkInterface::setNetworkMask(const char *mask) |
geky | 30:3cc78f5db99d | 43 | { |
Christopher Haster |
23:1e86d9fb3d86 | 44 | strcpy(_network_mask, mask); |
Christopher Haster |
23:1e86d9fb3d86 | 45 | } |
Christopher Haster |
23:1e86d9fb3d86 | 46 | |
geky | 30:3cc78f5db99d | 47 | void NetworkInterface::setGateway(const char *gateway) |
geky | 30:3cc78f5db99d | 48 | { |
Christopher Haster |
23:1e86d9fb3d86 | 49 | strcpy(_gateway, gateway); |
Christopher Haster |
23:1e86d9fb3d86 | 50 | } |
Christopher Haster |
23:1e86d9fb3d86 | 51 | |
geky | 30:3cc78f5db99d | 52 | const char *NetworkInterface::getIPAddress() |
geky | 30:3cc78f5db99d | 53 | { |
Christopher Haster |
39:47138420ea42 | 54 | if (_ip_address[0]) { |
Christopher Haster |
39:47138420ea42 | 55 | return _ip_address; |
Christopher Haster |
39:47138420ea42 | 56 | } else { |
Christopher Haster |
39:47138420ea42 | 57 | return 0; |
Christopher Haster |
39:47138420ea42 | 58 | } |
Christopher Haster |
23:1e86d9fb3d86 | 59 | } |
Christopher Haster |
23:1e86d9fb3d86 | 60 | |
geky | 30:3cc78f5db99d | 61 | const char *NetworkInterface::getNetworkMask() |
geky | 30:3cc78f5db99d | 62 | { |
Christopher Haster |
39:47138420ea42 | 63 | if (_network_mask[0]) { |
Christopher Haster |
39:47138420ea42 | 64 | return _network_mask; |
Christopher Haster |
39:47138420ea42 | 65 | } else { |
Christopher Haster |
39:47138420ea42 | 66 | return 0; |
Christopher Haster |
39:47138420ea42 | 67 | } |
Christopher Haster |
23:1e86d9fb3d86 | 68 | } |
Christopher Haster |
23:1e86d9fb3d86 | 69 | |
geky | 30:3cc78f5db99d | 70 | const char *NetworkInterface::getGateway() |
geky | 30:3cc78f5db99d | 71 | { |
Christopher Haster |
39:47138420ea42 | 72 | if (_gateway[0]) { |
Christopher Haster |
39:47138420ea42 | 73 | return _gateway; |
Christopher Haster |
39:47138420ea42 | 74 | } else { |
Christopher Haster |
39:47138420ea42 | 75 | return 0; |
Christopher Haster |
39:47138420ea42 | 76 | } |
Christopher Haster |
23:1e86d9fb3d86 | 77 | } |
Christopher Haster |
23:1e86d9fb3d86 | 78 | |
Christopher Haster |
41:3ec1c97e9bbf | 79 | void NetworkInterface::setTimeout(uint32_t timeout) |
Christopher Haster |
41:3ec1c97e9bbf | 80 | { |
Christopher Haster |
41:3ec1c97e9bbf | 81 | _timeout = timeout; |
Christopher Haster |
41:3ec1c97e9bbf | 82 | } |
Christopher Haster |
41:3ec1c97e9bbf | 83 | |
Christopher Haster |
41:3ec1c97e9bbf | 84 | uint32_t NetworkInterface::getTimeout() |
Christopher Haster |
41:3ec1c97e9bbf | 85 | { |
Christopher Haster |
41:3ec1c97e9bbf | 86 | return _timeout; |
Christopher Haster |
41:3ec1c97e9bbf | 87 | } |
Christopher Haster |
41:3ec1c97e9bbf | 88 | |
geky | 30:3cc78f5db99d | 89 | bool NetworkInterface::isConnected() |
geky | 30:3cc78f5db99d | 90 | { |
Christopher Haster |
23:1e86d9fb3d86 | 91 | return getIPAddress() != 0; |
Christopher Haster |
23:1e86d9fb3d86 | 92 | } |
Christopher Haster |
23:1e86d9fb3d86 | 93 | |
geky | 31:7f15b95f2a1d | 94 | int32_t NetworkInterface::getHostByName(const char *name, char *ip) |
geky | 31:7f15b95f2a1d | 95 | { |
geky | 31:7f15b95f2a1d | 96 | UDPSocket sock(this); |
geky | 31:7f15b95f2a1d | 97 | DnsQuery dns(&sock, name, ip); |
geky | 31:7f15b95f2a1d | 98 | return 0; |
geky | 31:7f15b95f2a1d | 99 | } |