00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 00021 #ifndef INET_SOCKET_ADDRESS_H 00022 #define INET_SOCKET_ADDRESS_H 00023 00024 #include "address.h" 00025 #include "ipv4-address.h" 00026 #include <stdint.h> 00027 00028 namespace ns3 { 00029 00030 00031 /** 00032 * \ingroup address 00033 * 00034 * \brief an Inet address class 00035 * 00036 * This class is similar to inet_sockaddr in the BSD socket 00037 * API. i.e., this class holds an Ipv4Address and a port number 00038 * to form an ipv4 transport endpoint. 00039 */ 00040 class InetSocketAddress 00041 { 00042 public: 00043 /** 00044 * \param ipv4 the ipv4 address 00045 * \param port the port number 00046 */ 00047 InetSocketAddress (Ipv4Address ipv4, uint16_t port); 00048 /** 00049 * \param ipv4 the ipv4 address 00050 * 00051 * The port number is set to zero by default. 00052 */ 00053 InetSocketAddress (Ipv4Address ipv4); 00054 /** 00055 * \param port the port number 00056 * 00057 * The ipv4 address is set to the "Any" address by default. 00058 */ 00059 InetSocketAddress (uint16_t port); 00060 /** 00061 * \param ipv4 string which represents an ipv4 address 00062 * \param port the port number 00063 */ 00064 InetSocketAddress (const char *ipv4, uint16_t port); 00065 /** 00066 * \param ipv4 string which represents an ipv4 address 00067 * 00068 * The port number is set to zero. 00069 */ 00070 InetSocketAddress (const char *ipv4); 00071 /** 00072 * \returns the port number 00073 */ 00074 uint16_t GetPort (void) const; 00075 /** 00076 * \returns the ipv4 address 00077 */ 00078 Ipv4Address GetIpv4 (void) const; 00079 00080 /** 00081 * \param port the new port number. 00082 */ 00083 void SetPort (uint16_t port); 00084 /** 00085 * \param address the new ipv4 address 00086 */ 00087 void SetIpv4 (Ipv4Address address); 00088 00089 /** 00090 * \returns true if the address matches, false otherwise. 00091 */ 00092 static bool IsMatchingType (const Address &address); 00093 00094 /** 00095 * \returns an Address instance which represents this 00096 * InetSocketAddress instance. 00097 */ 00098 operator Address () const; 00099 00100 /** 00101 * \param address the Address instance to convert from. 00102 * 00103 * Returns an InetSocketAddress which corresponds to the input 00104 * Address 00105 */ 00106 static InetSocketAddress ConvertFrom (const Address &address); 00107 private: 00108 Address ConvertTo (void) const; 00109 00110 static uint8_t GetType (void); 00111 Ipv4Address m_ipv4; 00112 uint16_t m_port; 00113 }; 00114 00115 } // namespace ns3 00116 00117 00118 #endif /* INET_SOCKET_ADDRESS_H */