struct sockaddr_un *addr;
socklen_t len;
- /* For debugging only, will be removed */
- uint64_t magic;
- static constexpr uint64_t kMagic = 0x1234faceb00c;
-
socklen_t pathLength() const {
return socklen_t(len - offsetof(struct sockaddr_un, sun_path));
}
void init() {
- addr = new sockaddr_un;
- magic = kMagic;
+ addr = new struct sockaddr_un;
addr->sun_family = AF_UNIX;
len = 0;
}
void init(const ExternalUnixAddr &other) {
- addr = new sockaddr_un;
- magic = kMagic;
+ addr = new struct sockaddr_un;
len = other.len;
memcpy(addr, other.addr, size_t(len));
- // Fill the rest with 0s, just for safety
- memset(reinterpret_cast<char*>(addr) + len, 0,
- sizeof(struct sockaddr_un) - len);
}
void copy(const ExternalUnixAddr &other) {
- CHECK(magic == kMagic);
len = other.len;
memcpy(addr, other.addr, size_t(len));
}
void free() {
- CHECK(magic == kMagic);
delete addr;
- magic = 0;
}
};