FreeBSD/contrib/netcat/netcat.c
/*
 * unix_connect()
 * Returns a socket connected to a local unix socket. Returns -1 on failure.
 */
unix_connect()
Returns a socket connected to a local unix socket. Returns -1 on failure.
unix_connect () Returns a socket connected to a local unix socket . Returns - 1 on failure .
int
unix_connect(char *path)
{
	struct sockaddr_un sun;
	int s;
	if (uflag) {
		if ((s = unix_bind(unix_dg_tmp_socket)) < 0)
			return (-1);
	} else {
		if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
			return (-1);
	}
	(void)fcntl(s, F_SETFD, FD_CLOEXEC);
	memset(&sun, 0, sizeof(struct sockaddr_un));
	sun.sun_family = AF_UNIX;
	if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >=
	    sizeof(sun.sun_path)) {
		close(s);
		errno = ENAMETOOLONG;
		return (-1);
	}
	if (connect(s, (struct sockaddr *)&sun, SUN_LEN(&sun)) < 0) {
		close(s);
		return (-1);
	}
	return (s);
}
int unix_connect ( char * path ) { struct sockaddr_un sun ; int s ; if ( uflag ) { if ( ( s = unix_bind ( unix_dg_tmp_socket ) ) < 0 ) return ( -1 ) ; } else { if ( ( s = socket ( AF_UNIX , SOCK_STREAM , 0 ) ) < 0 ) return ( -1 ) ; } ( void ) fcntl ( s , F_SETFD , FD_CLOEXEC ) ; memset ( & sun , 0 , sizeof ( struct sockaddr_un ) ) ; sun . sun_family = AF_UNIX ; if ( strlcpy ( sun . sun_path , path , sizeof ( sun . sun_path ) ) >= sizeof ( sun . sun_path ) ) { close ( s ) ; errno = ENAMETOOLONG ; return ( -1 ) ; } if ( connect ( s , ( struct sockaddr * ) & sun , SUN_LEN ( & sun ) ) < 0 ) { close ( s ) ; return ( -1 ) ; } return ( s ) ; }
unix_connect()
 Returns a socket connected to a local unix socket.
unix_connect () Returns a socket connected to a local unix socket .