/* $Id: mcl_addr.cpp,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. */ #ifdef ALC #include "../alc/mcl_includes.h" #elif defined(NORM) #include "../norm/mcl_includes.h" #endif // RM_PROTOCOL mcl_addr::mcl_addr() { /* * Clear the address structure and set the address family. */ memset(&(this->inet_address), 0, sizeof(struct sockaddr_in)); this->inet_address.sin_family = AF_INET; this->is_multicast = false; } mcl_addr::mcl_addr(const mcl_addr& address) { /* * Copy the address structure. */ this->inet_address = address.inet_address; this->is_multicast = address.is_multicast; } mcl_addr& mcl_addr::operator=(const mcl_addr& address) { if (this != &address) { /* Copy the address structure */ this->inet_address = address.inet_address; this->is_multicast = address.is_multicast; } return(*this); } mcl_addr::~mcl_addr() { /* * Do nothing. */ } void mcl_addr::reset() { /* * Clear the address structure and set the address family. */ memset(&(this->inet_address), 0, sizeof(struct sockaddr_in)); this->inet_address.sin_family = AF_INET; this->is_multicast = false; } void mcl_addr::set_port(UINT16 port) { /* * Store the port. */ this->inet_address.sin_port = htons(port); } void mcl_addr::set_any_port() { /* * Store the port number 0. */ this->inet_address.sin_port = htons(0); } void mcl_addr::set_addr(UINT32 address) { /* * Store the address. */ this->inet_address.sin_addr.s_addr = htonl(address); if ((ntohl(this->inet_address.sin_addr.s_addr) >> 24) >= 224) { this->is_multicast = true; } else { this->is_multicast = false; } } void mcl_addr::set_any_addr() { /* * Store the address INADDR_ANY. */ this->inet_address.sin_addr.s_addr = htonl(INADDR_ANY); this->is_multicast = false; } void mcl_addr::set_addr_struct(const struct sockaddr_in *address) { /* * Get the address structure from address. * Do this safely, copying only the required information. */ this->inet_address.sin_port = address->sin_port; this->inet_address.sin_addr.s_addr = address->sin_addr.s_addr; this->inet_address.sin_family = AF_INET; if ((ntohl(this->inet_address.sin_addr.s_addr) >> 24) >= 224) { this->is_multicast = true; } else { this->is_multicast = false; } } UINT16 mcl_addr::get_port() const { /* * Return the port. */ return(ntohs(this->inet_address.sin_port)); } UINT32 mcl_addr::get_addr() const { /* * Return the address. */ return(ntohl(this->inet_address.sin_addr.s_addr)); } void mcl_addr::get_addr_struct(struct sockaddr_in *address) const { /* * Set address to the address structure. */ *address = this->inet_address; } char* mcl_addr::get_addr_string() const { /* * Use inet_ntoa() to convert the address to a dot-decimal string. * Warning: inet_ntoa is not re-entrant, and get_addr_string isn't too! */ return(inet_ntoa(this->inet_address.sin_addr)); } #if 0 bool mcl_addr::is_multicast_addr() const { /* * Check if the address is a multicast address. */ if ((ntohl(this->inet_address.sin_addr.s_addr) >> 24) >= 224) { return(true); } else { return(false); } } #endif bool mcl_addr::is_equal(const mcl_addr& address) const { /* * Check if the specified address is the "same". */ if ((this->inet_address.sin_family == address.inet_address.sin_family)&& (this->inet_address.sin_port == address.inet_address.sin_port) && (this->inet_address.sin_addr.s_addr == address.inet_address.sin_addr.s_addr)) { return(true); } else { return(false); } } bool mcl_addr::addr_is_equal(const mcl_addr& address) const { /* * Check if the specified address is the "same". * Do not consider the port, only the addr. */ if ((this->inet_address.sin_family == address.inet_address.sin_family)&& (this->inet_address.sin_addr.s_addr == address.inet_address.sin_addr.s_addr)) { return(true); } else { return(false); } }