1 #include "ace/SPIPE_Addr.h"
2 #include "ace/OS_NS_string.h"
3 #include "ace/OS_NS_unistd.h"
4 #include "ace/os_include/sys/os_socket.h"
6 #if !defined (__ACE_INLINE__)
7 #include "ace/SPIPE_Addr.inl"
8 #endif /* __ACE_INLINE__ */
10 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
12 ACE_ALLOC_HOOK_DEFINE(ACE_SPIPE_Addr
)
15 ACE_SPIPE_Addr::dump () const
19 // Set a pointer to the address.
21 ACE_SPIPE_Addr::set_addr (const void *addr
, int len
)
23 ACE_TRACE ("ACE_SPIPE_Addr::set_addr");
25 this->ACE_Addr::base_set (AF_SPIPE
, len
);
26 ACE_OS::memcpy (&this->SPIPE_addr_
, addr
, len
);
29 // Return the address.
31 ACE_SPIPE_Addr::get_addr () const
33 return (void *) &this->SPIPE_addr_
;
36 // Do nothing constructor.
37 ACE_SPIPE_Addr::ACE_SPIPE_Addr ()
38 : ACE_Addr (AF_SPIPE
, sizeof this->SPIPE_addr_
)
40 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_
,
42 sizeof this->SPIPE_addr_
);
46 ACE_SPIPE_Addr::addr_to_string (ACE_TCHAR
*s
, size_t len
) const
49 this->SPIPE_addr_
.rendezvous_
,
54 // Transform the string into the current addressing format.
56 ACE_SPIPE_Addr::string_to_addr (const ACE_TCHAR
*addr
)
58 return this->set (addr
);
62 ACE_SPIPE_Addr::set (const ACE_SPIPE_Addr
&sa
)
64 this->base_set (sa
.get_type (), sa
.get_size ());
66 if (sa
.get_type () == AF_ANY
)
67 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_
,
69 sizeof this->SPIPE_addr_
);
71 (void) ACE_OS::memcpy ((void *) &this->SPIPE_addr_
, (void *)
78 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_SPIPE_Addr
&sa
)
79 : ACE_Addr (AF_SPIPE
, sizeof this->SPIPE_addr_
)
85 ACE_SPIPE_Addr::set (const ACE_TCHAR
*addr
,
89 int len
= sizeof (this->SPIPE_addr_
.uid_
);
90 len
+= sizeof (this->SPIPE_addr_
.gid_
);
92 #if defined (ACE_WIN32)
93 const ACE_TCHAR
*colonp
= ACE_OS::strchr (addr
, ':');
94 ACE_TCHAR temp
[BUFSIZ
];
96 if (colonp
== 0) // Assume it's a local name.
98 ACE_OS::strcpy (temp
, ACE_TEXT ( "\\\\.\\pipe\\"));
99 ACE_OS::strcat (temp
, addr
);
103 if (ACE_OS::strncmp (addr
,
104 ACE_TEXT ("localhost"),
105 ACE_OS::strlen ("localhost")) == 0)
106 // change "localhost" to "."
107 ACE_OS::strcpy (temp
, ACE_TEXT ("\\\\."));
110 ACE_OS::strcpy (temp
, ACE_TEXT ("\\\\"));
114 // We need to allocate a duplicate so that we can write a
115 // NUL character into it.
116 ACE_ALLOCATOR_RETURN (t
, ACE_OS::strdup (addr
), -1);
118 t
[colonp
- addr
] = ACE_TEXT ('\0');
119 ACE_OS::strcat (temp
, t
);
124 ACE_OS::strcat (temp
, ACE_TEXT ("\\pipe\\"));
125 ACE_OS::strcat (temp
, colonp
+ 1);
127 len
+= static_cast<int> (ACE_OS::strlen (temp
));
128 this->ACE_Addr::base_set (AF_SPIPE
, len
);
130 ACE_OS::strcpy (this->SPIPE_addr_
.rendezvous_
, temp
);
132 this->ACE_Addr::base_set (AF_SPIPE
,
133 ACE_OS::strlen (addr
) + 1 + len
);
134 ACE_OS::strsncpy (this->SPIPE_addr_
.rendezvous_
,
136 sizeof this->SPIPE_addr_
.rendezvous_
);
137 #endif /* ACE_WIN32 */
138 this->SPIPE_addr_
.gid_
= gid
== 0 ? ACE_OS::getgid () : gid
;
139 this->SPIPE_addr_
.uid_
= uid
== 0 ? ACE_OS::getuid () : uid
;
143 // Create a ACE_Addr from a ACE_SPIPE pathname.
144 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_TCHAR
*addr
,
147 : ACE_Addr (AF_SPIPE
, sizeof this->SPIPE_addr_
)
149 this->set (addr
, gid
, uid
);
152 ACE_END_VERSIONED_NAMESPACE_DECL