root / otg / trunk / src / cpp / address.h

Revision 575, 2.1 kB (checked in by zhibinwu, 3 years ago)

implement clone for address, fix a bug in genTimestamp reporting, remove flow.cpp from Makefile

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1#ifndef ADDRESS_H
2#define ADDRESS_H
3
4#define MAX_HOSTNAME_LENGTH 256
5#define MAC_ADDR_LENGTH 6
6
7#include <string.h>
8//#include <popt.h>
9
10/**
11 *  Address Class is to handle addresses.
12 *  For normal socket, the address used will be a combination of IP address and port.
13 *  In Socket Programming, IP address it self is not enough to distinguish an connection (stream, flow...), port # is also needed.
14 *  For PF_PACKET sockets, the address used is MAC address (HW address). So, we also put macaddr_ as a member variable.
15 */
16
17class Address
18{
19 
20 public:
21     
22  Address();
23  Address(char* hostname, short port);
24   
25  /**
26   * Check if an address has already been set or remain uninitialized
27   *
28   */ 
29  inline bool isSet() { return (hostname_[0] != '\0' && port_ >= 0); }
30  //inline bool isHWAddrSet() { return (macaddr_[0] != '\0');}
31 
32  inline void setPort(const short port){ port_ = port; }
33  inline short getPort(){ return port_; }
34
35  inline void setHostname(const char* hostname) { 
36    if (hostname == NULL) hostname_[0] = '\0'; else strcpy(hostname_, hostname); }
37 
38  inline char* getHostname() {return hostname_;} 
39  inline unsigned char* getHWAddr() { return macaddr_;} 
40  void setHWAddr(unsigned char* hwaddr); 
41  void setHWAddrFromColonFormat(const char* colon_seperated_macaddr);
42  char * convertHWAddrToColonFormat();
43  Address *clone();
44  /**
45   *Compare the two normal socket address is same or not
46   */
47  inline bool isSame(Address* addr)
48  {
49    if ( port_==  addr->getPort()) return false;
50    if ( strcmp( hostname_, addr->getHostname() ) == 0 ) return true;
51    return false;
52  } 
53  bool isSameMACAddr(Address* addr);
54
55  //const struct poptOption* getOptions();
56
57private:
58  char   hostname_[MAX_HOSTNAME_LENGTH]; ///< both hostname and ipaddress format (10.0.0.1) could be given as a string
59  short port_;  ///< port number for UDP or TCP (Transport layer)
60 
61  char * ipaddr_;  ///<optional use 
62  unsigned char   macaddr_[MAC_ADDR_LENGTH]; ///< optional use for Ethernet Socket
63 
64  // define a "=" operator, is it possible?
65  // yes  ..
66  /*
67   * do some coding later
68   * .....
69   */ 
70 
71};
72
73
74#endif
Note: See TracBrowser for help on using the browser.