Example of AWS IoT connection and Web Dashboard thru STM32 Nucleo evaluation board and mbed OS.
Dependencies: X_NUCLEO_IKS01A1 mbed FP MQTTPacket DnsQuery ATParser
SocketAddress.h
00001 /* SocketAddress 00002 * Copyright (c) 2015 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SOCKET_ADDRESS_H 00018 #define SOCKET_ADDRESS_H 00019 00020 #include <stdint.h> 00021 00022 00023 /** Maximum size of IP address representation 00024 */ 00025 #define NSAPI_IP_SIZE NSAPI_IPv6_SIZE 00026 00027 /** Maximum number of bytes for IP address 00028 */ 00029 #define NSAPI_IP_BYTES NSAPI_IPv6_BYTES 00030 00031 /** Maximum size of MAC address representation 00032 */ 00033 #define NSAPI_MAC_SIZE 18 00034 00035 /** Maximum number of bytes for MAC address 00036 */ 00037 #define NSAPI_MAC_BYTES 6 00038 00039 /** Enum of IP address versions 00040 * 00041 * The IP version specifies the type of an IP address. 00042 * 00043 * @enum nsapi_version_t 00044 */ 00045 enum nsapi_version_t { 00046 NSAPI_IPv4, /*!< Address is IPv4 */ 00047 NSAPI_IPv6, /*!< Address is IPv6 */ 00048 }; 00049 00050 /** Size of IPv4 representation 00051 */ 00052 #define NSAPI_IPv4_SIZE 16 00053 00054 /** Number of bytes in IPv4 address 00055 */ 00056 #define NSAPI_IPv4_BYTES 4 00057 00058 /** Size of IPv6 representation 00059 */ 00060 #define NSAPI_IPv6_SIZE 40 00061 00062 /** Number of bytes in IPv6 address 00063 */ 00064 #define NSAPI_IPv6_BYTES 16 00065 00066 // Predeclared classes 00067 class NetworkStack; 00068 00069 00070 /** SocketAddress class 00071 * 00072 * Representation of an IP address and port pair. 00073 */ 00074 class SocketAddress { 00075 public: 00076 /** Create a SocketAddress from a hostname and port 00077 * 00078 * The hostname may be either a domain name or an IP address. If the 00079 * hostname is an IP address, no network transactions will be performed. 00080 * 00081 * On failure, the IP address and port will be set to zero 00082 * 00083 * @param iface Network stack to use for DNS resolution 00084 * @param host Hostname to resolve 00085 * @param port Optional 16-bit port 00086 */ 00087 SocketAddress(NetworkStack *iface, const char *host, uint16_t port = 0); 00088 00089 /** Create a SocketAddress from an IP address and port 00090 * 00091 * @param host Null-terminated representation of the IP address 00092 * @param port Optional 16-bit port 00093 */ 00094 SocketAddress(const char *addr = 0, uint16_t port = 0); 00095 00096 /** Create a SocketAddress from a raw IP address and port 00097 * 00098 * @param bytes Raw IP address in big-endian order 00099 * @param version IP address version, NSAPI_IPv4 or NSAPI_IPv6 00100 * @param port Optional 16-bit port 00101 */ 00102 SocketAddress(const void *bytes, nsapi_version_t version, uint16_t port = 0); 00103 00104 /** Create a SocketAddress from another SocketAddress 00105 * 00106 * @param address SocketAddress to copy 00107 */ 00108 SocketAddress(const SocketAddress &addr); 00109 00110 /** Set the IP address 00111 * 00112 * @param addr Null-terminated represention of the IP address 00113 */ 00114 void set_ip_address(const char *addr); 00115 00116 /** Set the raw IP address 00117 * 00118 * @param bytes Raw IP address in big-endian order 00119 * @param version IP address version, NSAPI_IPv4 or NSAPI_IPv6 00120 */ 00121 void set_ip_bytes(const void *bytes, nsapi_version_t version); 00122 00123 /** Set the port 00124 * 00125 * @param port 16-bit port 00126 */ 00127 void set_port(uint16_t port); 00128 00129 /** Get the IP address 00130 * 00131 * @return Null-terminated representation of the IP Address 00132 */ 00133 const char *get_ip_address() const; 00134 00135 /** Get the raw IP address 00136 * 00137 * @return Raw IP address in big-endian order 00138 */ 00139 const void *get_ip_bytes() const; 00140 00141 /** Get the IP address version 00142 * 00143 * @return IP address version, NSAPI_IPv4 or NSAPI_IPv6 00144 */ 00145 nsapi_version_t get_ip_version() const; 00146 00147 /** Get the port 00148 * 00149 * @return The 16-bit port 00150 */ 00151 uint16_t get_port() const; 00152 00153 /** Test if address is zero 00154 * 00155 * @return True if address is not zero 00156 */ 00157 operator bool() const; 00158 00159 private: 00160 char _ip_address[NSAPI_IP_SIZE]; 00161 uint8_t _ip_bytes[NSAPI_IP_BYTES]; 00162 nsapi_version_t _ip_version; 00163 uint16_t _port; 00164 }; 00165 00166 #endif
Generated on Wed Jul 13 2022 20:28:49 by 1.7.2