3 //==========================================================================
7 * @author Nanbor Wang <nanbor@cs.wustl.edu>
9 //==========================================================================
12 #ifndef ACE_MEM_ADDR_H
13 #define ACE_MEM_ADDR_H
14 #include /**/ "ace/pre.h"
16 #include /**/ "ace/ACE_export.h"
18 #if !defined (ACE_LACKS_PRAGMA_ONCE)
20 #endif /* ACE_LACKS_PRAGMA_ONCE */
22 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
24 #include "ace/INET_Addr.h"
26 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
31 * @brief Defines a C++ wrapper facade for the shared memory transport
32 * address family format.
34 class ACE_Export ACE_MEM_Addr
: public ACE_Addr
37 /// Default constructor.
41 ACE_MEM_Addr (const ACE_MEM_Addr
&);
43 /// Creates an ACE_MEM_Addr from a @a port_number
44 ACE_MEM_Addr (u_short port_number
);
46 /// Creates an ACE_MEM_Addr from a @a port_name.
47 explicit ACE_MEM_Addr (const ACE_TCHAR port_name
[]);
52 // = Direct initialization methods.
54 /// Default initialization routine.
55 int initialize_local (u_short port
);
57 /// Check if @a sap designates an endpoint on the same host.
58 int same_host (const ACE_INET_Addr
& sap
);
60 // These methods are useful after the object has been constructed.
63 * Initializes an ACE_MEM_Addr from a @a port_number. If @a encode
64 * is enabled then @a port_number is converted into network byte order,
65 * otherwise it is assumed to be in network byte order already and
66 * are passed straight through.
68 int set (u_short port_number
, int encode
= 1);
70 /// Uses <getservbyname> to initialize an ACE_MEM_Addr from a
71 /// @a port_name, the remote <host_name>, and the <protocol>.
72 int set (const ACE_TCHAR port_name
[]);
74 /// Return a pointer to the underlying network address.
75 virtual void *get_addr (void) const;
77 /// Set a pointer to the address.
78 virtual void set_addr (const void *, int len
);
80 /// Transform the external ACE_MEM_Addr address into string
82 virtual int addr_to_string (ACE_TCHAR buffer
[],
84 int ipaddr_format
= 1) const;
86 /// Initializes the external ACE_MEM_Addr from the @a address.
87 virtual int string_to_addr (const ACE_TCHAR address
[]);
89 /// Sets the port number.
90 void set_port_number (u_short
,
93 /// Return the port number, converting it into host byte order.
94 u_short
get_port_number (void) const;
96 /// Return the character representation of the hostname.
97 int get_host_name (ACE_TCHAR hostname
[],
98 size_t hostnamelen
) const;
101 * Return the character representation of the hostname (this version
102 * is non-reentrant since it returns a pointer to a static data
105 const char *get_host_name (void) const;
108 * Return the "dotted decimal" external Internet address representation of
109 * the hostname storing it in the @a addr (which is assumed to be
110 * @a addr_size bytes long). This version is reentrant.
112 const char *get_host_addr (char *addr
, int addr_size
) const;
115 * Return the "dotted decimal" external Internet address representation of
116 * the hostname. This version is non-reentrant since it returns a
117 * pointer to a static data area. You should therefore either
118 * (1) do a "deep copy" of the address returned by get_host_addr(), e.g.,
119 * using strdup() or (2) use the "reentrant" version of
120 * get_host_addr() described above.
122 const char *get_host_addr (void) const;
124 /// Return the 4-byte external IP address, converting it into host byte
126 ACE_UINT32
get_ip_address (void) const;
128 const ACE_INET_Addr
&get_remote_addr (void) const;
129 const ACE_INET_Addr
&get_local_addr (void) const;
131 /// Compare two addresses for equality. The addresses are considered
132 /// equal if they contain the same IP address and port number.
133 bool operator == (const ACE_MEM_Addr
&SAP
) const;
134 bool operator == (const ACE_INET_Addr
&SAP
) const;
136 /// Compare two addresses for inequality.
137 bool operator != (const ACE_MEM_Addr
&SAP
) const;
138 bool operator != (const ACE_INET_Addr
&SAP
) const;
140 /// Computes and returns hash value.
141 virtual u_long
hash (void) const;
143 /// Dump the state of an object.
144 void dump (void) const;
146 /// Declare the dynamic allocation hooks.
147 ACE_ALLOC_HOOK_DECLARE
;
150 /// External INET addr used for identifying host.
151 ACE_INET_Addr external_
;
153 /// Internal INET addr for accepting/connecting.
154 ACE_INET_Addr internal_
;
157 ACE_END_VERSIONED_NAMESPACE_DECL
159 #if defined (__ACE_INLINE__)
160 #include "ace/MEM_Addr.inl"
161 #endif /* __ACE_INLINE__ */
163 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
165 #include /**/ "ace/post.h"
166 #endif /* ACE_MEM_ADDR_H */