Logo ROOT  
Reference Guide
TInetAddress.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 16/12/96
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TInetAddress
13 #define ROOT_TInetAddress
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // TInetAddress //
19 // //
20 // This class represents an Internet Protocol (IP) address. //
21 // Objects of this class can not be created directly, but only via //
22 // the TSystem GetHostByName(), GetSockName(), and GetPeerName() //
23 // members and via members of the TServerSocket and TSocket classes. //
24 // //
25 //////////////////////////////////////////////////////////////////////////
26 
27 #include "TObject.h"
28 #include "TString.h"
29 
30 #include <vector>
31 #ifdef R__GLOBALSTL
32 namespace std { using ::vector; }
33 #endif
34 
35 
36 class TInetAddress : public TObject {
37 
38 friend class TSystem;
39 friend class TUnixSystem;
40 friend class TWinNTSystem;
41 friend class TUUID;
42 friend class TSocket;
43 friend class TUDPSocket;
44 friend class TServerSocket;
45 friend class TXSocket; // special for BaBar
46 
47 public:
48  typedef std::vector<UInt_t> AddressList_t;
49  typedef std::vector<TString> AliasList_t;
50 
51 private:
52  TString fHostname; // fully qualified hostname
53  Int_t fFamily; // address family
54  Int_t fPort; // port through which we are connected
55  AddressList_t fAddresses; // list of all IP addresses in host byte order
56  AliasList_t fAliases; // list of aliases
57 
58  TInetAddress(const char *host, UInt_t addr, Int_t family, Int_t port = -1);
59  void AddAddress(UInt_t addr);
60  void AddAlias(const char *alias);
61 
62 public:
63  TInetAddress();
64  TInetAddress(const TInetAddress &adr);
65  TInetAddress &operator=(const TInetAddress &rhs);
66  virtual ~TInetAddress() { }
67 
68  UInt_t GetAddress() const { return fAddresses[0]; }
69  UChar_t *GetAddressBytes() const;
70  const char *GetHostAddress() const;
71  const char *GetHostName() const { return (const char *) fHostname; }
72  Int_t GetFamily() const { return fFamily; }
73  Int_t GetPort() const { return fPort; }
74  const AddressList_t &GetAddresses() const { return fAddresses; }
75  const AliasList_t &GetAliases() const { return fAliases; }
76  Bool_t IsValid() const { return fFamily == -1 ? kFALSE : kTRUE; }
77  void Print(Option_t *option="") const;
78 
79  static const char *GetHostAddress(UInt_t addr);
80 
81  ClassDef(TInetAddress,4) //Represents an Internet Protocol (IP) address
82 };
83 
84 #endif
TWinNTSystem
Definition: TWinNTSystem.h:67
TUDPSocket
Definition: TUDPSocket.h:37
TXSocket
Definition: TXSocket.h:59
kTRUE
const Bool_t kTRUE
Definition: RtypesCore.h:91
TInetAddress::AddAddress
void AddAddress(UInt_t addr)
Add alternative address to list of addresses.
Definition: TInetAddress.cxx:150
TInetAddress::fAliases
AliasList_t fAliases
Definition: TInetAddress.h:62
TInetAddress::fPort
Int_t fPort
Definition: TInetAddress.h:60
TInetAddress::GetHostName
const char * GetHostName() const
Definition: TInetAddress.h:77
TInetAddress::fFamily
Int_t fFamily
Definition: TInetAddress.h:59
TInetAddress::GetFamily
Int_t GetFamily() const
Definition: TInetAddress.h:78
TInetAddress::operator=
TInetAddress & operator=(const TInetAddress &rhs)
TInetAddress assignment operator.
Definition: TInetAddress.cxx:65
TSystem
Definition: TSystem.h:266
Int_t
int Int_t
Definition: RtypesCore.h:45
TString
Definition: TString.h:136
TInetAddress::GetAddressBytes
UChar_t * GetAddressBytes() const
Returns the raw IP address in host byte order.
Definition: TInetAddress.cxx:84
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TString.h
TUnixSystem
Definition: TUnixSystem.h:32
TSocket
Definition: TSocket.h:41
TInetAddress::GetAddress
UInt_t GetAddress() const
Definition: TInetAddress.h:74
Option_t
const typedef char Option_t
Definition: RtypesCore.h:66
TInetAddress::GetAddresses
const AddressList_t & GetAddresses() const
Definition: TInetAddress.h:80
TInetAddress::TInetAddress
TInetAddress()
Default ctor. Used in case of unknown host. Not a valid address.
Definition: TInetAddress.cxx:26
TInetAddress::AliasList_t
std::vector< TString > AliasList_t
Definition: TInetAddress.h:55
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TInetAddress::fHostname
TString fHostname
Definition: TInetAddress.h:58
TInetAddress::~TInetAddress
virtual ~TInetAddress()
Definition: TInetAddress.h:72
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TInetAddress::Print
void Print(Option_t *option="") const
Print internet address as string.
Definition: TInetAddress.cxx:121
TUUID
Definition: TUUID.h:42
unsigned int
TInetAddress::AddAlias
void AddAlias(const char *alias)
Add alias to list of aliases.
Definition: TInetAddress.cxx:158
TObject.h
UChar_t
unsigned char UChar_t
Definition: RtypesCore.h:38
TInetAddress::fAddresses
AddressList_t fAddresses
Definition: TInetAddress.h:61
TObject
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TInetAddress::AddressList_t
std::vector< UInt_t > AddressList_t
Definition: TInetAddress.h:54
TInetAddress::GetAliases
const AliasList_t & GetAliases() const
Definition: TInetAddress.h:81
TServerSocket
Definition: TServerSocket.h:42
TInetAddress
Definition: TInetAddress.h:36
TInetAddress::IsValid
Bool_t IsValid() const
Definition: TInetAddress.h:82
TInetAddress::GetHostAddress
const char * GetHostAddress() const
Returns the IP address string "%d.%d.%d.%d".
Definition: TInetAddress.cxx:113
int
TInetAddress::GetPort
Int_t GetPort() const
Definition: TInetAddress.h:79