1 // $Id: UNIX_Addr.cpp 80826 2008-03-04 14:51:23Z wotte $
3 #include "ace/UNIX_Addr.h"
5 ACE_RCSID(ace
, UNIX_Addr
, "$Id: UNIX_Addr.cpp 80826 2008-03-04 14:51:23Z wotte $")
7 #if !defined (ACE_LACKS_UNIX_DOMAIN_SOCKETS)
9 #if !defined (__ACE_INLINE__)
10 #include "ace/UNIX_Addr.inl"
11 #endif /* __ACE_INLINE__ */
13 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
15 ACE_ALLOC_HOOK_DEFINE(ACE_UNIX_Addr
)
17 // Set a pointer to the address.
19 ACE_UNIX_Addr::set_addr (void *addr
, int len
)
21 ACE_TRACE ("ACE_UNIX_Addr::set_addr");
23 this->ACE_Addr::base_set (AF_UNIX
, len
);
24 ACE_OS::memcpy ((void *) &this->unix_addr_
,
29 // Return a pointer to the underlying address.
32 ACE_UNIX_Addr::get_addr (void) const
34 return (void *) &this->unix_addr_
;
37 // Transform the string into the current addressing format.
40 ACE_UNIX_Addr::string_to_addr (const char addr
[])
42 ACE_OS::strsncpy (this->unix_addr_
.sun_path
, addr
,
43 sizeof this->unix_addr_
.sun_path
);
47 // Transform the current address into string format.
50 ACE_UNIX_Addr::addr_to_string (ACE_TCHAR s
[], size_t len
) const
53 ACE_TEXT_CHAR_TO_TCHAR (this->unix_addr_
.sun_path
),
59 ACE_UNIX_Addr::hash (void) const
61 return ACE::hash_pjw (this->unix_addr_
.sun_path
);
65 ACE_UNIX_Addr::dump (void) const
67 #if defined (ACE_HAS_DUMP)
68 #endif /* ACE_HAS_DUMP */
71 // Do nothing constructor.
73 ACE_UNIX_Addr::ACE_UNIX_Addr (void)
74 : ACE_Addr (AF_UNIX
, sizeof this->unix_addr_
)
76 (void) ACE_OS::memset ((void *) &this->unix_addr_
,
78 sizeof this->unix_addr_
);
80 this->unix_addr_
.sun_family
= AF_UNIX
;
84 ACE_UNIX_Addr::set (const ACE_UNIX_Addr
&sa
)
86 if (sa
.get_type () == AF_ANY
)
87 (void) ACE_OS::memset ((void *) &this->unix_addr_
,
89 sizeof this->unix_addr_
);
91 ACE_OS::strcpy (this->unix_addr_
.sun_path
,
92 sa
.unix_addr_
.sun_path
);
94 this->unix_addr_
.sun_family
= AF_UNIX
;
95 this->base_set (sa
.get_type (), sa
.get_size ());
102 ACE_UNIX_Addr::ACE_UNIX_Addr (const ACE_UNIX_Addr
&sa
)
103 : ACE_Addr (AF_UNIX
, sa
.get_size ())
109 ACE_UNIX_Addr::set (const sockaddr_un
*un
, int len
)
111 (void) ACE_OS::memset ((void *) &this->unix_addr_
, 0,
112 sizeof this->unix_addr_
);
113 this->unix_addr_
.sun_family
= AF_UNIX
;
114 ACE_OS::strcpy (this->unix_addr_
.sun_path
, un
->sun_path
);
115 this->base_set (AF_UNIX
, len
);
119 ACE_UNIX_Addr::ACE_UNIX_Addr (const sockaddr_un
*un
, int len
)
125 ACE_UNIX_Addr::set (const char rendezvous_point
[])
127 (void) ACE_OS::memset ((void *) &this->unix_addr_
,
129 sizeof this->unix_addr_
);
130 this->unix_addr_
.sun_family
= AF_UNIX
;
131 (void) ACE_OS::strsncpy (this->unix_addr_
.sun_path
,
133 sizeof this->unix_addr_
.sun_path
);
135 this->ACE_Addr::base_set (AF_UNIX
,
136 sizeof this->unix_addr_
-
137 sizeof (this->unix_addr_
.sun_path
) +
138 ACE_OS::strlen (this->unix_addr_
.sun_path
));
142 // Create a ACE_Addr from a UNIX pathname.
144 ACE_UNIX_Addr::ACE_UNIX_Addr (const char rendezvous_point
[])
146 this->set (rendezvous_point
);
149 ACE_END_VERSIONED_NAMESPACE_DECL
151 #endif /* ACE_LACKS_UNIX_DOMAIN_SOCKETS */