32 #include <sys/socket.h>
36 #include <system_error>
46 using namespace scc::net;
50 m_addr->sun_family = AF_UNIX;
51 m_addr->sun_path[0] = 0;
73 if (a->sa_family == AF_UNIX)
75 memcpy(m_addr, a,
sizeof(sockaddr_un));
81 strcpy(m_addr->sun_path, b.m_addr->sun_path);
86 strcpy(m_addr->sun_path, b.m_addr->sun_path);
92 strcpy(m_addr->sun_path, b.m_addr->sun_path);
98 strcpy(m_addr->sun_path, b.m_addr->sun_path);
103 UnixAddr::operator
const sockaddr*()
const
105 return reinterpret_cast<const sockaddr*
>(m_addr);
108 UnixAddr::operator sockaddr*()
110 return reinterpret_cast<sockaddr*
>(m_addr);
115 return sizeof(sockaddr_un);
125 if (h.size() <
sizeof(m_addr->sun_path))
127 strcpy(m_addr->sun_path, h.c_str());
131 strncpy(m_addr->sun_path, h.c_str(),
sizeof(m_addr->sun_path)-1);
132 m_addr->sun_path[
sizeof(m_addr->sun_path)-1] = 0;
138 return std::string(m_addr->sun_path);
143 return os.write(sa.
str().c_str(), sa.
str().size());
149 s <<
"unix domain name=" <<
host();
153 UnixTcpSock::UnixTcpSock() :
TcpSocket(AF_UNIX, SOCK_STREAM, 0) { }
155 UnixTcpSock::UnixTcpSock(
int fd) :
TcpSocket(fd) { }
159 SocketBase::reset(AF_UNIX, SOCK_STREAM, 0);
175 std::stringstream st;
177 throw std::system_error(ec, st.str());
188 std::stringstream st;
189 st <<
"accept(peer)";
190 throw std::system_error(ec, st.str());
195 UnixUdpSock::UnixUdpSock() :
UdpSocket(AF_UNIX, SOCK_DGRAM, 0) { }
199 SocketBase::reset(AF_UNIX, SOCK_DGRAM, 0);
int accept(sockaddr *, int len, std::error_code &) noexcept
Accept a connection.
A unix domain address, which is a file of type "socket.".
UnixAddr()
IPv6 SocketBase address, initialized with "any" address.
virtual std::string host() const
Get host name.
virtual std::string str() const
Descriptive string for socket address.
UnixAddr & operator=(const UnixAddr &)
Copy assign.
virtual unsigned len() const
Length of socket address.
Unix domain tcp (stream) socket.
UnixTcpSock accept()
Accept a connection from an anonymous peer.
virtual void reset()
Reset the socket.
UnixAddr get_addr()
Get the socket address.
virtual void reset()
Reset the socket.
UnixAddr get_addr()
Get the socket address.
std::ostream & operator<<(std::ostream &, const scc::net::InetAddr &)
Print the socket address details to an output stream.
Unix domain tcp and udp networking.