00001 // @(#)root/base:$Id: TInetAddress.h 31825 2009-12-10 20:16:27Z pcanal $ 00002 // Author: Fons Rademakers 16/12/96 00003 00004 /************************************************************************* 00005 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. * 00006 * All rights reserved. * 00007 * * 00008 * For the licensing terms see $ROOTSYS/LICENSE. * 00009 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00010 *************************************************************************/ 00011 00012 #ifndef ROOT_TInetAddress 00013 #define ROOT_TInetAddress 00014 00015 00016 ////////////////////////////////////////////////////////////////////////// 00017 // // 00018 // TInetAddress // 00019 // // 00020 // This class represents an Internet Protocol (IP) address. // 00021 // Objects of this class can not be created directly, but only via // 00022 // the TSystem GetHostByName(), GetSockName(), and GetPeerName() // 00023 // members and via members of the TServerSocket and TSocket classes. // 00024 // // 00025 ////////////////////////////////////////////////////////////////////////// 00026 00027 #ifndef ROOT_TObject 00028 #include "TObject.h" 00029 #endif 00030 #ifndef ROOT_TString 00031 #include "TString.h" 00032 #endif 00033 00034 #include <vector> 00035 #ifdef R__GLOBALSTL 00036 namespace std { using ::vector; } 00037 #endif 00038 00039 00040 class TInetAddress : public TObject { 00041 00042 friend class TSystem; 00043 friend class TUnixSystem; 00044 friend class TWinNTSystem; 00045 friend class TUUID; 00046 friend class TSocket; 00047 friend class TServerSocket; 00048 friend class TXSocket; // special for BaBar 00049 00050 public: 00051 typedef std::vector<UInt_t> AddressList_t; 00052 typedef std::vector<TString> AliasList_t; 00053 00054 private: 00055 TString fHostname; // fully qualified hostname 00056 Int_t fFamily; // address family 00057 Int_t fPort; // port through which we are connected 00058 AddressList_t fAddresses; // list of all IP addresses in host byte order 00059 AliasList_t fAliases; // list of aliases 00060 00061 TInetAddress(const char *host, UInt_t addr, Int_t family, Int_t port = -1); 00062 void AddAddress(UInt_t addr); 00063 void AddAlias(const char *alias); 00064 00065 public: 00066 TInetAddress(); 00067 TInetAddress(const TInetAddress &adr); 00068 TInetAddress &operator=(const TInetAddress &rhs); 00069 virtual ~TInetAddress() { } 00070 00071 UInt_t GetAddress() const { return fAddresses[0]; } 00072 UChar_t *GetAddressBytes() const; 00073 const char *GetHostAddress() const; 00074 const char *GetHostName() const { return (const char *) fHostname; } 00075 Int_t GetFamily() const { return fFamily; } 00076 Int_t GetPort() const { return fPort; } 00077 const AddressList_t &GetAddresses() const { return fAddresses; } 00078 const AliasList_t &GetAliases() const { return fAliases; } 00079 Bool_t IsValid() const { return fFamily == -1 ? kFALSE : kTRUE; } 00080 void Print(Option_t *option="") const; 00081 00082 static const char *GetHostAddress(UInt_t addr); 00083 00084 ClassDef(TInetAddress,4) //Represents an Internet Protocol (IP) address 00085 }; 00086 00087 #endif