NetworkSocketAPI

Dependencies:   DnsQuery

Dependents:   HelloWizFi250Interface

Fork of NetworkSocketAPI by NetworkSocketAPI

Committer:
Christopher Haster
Date:
Tue Apr 19 18:20:38 2016 -0500
Revision:
89:b1d417383c0d
Parent:
87:94e2cf3a06be
Child:
94:644df37bb05b
Adopt mbed style doxygen comments

Who changed what in which revision?

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