This is Unofficial EPICS BASE Doxygen Site
inetAddrID.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /*
11  *
12  * L O S A L A M O S
13  * Los Alamos National Laboratory
14  * Los Alamos, New Mexico 87545
15  *
16  * Copyright, 1986, The Regents of the University of California.
17  *
18  * Author: Jeff Hill
19  */
20 
21 #ifndef INC_inetAddrID_H
22 #define INC_inetAddrID_H
23 
24 #include "osiSock.h"
25 #include "resourceLib.h"
26 
27 class inetAddrID {
28 public:
29  inetAddrID ( const struct sockaddr_in & addrIn );
30  bool operator == ( const inetAddrID & ) const;
31  resTableIndex hash () const;
32  void name ( char *pBuf, unsigned bufSize ) const;
33 private:
34  struct sockaddr_in addr;
35 };
36 
37 inline inetAddrID::inetAddrID ( const struct sockaddr_in & addrIn ) :
38  addr ( addrIn )
39 {
40 }
41 
42 inline bool inetAddrID::operator == ( const inetAddrID &rhs ) const
43 {
44  if ( this->addr.sin_addr.s_addr == rhs.addr.sin_addr.s_addr ) {
45  if ( this->addr.sin_port == rhs.addr.sin_port ) {
46  return true;
47  }
48  }
49  return false;
50 }
51 
53 {
54  const unsigned inetAddrMinIndexBitWidth = 8u;
55  const unsigned inetAddrMaxIndexBitWidth = 32u;
56  unsigned index;
57  index = this->addr.sin_addr.s_addr;
58  index ^= this->addr.sin_port;
59  index ^= this->addr.sin_port >> 8u;
60  return integerHash ( inetAddrMinIndexBitWidth,
61  inetAddrMaxIndexBitWidth, index );
62 }
63 
64 inline void inetAddrID::name ( char *pBuf, unsigned bufSize ) const
65 {
66  ipAddrToDottedIP ( &this->addr, pBuf, bufSize );
67 }
68 
69 #endif // ifdef INC_inetAddrID_H
70 
71 
resTableIndex hash() const
Definition: inetAddrID.h:52
bool operator==(const inetAddrID &) const
Definition: inetAddrID.h:42
inetAddrID(const struct sockaddr_in &addrIn)
Definition: inetAddrID.h:37
size_t resTableIndex
Definition: resourceLib.h:45
resTableIndex integerHash(unsigned MIN_INDEX_WIDTH, unsigned MAX_ID_WIDTH, const T &id)
Definition: resourceLib.h:1032
void name(char *pBuf, unsigned bufSize) const
Definition: inetAddrID.h:64
unsigned epicsStdCall ipAddrToDottedIP(const struct sockaddr_in *paddr, char *pBuf, unsigned bufSize)
Definition: osiSock.c:144