1 // SPDX-License-Identifier: GPL-2.0+
2 /* Create an AF_UNIX socket.
3 * Copyright (C) 2017 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
15 #include <sys/types.h>
17 #include <sys/socket.h>
20 #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
22 int main(int argc, char *argv[])
24 struct sockaddr_un sun;
30 fprintf(stderr, "Format: %s <socketpath>\n", argv[0]);
34 max = sizeof(sun.sun_path);
35 len = strlen(argv[1]);
37 fprintf(stderr, "Filename too long (max %zu)\n", max);
41 fd = socket(AF_UNIX, SOCK_DGRAM, 0);
47 memset(&sun, 0, sizeof(sun));
48 sun.sun_family = AF_UNIX;
49 strcpy(sun.sun_path, argv[1]);
50 if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) {
55 if (stat(argv[1], &st)) {
56 fprintf(stderr, "Couldn't stat socket after creation: %m\n");