3 //==========================================================================
7 * $Id: MEM_Addr.h 80826 2008-03-04 14:51:23Z wotte $
9 * @author Nanbor Wang <nanbor@cs.wustl.edu>
11 //==========================================================================
14 #ifndef ACE_MEM_ADDR_H
15 #define ACE_MEM_ADDR_H
16 #include /**/ "ace/pre.h"
18 #include /**/ "ace/ACE_export.h"
20 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 #endif /* ACE_LACKS_PRAGMA_ONCE */
24 #if (ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1)
26 #include "ace/INET_Addr.h"
28 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
33 * @brief Defines a C++ wrapper facade for the shared memory transport
34 * address family format.
36 class ACE_Export ACE_MEM_Addr
: public ACE_Addr
39 // = Initialization methods.
40 /// Default constructor.
44 ACE_MEM_Addr (const ACE_MEM_Addr
&);
46 /// Creates an ACE_MEM_Addr from a @a port_number
47 ACE_MEM_Addr (u_short port_number
);
49 /// Creates an ACE_MEM_Addr from a @a port_name.
50 explicit ACE_MEM_Addr (const ACE_TCHAR port_name
[]);
55 // = Direct initialization methods.
57 /// Default initialization routine.
58 int initialize_local (u_short port
);
60 /// Check if @a sap designates an endpoint on the same host.
61 int same_host (const ACE_INET_Addr
& sap
);
63 // These methods are useful after the object has been constructed.
66 * Initializes an ACE_MEM_Addr from a @a port_number. If @a encode
67 * is enabled then @a port_number is converted into network byte order,
68 * otherwise it is assumed to be in network byte order already and
69 * are passed straight through.
71 int set (u_short port_number
, int encode
= 1);
73 /// Uses <getservbyname> to initialize an ACE_MEM_Addr from a
74 /// <port_name>, the remote <host_name>, and the <protocol>.
75 int set (const ACE_TCHAR port_name
[]);
77 /// Return a pointer to the underlying network address.
78 virtual void *get_addr (void) const;
80 /// Set a pointer to the address.
81 virtual void set_addr (void *, int len
);
83 /// Transform the external ACE_MEM_Addr address into string
85 virtual int addr_to_string (ACE_TCHAR buffer
[],
87 int ipaddr_format
= 1) const;
89 /// Initializes the external ACE_MEM_Addr from the @a address.
90 virtual int string_to_addr (const ACE_TCHAR address
[]);
92 /// Sets the port number.
93 void set_port_number (u_short
,
96 /// Return the port number, converting it into host byte order.
97 u_short
get_port_number (void) const;
99 /// Return the character representation of the hostname.
100 int get_host_name (ACE_TCHAR hostname
[],
101 size_t hostnamelen
) const;
104 * Return the character representation of the hostname (this version
105 * is non-reentrant since it returns a pointer to a static data
108 const char *get_host_name (void) const;
110 /// Return the "dotted decimal" external address.
111 const char *get_host_addr (void) const;
113 /// Return the 4-byte external IP address, converting it into host byte
115 ACE_UINT32
get_ip_address (void) const;
117 const ACE_INET_Addr
&get_remote_addr (void) const;
118 const ACE_INET_Addr
&get_local_addr (void) const;
120 /// Compare two addresses for equality. The addresses are considered
121 /// equal if they contain the same IP address and port number.
122 bool operator == (const ACE_MEM_Addr
&SAP
) const;
123 bool operator == (const ACE_INET_Addr
&SAP
) const;
125 /// Compare two addresses for inequality.
126 bool operator != (const ACE_MEM_Addr
&SAP
) const;
127 bool operator != (const ACE_INET_Addr
&SAP
) const;
129 /// Computes and returns hash value.
130 virtual u_long
hash (void) const;
132 /// Dump the state of an object.
133 void dump (void) const;
135 /// Declare the dynamic allocation hooks.
136 ACE_ALLOC_HOOK_DECLARE
;
139 /// External INET addr used for identifying host.
140 ACE_INET_Addr external_
;
142 /// Internal INET addr for accepting/connecting.
143 ACE_INET_Addr internal_
;
146 ACE_END_VERSIONED_NAMESPACE_DECL
148 #if defined (__ACE_INLINE__)
149 #include "ace/MEM_Addr.inl"
150 #endif /* __ACE_INLINE__ */
152 #endif /* ACE_HAS_POSITION_INDEPENDENT_POINTERS == 1 */
154 #include /**/ "ace/post.h"
155 #endif /* ACE_MEM_ADDR_H */