48b4c725
Peter M. Groen
Setting up Socket-pp
|
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
constexpr sa_family_t unix_address::ADDRESS_FAMILY;
constexpr size_t unix_address::MAX_PATH_NAME;
// --------------------------------------------------------------------------
unix_address::unix_address(const string& path)
{
addr_.sun_family = ADDRESS_FAMILY;
::strncpy(addr_.sun_path, path.c_str(), MAX_PATH_NAME);
}
unix_address::unix_address(const sockaddr& addr)
{
auto domain = addr.sa_family;
if (domain != AF_UNIX)
throw std::invalid_argument("Not a UNIX-domain address");
// TODO: We should check the path, or at least see that it has
// proper NUL termination.
std::memcpy(&addr_, &addr, sizeof(sockaddr));
}
// --------------------------------------------------------------------------
ostream& operator<<(ostream& os, const unix_address& addr)
{
os << "unix:" << addr.path();
return os;
}
|