int drain_rcvbuf(int fd);
int make_unix_socket(int style, bool nonblock, bool passcred,
const char *bind_path, const char *connect_path);
+int get_unix_name_len(socklen_t sun_len);
#endif /* socket-util.h */
close(fd);
return -error;
}
+
+int
+get_unix_name_len(socklen_t sun_len)
+{
+ return (sun_len >= offsetof(struct sockaddr_un, sun_path)
+ ? sun_len - offsetof(struct sockaddr_un, sun_path)
+ : 0);
+}
struct vconn **vconnp)
{
const struct sockaddr_un *sun = (const struct sockaddr_un *) sa;
+ int name_len = get_unix_name_len(sa_len);
char name[128];
- if (sa_len >= offsetof(struct sockaddr_un, sun_path)) {
- snprintf(name, sizeof name, "unix:%.*s",
- (int) (sa_len - offsetof(struct sockaddr_un, sun_path)),
- sun->sun_path);
+ if (name_len > 0) {
+ snprintf(name, sizeof name, "unix:%.*s", name_len, sun->sun_path);
} else {
strcpy(name, "unix");
}