Path: blob/main/sys/contrib/openzfs/tests/zfs-tests/cmd/zfs_diff-socket.c
48529 views
// SPDX-License-Identifier: CDDL-1.01/*2* This file and its contents are supplied under the terms of the3* Common Development and Distribution License ("CDDL"), version 1.0.4* You may only use this file in accordance with the terms of version5* 1.0 of the CDDL.6*7* A full copy of the text of the CDDL should have accompanied this8* source. A copy of the CDDL is also available via the Internet at9* http://www.illumos.org/license/CDDL.10*/1112/*13* Copyright 2017, loli10K <[email protected]>. All rights reserved.14*/1516#include <fcntl.h>17#include <sys/un.h>18#include <sys/socket.h>19#include <sys/stat.h>20#include <sys/types.h>21#include <unistd.h>22#include <errno.h>23#include <stdio.h>24#include <stdlib.h>25#include <string.h>2627int28main(int argc, char *argv[])29{30struct sockaddr_un sock;31int fd;32char *path;33size_t size;34if (argc != 2) {35fprintf(stderr, "usage: %s /path/to/socket\n", argv[0]);36exit(1);37}38path = argv[1];39size = sizeof (sock.sun_path);40(void) snprintf(sock.sun_path, size, "%s", path);4142sock.sun_family = AF_UNIX;43if ((fd = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) {44perror("socket");45return (1);46}47if (bind(fd, (struct sockaddr *)&sock, sizeof (struct sockaddr_un))) {48perror("bind");49return (1);50}51if (close(fd)) {52perror("close");53return (1);54}55return (0);56}575859