00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <sys/socket.h>
00023 #include <netinet/in.h>
00024 #include <arpa/inet.h>
00025
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);