aboutsummaryrefslogtreecommitdiffstats
path: root/mksocket.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2017-10-19 19:07:43 +0200
committerMattias Andrée <maandree@kth.se>2017-10-19 19:07:43 +0200
commitf7fedd90fb3f7d3110f2ff976639c7f8ec51fbad (patch)
treeb1099b364a4d3a1f90f8178b7a192c931a63bc29 /mksocket.c
parentSimplify (diff)
downloadxtest-f7fedd90fb3f7d3110f2ff976639c7f8ec51fbad.tar.gz
xtest-f7fedd90fb3f7d3110f2ff976639c7f8ec51fbad.tar.bz2
xtest-f7fedd90fb3f7d3110f2ff976639c7f8ec51fbad.tar.xz
Add test
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'mksocket.c')
-rw-r--r--mksocket.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/mksocket.c b/mksocket.c
new file mode 100644
index 0000000..0cf6e8d
--- /dev/null
+++ b/mksocket.c
@@ -0,0 +1,37 @@
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+int
+main(int argc, char *argv[])
+{
+ struct sockaddr_un addr;
+ int fd;
+
+ if (argc != 2)
+ abort();
+ fd = socket(PF_UNIX, SOCK_STREAM, 0);
+ if (fd < 0) {
+ perror("mksocket");
+ return 1;
+ }
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_UNIX;
+ if (strlen(argv[1]) >= sizeof(addr.sun_path)) {
+ errno = ENAMETOOLONG;
+ perror("mksocket");
+ return 1;
+ }
+ strcpy(addr.sun_path, argv[1]);
+ if (bind(fd, (void *)&addr, (socklen_t)sizeof(addr))) {
+ perror("mksocket");
+ return 1;
+ }
+ close(fd);
+
+ return 0;
+}