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 (void) const
17 #if defined (ACE_HAS_DUMP)
18 #endif /* ACE_HAS_DUMP */
21 // Set a pointer to the address.
23 ACE_SPIPE_Addr::set_addr (const void *addr
, int len
)
25 ACE_TRACE ("ACE_SPIPE_Addr::set_addr");
27 this->ACE_Addr::base_set (AF_SPIPE
, len
);
28 ACE_OS::memcpy (&this->SPIPE_addr_
, addr
, len
);
31 // Return the address.
34 ACE_SPIPE_Addr::get_addr (void) const
36 return (void *) &this->SPIPE_addr_
;
40 // Do nothing constructor.
42 ACE_SPIPE_Addr::ACE_SPIPE_Addr (void)
43 : ACE_Addr (AF_SPIPE
, sizeof this->SPIPE_addr_
)
45 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_
,
47 sizeof this->SPIPE_addr_
);
51 ACE_SPIPE_Addr::addr_to_string (ACE_TCHAR
*s
, size_t len
) const
54 this->SPIPE_addr_
.rendezvous_
,
59 // Transform the string into the current addressing format.
62 ACE_SPIPE_Addr::string_to_addr (const ACE_TCHAR
*addr
)
64 return this->set (addr
);
68 ACE_SPIPE_Addr::set (const ACE_SPIPE_Addr
&sa
)
70 this->base_set (sa
.get_type (), sa
.get_size ());
72 if (sa
.get_type () == AF_ANY
)
73 (void) ACE_OS::memset ((void *) &this->SPIPE_addr_
,
75 sizeof this->SPIPE_addr_
);
77 (void) ACE_OS::memcpy ((void *) &this->SPIPE_addr_
, (void *)
85 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_SPIPE_Addr
&sa
)
86 : ACE_Addr (AF_SPIPE
, sizeof this->SPIPE_addr_
)
92 ACE_SPIPE_Addr::set (const ACE_TCHAR
*addr
,
96 int len
= sizeof (this->SPIPE_addr_
.uid_
);
97 len
+= sizeof (this->SPIPE_addr_
.gid_
);
99 #if defined (ACE_WIN32)
100 const ACE_TCHAR
*colonp
= ACE_OS::strchr (addr
, ':');
101 ACE_TCHAR temp
[BUFSIZ
];
103 if (colonp
== 0) // Assume it's a local name.
105 ACE_OS::strcpy (temp
, ACE_TEXT ( "\\\\.\\pipe\\"));
106 ACE_OS::strcat (temp
, addr
);
111 if (ACE_OS::strncmp (addr
,
112 ACE_TEXT ("localhost"),
113 ACE_OS::strlen ("localhost")) == 0)
114 // change "localhost" to "."
115 ACE_OS::strcpy (temp
, ACE_TEXT ("\\\\."));
118 ACE_OS::strcpy (temp
, ACE_TEXT ("\\\\"));
122 // We need to allocate a duplicate so that we can write a
123 // NUL character into it.
124 ACE_ALLOCATOR_RETURN (t
, ACE_OS::strdup (addr
), -1);
126 t
[colonp
- addr
] = ACE_TEXT ('\0');
127 ACE_OS::strcat (temp
, t
);
132 ACE_OS::strcat (temp
, ACE_TEXT ("\\pipe\\"));
133 ACE_OS::strcat (temp
, colonp
+ 1);
135 len
+= static_cast<int> (ACE_OS::strlen (temp
));
136 this->ACE_Addr::base_set (AF_SPIPE
, len
);
138 ACE_OS::strcpy (this->SPIPE_addr_
.rendezvous_
, temp
);
140 this->ACE_Addr::base_set (AF_SPIPE
,
141 ACE_OS::strlen (addr
) + 1 + len
);
142 ACE_OS::strsncpy (this->SPIPE_addr_
.rendezvous_
,
144 sizeof this->SPIPE_addr_
.rendezvous_
);
145 #endif /* ACE_WIN32 */
146 this->SPIPE_addr_
.gid_
= gid
== 0 ? ACE_OS::getgid () : gid
;
147 this->SPIPE_addr_
.uid_
= uid
== 0 ? ACE_OS::getuid () : uid
;
151 // Create a ACE_Addr from a ACE_SPIPE pathname.
153 ACE_SPIPE_Addr::ACE_SPIPE_Addr (const ACE_TCHAR
*addr
,
156 : ACE_Addr (AF_SPIPE
, sizeof this->SPIPE_addr_
)
158 this->set (addr
, gid
, uid
);
161 ACE_END_VERSIONED_NAMESPACE_DECL