For userspace, SUN_LEN() is an unnecessary BSD-ism. The kernel has to
accept sizeof(struct sockaddr_un) here, so do the simple, portable thing.
ok?
Philip Guenther
Index: nc/netcat.c
===================================================================
RCS file: /cvs/src/usr.bin/nc/netcat.c,v
retrieving revision 1.138
diff -u -p -r1.138 netcat.c
--- nc/netcat.c 13 Sep 2015 11:12:09 -0000 1.138
+++ nc/netcat.c 10 Oct 2015 23:30:53 -0000
@@ -57,11 +57,6 @@
#include <tls.h>
#include "atomicio.h"
-#ifndef SUN_LEN
-#define SUN_LEN(su) \
- (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
-#endif
-
#define PORT_MAX 65535
#define PORT_MAX_LEN 6
#define UNIX_DG_TMP_SOCKET_SIZE 19
@@ -646,7 +641,7 @@ unix_bind(char *path, int flags)
return (-1);
}
- if (bind(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
+ if (bind(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
close(s);
return (-1);
}
@@ -741,7 +736,7 @@ unix_connect(char *path)
errno = ENAMETOOLONG;
return (-1);
}
- if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
+ if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) {
close(s);
return (-1);
}
Index: tmux/client.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/client.c,v
retrieving revision 1.95
diff -u -p -r1.95 client.c
--- tmux/client.c 24 Sep 2015 12:06:20 -0000 1.95
+++ tmux/client.c 10 Oct 2015 23:30:54 -0000
@@ -119,7 +119,7 @@ retry:
fatal("socket failed");
log_debug("trying connect");
- if (connect(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1) {
+ if (connect(fd, (struct sockaddr *) &sa, sizeof(sa)) == -1) {
log_debug("connect failed: %s", strerror(errno));
if (errno != ECONNREFUSED && errno != ENOENT)
goto failed;
Index: tmux/server.c
===================================================================
RCS file: /cvs/src/usr.bin/tmux/server.c,v
retrieving revision 1.139
diff -u -p -r1.139 server.c
--- tmux/server.c 1 Sep 2015 10:01:56 -0000 1.139
+++ tmux/server.c 10 Oct 2015 23:30:55 -0000
@@ -145,7 +145,7 @@ server_create_socket(void)
return (-1);
mask = umask(S_IXUSR|S_IXGRP|S_IRWXO);
- if (bind(fd, (struct sockaddr *) &sa, SUN_LEN(&sa)) == -1)
+ if (bind(fd, (struct sockaddr *) &sa, sizeof(sa)) == -1)
return (-1);
umask(mask);