/* $Id: mcl_addr.h,v 1.1.1.1 2003/09/03 12:45:44 chneuman Exp $ */ /* * Copyright (c) 2003 INRIA - All rights reserved * (main author: Vincent Roca - vincent.roca@inrialpes.fr) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, * USA. */ #ifndef mcl_addr_h #define mcl_addr_h /** * Class defining an IP address. * Currently only supports IPv4. */ class mcl_addr { public: /** * Default constructor. */ mcl_addr (); /** * Copy constructor. * @param address The address object to copy. */ mcl_addr (const mcl_addr & address); /** * The destructor. */ ~mcl_addr (); /** * The operator=. * @param address The address object to copy. * @return A reference to this object. */ mcl_addr & operator=(const mcl_addr & address); /** * Manual reset of an address. * This function resets all fields of the address. * Usefull when the default constructor cannot be called. */ void reset (void); /****** SET FUNCTIONS *************************************************/ /** * Set the port number. * @param port New port number in host byte order. */ void set_port (UINT16 port); /** * Set the port number to "any". */ void set_any_port (); /** * Set the address. * Restricted to IPv4 addresses. * @param address New address in host byte order. */ void set_addr (UINT32 address); /** * Set the address to "any". */ void set_any_addr (); /** * Set the entire address at one time. * @param address New address in network byte order. */ void set_addr_struct (const struct sockaddr_in *address); /****** GET FUNCTIONS *************************************************/ /** * Return the address port number. * @return Address port number in host byte order. */ UINT16 get_port () const; /** * Returns the sockaddr_in(6) length. * @reuturn Length in bytes of the internal sockaddr_in * or sockaddr_in6 structure. */ int get_addr_struct_len (void) const; /** * Return the address as a UINT32. * Restricted to IPv4 addresses. * @return Address in host byte order. */ UINT32 get_addr () const; /** * Get the entire address at one time. * @param address Pointer to a sockaddr_in structure where * the address will be placed in network byte * order. */ void get_addr_struct (struct sockaddr_in *address) const; /** * Return the internal sockaddr buffer address. * @return address of internal sockaddr buffer. */ struct sockaddr* get_internal_struct_addr (void); /** * Return the address as a string in dot-decimal format. * Warning: inet_ntoa is not re-entrant, and get_addr_string isn't too! * @return Temporary character buffer containing * the string. This buffer is overwritten by * subsequent calls to this method. */ char* get_addr_string () const; /****** TEST FUNCTIONS ************************************************/ /** * Checks if the address is a multicast address. * @return TRUE if this is a multicast address, * FALSE otherwise. */ bool is_multicast_addr () const; /** * Checks if the specified object is the "same" as this object. * This function compares all fields of the address object. * @param address The address to compare against. * @return TRUE if the address is the "same" as * this object, FALSE otherwise. */ bool is_equal (const mcl_addr & address) const; /** * Checks if the IP address of the specified object is the "same" * as this object. * It does not consider the port info, only the IP address. * @param address The address to compare against. * @return TRUE if the address is the "same" as this * object, FALSE otherwise. */ bool addr_is_equal (const mcl_addr & address) const; private: /** * The internet address structure in network byte order. */ struct sockaddr_in inet_address; bool is_multicast; }; //---------------------------------------------------------------------------- // Inlines for all classes follow //---------------------------------------------------------------------------- inline bool mcl_addr::is_multicast_addr() const { return (this->is_multicast); } inline int mcl_addr::get_addr_struct_len (void) const { return (sizeof(struct sockaddr_in)); } inline struct sockaddr* mcl_addr::get_internal_struct_addr () { return ((struct sockaddr*) &(this->inet_address)); } #endif // mcl_addr_h