1 // SPDX-License-Identifier: CDDL-1.0 2 /* 3 * This file and its contents are supplied under the terms of the 4 * Common Development and Distribution License ("CDDL"), version 1.0. 5 * You may only use this file in accordance with the terms of version 6 * 1.0 of the CDDL. 7 * 8 * A full copy of the text of the CDDL should have accompanied this 9 * source. A copy of the CDDL is also available via the Internet at 10 * http://www.illumos.org/license/CDDL. 11 */ 12 13 /* 14 * Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. 15 */ 16 17 #include <fcntl.h> 18 #include <sys/un.h> 19 #include <sys/socket.h> 20 #include <sys/stat.h> 21 #include <sys/types.h> 22 #include <unistd.h> 23 #include <errno.h> 24 #include <stdio.h> 25 #include <stdlib.h> 26 #include <string.h> 27 28 int 29 main(int argc, char *argv[]) 30 { 31 struct sockaddr_un sock; 32 int fd; 33 char *path; 34 size_t size; 35 if (argc != 2) { 36 fprintf(stderr, "usage: %s /path/to/socket\n", argv[0]); 37 exit(1); 38 } 39 path = argv[1]; 40 size = sizeof (sock.sun_path); 41 (void) snprintf(sock.sun_path, size, "%s", path); 42 43 sock.sun_family = AF_UNIX; 44 if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) { 45 perror("socket"); 46 return (1); 47 } 48 if (bind(fd, (struct sockaddr *)&sock, sizeof (struct sockaddr_un))) { 49 perror("bind"); 50 return (1); 51 } 52 if (close(fd)) { 53 perror("close"); 54 return (1); 55 } 56 return (0); 57 } 58