#include <sys/socket.h>
#include <sys/un.h>
#include <netinet/in.h>
-#include <features.h>
#include <netdb.h>
#include <cstddef>
#include <iostream>
#include <string>
#include <folly/IPAddress.h>
+#include <folly/Portability.h>
namespace folly {
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 len - offsetof(struct sockaddr_un, sun_path);
}
void init() {
addr = new sockaddr_un;
+ magic = kMagic;
addr->sun_family = AF_UNIX;
len = 0;
}
void init(const ExternalUnixAddr &other) {
addr = new sockaddr_un;
+ magic = kMagic;
len = other.len;
memcpy(addr, other.addr, len);
// Fill the rest with 0s, just for safety
sizeof(struct sockaddr_un) - len);
}
void copy(const ExternalUnixAddr &other) {
+ CHECK(magic == kMagic);
len = other.len;
memcpy(addr, other.addr, len);
}
void free() {
+ CHECK(magic == kMagic);
delete addr;
+ magic = 0;
}
};