From owner-svn-src-all@freebsd.org Sat Oct 3 12:49:06 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 46F17A0C691; Sat, 3 Oct 2015 12:49:06 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 1C80A111E; Sat, 3 Oct 2015 12:49:06 +0000 (UTC) (envelope-from hrs@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t93Cn5sh099161; Sat, 3 Oct 2015 12:49:05 GMT (envelope-from hrs@FreeBSD.org) Received: (from hrs@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t93Cn5rW099160; Sat, 3 Oct 2015 12:49:05 GMT (envelope-from hrs@FreeBSD.org) Message-Id: <201510031249.t93Cn5rW099160@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hrs set sender to hrs@FreeBSD.org using -f From: Hiroki Sato Date: Sat, 3 Oct 2015 12:49:05 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r288602 - head/bin/cat X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 03 Oct 2015 12:49:06 -0000 Author: hrs Date: Sat Oct 3 12:49:05 2015 New Revision: 288602 URL: https://svnweb.freebsd.org/changeset/base/288602 Log: Use getaddrinfo() to fill struct sockaddr_un. It now supports SOCK_DGRAM and SOCK_SEQPACKET in addition to SOCK_STREAM. Modified: head/bin/cat/cat.c Modified: head/bin/cat/cat.c ============================================================================== --- head/bin/cat/cat.c Sat Oct 3 12:40:54 2015 (r288601) +++ head/bin/cat/cat.c Sat Oct 3 12:49:05 2015 (r288602) @@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #endif #include @@ -302,31 +303,39 @@ raw_cat(int rfd) static int udom_open(const char *path, int flags) { - struct sockaddr_un sou; - int fd; - unsigned int len; - - bzero(&sou, sizeof(sou)); + struct addrinfo hints, *res, *res0; + char rpath[PATH_MAX]; + int fd, error; /* - * Construct the unix domain socket address and attempt to connect + * Construct the unix domain socket address and attempt to connect. */ - fd = socket(AF_UNIX, SOCK_STREAM, 0); - if (fd >= 0) { - sou.sun_family = AF_UNIX; - if ((len = strlcpy(sou.sun_path, path, - sizeof(sou.sun_path))) >= sizeof(sou.sun_path)) { - close(fd); - errno = ENAMETOOLONG; + bzero(&hints, sizeof(hints)); + hints.ai_family = AF_LOCAL; + if (realpath(path, rpath) == NULL) + return (-1); + error = getaddrinfo(rpath, NULL, &hints, &res0); + if (error) { + warn("%s", gai_strerror(error)); + errno = EINVAL; + return (-1); + } + for (res = res0; res != NULL; res = res->ai_next) { + fd = socket(res->ai_family, res->ai_socktype, + res->ai_protocol); + if (fd < 0) { + freeaddrinfo(res0); return (-1); } - len = offsetof(struct sockaddr_un, sun_path[len+1]); - - if (connect(fd, (void *)&sou, len) < 0) { + error = connect(fd, res->ai_addr, res->ai_addrlen); + if (error == 0) + break; + else { close(fd); fd = -1; } } + freeaddrinfo(res0); /* * handle the open flags by shutting down appropriate directions