ap

Dependencies:   DnsQuery

Dependents:   WizFi310_TCP_Echo_Server_Example

Fork of NetworkSocketAPI by NetworkSocketAPI

Committer:
Christopher Haster
Date:
Tue Apr 05 12:02:56 2016 -0500
Revision:
80:9c6673c93082
Parent:
79:43a7e8c0d6cc
Child:
87:94e2cf3a06be
Added support for DNS resolution

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Christopher Haster 78:0914f9b9b24b 1 /* Socket
Christopher Haster 78:0914f9b9b24b 2 * Copyright (c) 2015 ARM Limited
Christopher Haster 75:dea0cdb42241 3 *
Christopher Haster 78:0914f9b9b24b 4 * Licensed under the Apache License, Version 2.0 (the "License");
Christopher Haster 78:0914f9b9b24b 5 * you may not use this file except in compliance with the License.
Christopher Haster 78:0914f9b9b24b 6 * You may obtain a copy of the License at
Christopher Haster 75:dea0cdb42241 7 *
Christopher Haster 78:0914f9b9b24b 8 * http://www.apache.org/licenses/LICENSE-2.0
Christopher Haster 75:dea0cdb42241 9 *
Christopher Haster 78:0914f9b9b24b 10 * Unless required by applicable law or agreed to in writing, software
Christopher Haster 78:0914f9b9b24b 11 * distributed under the License is distributed on an "AS IS" BASIS,
Christopher Haster 78:0914f9b9b24b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Christopher Haster 78:0914f9b9b24b 13 * See the License for the specific language governing permissions and
Christopher Haster 78:0914f9b9b24b 14 * limitations under the License.
Christopher Haster 75:dea0cdb42241 15 */
Christopher Haster 78:0914f9b9b24b 16
Christopher Haster 76:bbe51641f405 17 #ifndef SOCKET_ADDRESS_H
Christopher Haster 76:bbe51641f405 18 #define SOCKET_ADDRESS_H
Christopher Haster 75:dea0cdb42241 19
Christopher Haster 79:43a7e8c0d6cc 20 #include <stdint.h>
Christopher Haster 79:43a7e8c0d6cc 21
Christopher Haster 80:9c6673c93082 22 // Predeclared classes
Christopher Haster 80:9c6673c93082 23 class NetworkInterface;
Christopher Haster 80:9c6673c93082 24
Christopher Haster 75:dea0cdb42241 25 /**
Christopher Haster 75:dea0cdb42241 26 * A general socket address composed of the IP address and port
Christopher Haster 75:dea0cdb42241 27 */
Christopher Haster 75:dea0cdb42241 28 class SocketAddress {
Christopher Haster 75:dea0cdb42241 29 public:
Christopher Haster 80:9c6673c93082 30 /** Maximum size of IP address
Christopher Haster 80:9c6673c93082 31 */
Christopher Haster 80:9c6673c93082 32 static const int IP_SIZE = 16;
Christopher Haster 80:9c6673c93082 33
Christopher Haster 80:9c6673c93082 34 /** SocketAddress construction using DNS resolution
Christopher Haster 80:9c6673c93082 35 /param iface NetworkInterface to use for DNS resolution
Christopher Haster 80:9c6673c93082 36 /param addr Null-terminated hostname that will be resolved
Christopher Haster 80:9c6673c93082 37 /param port 16-bit port
Christopher Haster 80:9c6673c93082 38 /note on failure, IP address and port will be set to null
Christopher Haster 80:9c6673c93082 39 */
Christopher Haster 80:9c6673c93082 40 SocketAddress(NetworkInterface *iface, const char *addr, uint16_t port = 0);
Christopher Haster 80:9c6673c93082 41
Christopher Haster 79:43a7e8c0d6cc 42 /** SocketAddress construction
Christopher Haster 80:9c6673c93082 43 /param addr Null-terminated IP address
Christopher Haster 80:9c6673c93082 44 /param port 16-bit port
Christopher Haster 80:9c6673c93082 45 /note on failure, IP address and port will be set to null
Christopher Haster 80:9c6673c93082 46 */
Christopher Haster 76:bbe51641f405 47 SocketAddress(const char *addr = 0, uint16_t port = 0);
Christopher Haster 80:9c6673c93082 48
Christopher Haster 80:9c6673c93082 49 /** SocketAddress construction
Christopher Haster 80:9c6673c93082 50 /param addr SocketAddress to copy
Christopher Haster 80:9c6673c93082 51 */
Christopher Haster 80:9c6673c93082 52 SocketAddress(const SocketAddress &addr);
Christopher Haster 75:dea0cdb42241 53
Christopher Haster 75:dea0cdb42241 54 /** Set the IP address
Christopher Haster 80:9c6673c93082 55 \param addr Null-terminated string representing the IP address
Christopher Haster 75:dea0cdb42241 56 */
Christopher Haster 79:43a7e8c0d6cc 57 void set_ip_address(const char *addr);
Christopher Haster 75:dea0cdb42241 58
Christopher Haster 75:dea0cdb42241 59 /** Set the port
Christopher Haster 80:9c6673c93082 60 \param port 16-bit port
Christopher Haster 75:dea0cdb42241 61 */
Christopher Haster 75:dea0cdb42241 62 void set_port(uint16_t port);
Christopher Haster 75:dea0cdb42241 63
Christopher Haster 75:dea0cdb42241 64 /** Get the IP address
Christopher Haster 80:9c6673c93082 65 \return The string representation of the IP Address
Christopher Haster 75:dea0cdb42241 66 */
Christopher Haster 79:43a7e8c0d6cc 67 const char *get_ip_address() const;
Christopher Haster 75:dea0cdb42241 68
Christopher Haster 75:dea0cdb42241 69 /** Get the port
Christopher Haster 80:9c6673c93082 70 \return The 16-bit port
Christopher Haster 75:dea0cdb42241 71 */
Christopher Haster 79:43a7e8c0d6cc 72 uint16_t get_port(void) const;
Christopher Haster 79:43a7e8c0d6cc 73
Christopher Haster 79:43a7e8c0d6cc 74 private:
Christopher Haster 80:9c6673c93082 75 char _ip_address[IP_SIZE];
Christopher Haster 79:43a7e8c0d6cc 76 uint16_t _port;
Christopher Haster 75:dea0cdb42241 77 };
Christopher Haster 75:dea0cdb42241 78
Christopher Haster 75:dea0cdb42241 79 #endif