xrootd
XrdMonSenderInfo.hh
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* */
3 /* XrdMonSenderInfo.hh */
4 /* */
5 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Jacek Becla for Stanford University under contract */
8 /* DE-AC02-76SF00515 with the Department of Energy */
9 /*****************************************************************************/
10 
11 // $Id$
12 
13 #ifndef XRDMONSENDERINFO_HH
14 #define XRDMONSENDERINFO_HH
15 
16 #include "XrdMon/XrdMonTypes.hh"
17 #include <stdio.h>
18 #include <netinet/in.h>
19 #include <map>
20 #include <vector>
21 using std::map;
22 using std::vector;
23 
25 public:
26  static senderid_t convert2Id(struct sockaddr_in sAddr);
27  static hp_t addr2HostPort(struct sockaddr_in sAddr) {
28  return id2HostPort(convert2Id(sAddr));
29  }
31  if ( id >= _hps.size() ) {
32  return hp_t((char*) "Error, invalid offset", 0);
33  }
34  return _hps[id];
35  }
36  static const char* id2HostPortStr(senderid_t id) {
37  hp_t hp = id2HostPort(id);
38  static char x[256];
39  sprintf(x, "%s:%d", hp.first, hp.second);
40  return x;
41  }
42 
43  static const char* id2Host(senderid_t id) {
44  if ( id >= _hps.size() ) {
45  return "Error, invalid offset";
46  }
47  return _hps[id].first;
48  }
49  static void printSelf();
50 
51  static void shutdown();
52 
53 private:
54  static void registerSender(struct sockaddr_in sAddr);
55 
56 private:
57  // Maps hash of sockaddr_in --> id.
58  // Used as offset in various vectors
59  static map<kXR_int64, senderid_t> _ids;
60 
61  static vector<hp_t> _hps; // {host, port}
62 };
63 
64 #endif /* XRDMONSENDERINFO_HH */