1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. 14 * Copyright 2019 Joyent, Inc. 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 /* ARGSUSED */ 29 int 30 main(int argc, char *argv[]) 31 { 32 struct sockaddr_un sock; 33 int fd; 34 char *path; 35 size_t size; 36 if (argc != 2) { 37 fprintf(stderr, "usage: %s /path/to/socket\n", argv[0]); 38 exit(1); 39 } 40 path = argv[1]; 41 size = sizeof (sock.sun_path); 42 (void) strncpy(sock.sun_path, (char *)path, size - 1); 43 sock.sun_path[size - 1] = '\0'; 44 45 sock.sun_family = AF_UNIX; 46 if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) { 47 perror("socket"); 48 return (1); 49 } 50 if (bind(fd, (struct sockaddr *)&sock, sizeof (struct sockaddr_un))) { 51 perror("bind"); 52 return (1); 53 } 54 if (close(fd)) { 55 perror("close"); 56 return (1); 57 } 58 return (0); 59 } 60