#include "TInetAddress.h"
#include "TClass.h"
ClassImp(TInetAddress)
TInetAddress::TInetAddress()
{
fHostname = "UnknownHost";
AddAddress(0);
fFamily = -1;
fPort = -1;
}
TInetAddress::TInetAddress(const char *host, UInt_t addr, Int_t family, Int_t port)
{
AddAddress(addr);
if (!strcmp(host, "????") || !strcmp(host, "UnNamedHost"))
fHostname = GetHostAddress();
else
fHostname = host;
fFamily = family;
fPort = port;
}
TInetAddress::TInetAddress(const TInetAddress &adr) : TObject(adr)
{
fHostname = adr.fHostname;
fFamily = adr.fFamily;
fPort = adr.fPort;
fAddresses = adr.fAddresses;
fAliases = adr.fAliases;
}
TInetAddress& TInetAddress::operator=(const TInetAddress &rhs)
{
if (this != &rhs) {
TObject::operator=(rhs);
fHostname = rhs.fHostname;
fFamily = rhs.fFamily;
fPort = rhs.fPort;
fAddresses = rhs.fAddresses;
fAliases = rhs.fAliases;
}
return *this;
}
UChar_t *TInetAddress::GetAddressBytes() const
{
UChar_t *addr = new UChar_t[4];
addr[0] = (UChar_t) ((fAddresses[0] >> 24) & 0xFF);
addr[1] = (UChar_t) ((fAddresses[0] >> 16) & 0xFF);
addr[2] = (UChar_t) ((fAddresses[0] >> 8) & 0xFF);
addr[3] = (UChar_t) (fAddresses[0] & 0xFF);
return addr;
}
const char *TInetAddress::GetHostAddress(UInt_t addr)
{
return Form("%d.%d.%d.%d", (addr >> 24) & 0xFF,
(addr >> 16) & 0xFF,
(addr >> 8) & 0xFF,
addr & 0xFF);
}
const char *TInetAddress::GetHostAddress() const
{
return GetHostAddress(fAddresses[0]);
}
void TInetAddress::Print(Option_t *) const
{
if (fPort == -1)
Printf("%s/%s (not connected)", GetHostName(), GetHostAddress());
else
Printf("%s/%s (port %d)", GetHostName(), GetHostAddress(), fPort);
int i = 0;
AddressList_t::const_iterator ai;
for (ai = fAddresses.begin(); ai != fAddresses.end(); ai++) {
if (!i) printf("%s:", fAddresses.size() == 1 ? "Address" : "Addresses");
printf(" %s", GetHostAddress(*ai));
i++;
}
if (i) printf("\n");
i = 0;
AliasList_t::const_iterator ali;
for (ali = fAliases.begin(); ali != fAliases.end(); ali++) {
if (!i) printf("%s:", fAliases.size() == 1 ? "Alias" : "Aliases");
printf(" %s", ali->Data());
i++;
}
if (i) printf("\n");
}
void TInetAddress::AddAddress(UInt_t addr)
{
fAddresses.push_back(addr);
}
void TInetAddress::AddAlias(const char *alias)
{
fAliases.push_back(TString(alias));
}
void TInetAddress::Streamer(TBuffer &R__b)
{
if (R__b.IsReading()) {
UInt_t R__s, R__c;
Version_t R__v = R__b.ReadVersion(&R__s, &R__c); if (R__v) { }
if (R__v > 2) {
R__b.ReadClassBuffer(TInetAddress::Class(), this);
return;
}
TObject::Streamer(R__b);
fHostname.Streamer(R__b);
R__b >> fAddress;
R__b >> fFamily;
R__b >> fPort;
if (R__v > 1) {
TInetAddress::AddressList_t &R__stl1 = fAddresses;
R__stl1.clear();
int R__i, R__n;
R__b >> R__n;
R__stl1.reserve(R__n);
for (R__i = 0; R__i < R__n; R__i++) {
unsigned int R__t1;
R__b >> R__t1;
R__stl1.push_back(R__t1);
}
TInetAddress::AliasList_t &R__stl2 = fAliases;
R__stl2.clear();
R__b >> R__n;
R__stl2.reserve(R__n);
for (R__i = 0; R__i < R__n; R__i++) {
TString R__t2;
R__t2.Streamer(R__b);
R__stl2.push_back(R__t2);
}
}
R__b.CheckByteCount(R__s, R__c, TInetAddress::IsA());
} else {
R__b.WriteClassBuffer(TInetAddress::Class(), this);
}
}