IPAddress.cc

Go to the documentation of this file.
00001 /*
00002  * This file is part of openSDK.
00003  *
00004  * Copyright (C) 2006-2007 openSDK team
00005  *
00006  * openSDK is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; version 2.
00009  *
00010  * openSDK is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with openSDK; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *
00019  *     $Id: IPAddress.cc,v 1.3 2007/01/26 23:12:05 nuno-lopes Exp $
00020  */
00021 
00022 #include <sys/socket.h>
00023 #include <netinet/in.h>
00024 #include <arpa/inet.h>
00025 // avoid warnings
00026 #undef IPPROTO_IP
00027 #undef IPPROTO_ICMP
00028 #undef IPPROTO_IGMP
00029 #undef IPPROTO_GGP
00030 #undef IPPROTO_TCP
00031 #undef IPPROTO_EGP
00032 #undef IPPROTO_PUP
00033 #undef IPPROTO_UDP
00034 #undef IPPROTO_IDP
00035 #undef IPPROTO_TP
00036 #undef IPPROTO_EON
00037 #undef IPPROTO_ENCAP
00038 #undef IPPROTO_RAW
00039 #undef IPPROTO_MAX
00040 #undef IPPROTO_RESERVED
00041 #undef IPPROTO_UNRESERVED
00042 #include <IPAddress.h>
00043 
00044 IPAddress::IPAddress(byte b1, byte b2, byte b3, byte b4)
00045 {
00046         address = (b1 << 24) + (b2 << 16) + (b3 << 8) + b4;
00047 }
00048 
00049 IPAddress::IPAddress(const char *str)
00050 {
00051         struct in_addr in;
00052         inet_aton(str, &in);
00053         address = in.s_addr;
00054 }
00055 
00056 char* IPAddress::GetAsString(char* str) const
00057 {
00058         struct in_addr in = {address};
00059         strcpy(str, inet_ntoa(in));
00060         return str;
00061 }
00062 
00063 OSTREAM& IPAddress::print(OSTREAM& os) const
00064 {
00065         char tmp[50];
00066         os << GetAsString(tmp);
00067         return os;
00068 }
00069 
00070 const IPAddress IP_ADDR_ANY((uint32)INADDR_ANY);
00071 const IPAddress IP_ADDR_BROADCAST((uint32)INADDR_BROADCAST);

Generated on Sun Dec 2 23:04:28 2007 for openSDK by  doxygen 1.3.9.1