version 1.143, 2015/11/13 18:13:13 |
version 1.144, 2015/11/23 01:23:56 |
|
|
int |
int |
unix_bind(char *path, int flags) |
unix_bind(char *path, int flags) |
{ |
{ |
struct sockaddr_un sun; |
struct sockaddr_un s_un; |
int s; |
int s; |
|
|
/* Create unix domain socket. */ |
/* Create unix domain socket. */ |
|
|
0)) < 0) |
0)) < 0) |
return (-1); |
return (-1); |
|
|
memset(&sun, 0, sizeof(struct sockaddr_un)); |
memset(&s_un, 0, sizeof(struct sockaddr_un)); |
sun.sun_family = AF_UNIX; |
s_un.sun_family = AF_UNIX; |
|
|
if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= |
if (strlcpy(s_un.sun_path, path, sizeof(s_un.sun_path)) >= |
sizeof(sun.sun_path)) { |
sizeof(s_un.sun_path)) { |
close(s); |
close(s); |
errno = ENAMETOOLONG; |
errno = ENAMETOOLONG; |
return (-1); |
return (-1); |
} |
} |
|
|
if (bind(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) { |
if (bind(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) { |
close(s); |
close(s); |
return (-1); |
return (-1); |
} |
} |
|
|
int |
int |
unix_connect(char *path) |
unix_connect(char *path) |
{ |
{ |
struct sockaddr_un sun; |
struct sockaddr_un s_un; |
int s; |
int s; |
|
|
if (uflag) { |
if (uflag) { |
|
|
return (-1); |
return (-1); |
} |
} |
|
|
memset(&sun, 0, sizeof(struct sockaddr_un)); |
memset(&s_un, 0, sizeof(struct sockaddr_un)); |
sun.sun_family = AF_UNIX; |
s_un.sun_family = AF_UNIX; |
|
|
if (strlcpy(sun.sun_path, path, sizeof(sun.sun_path)) >= |
if (strlcpy(s_un.sun_path, path, sizeof(s_un.sun_path)) >= |
sizeof(sun.sun_path)) { |
sizeof(s_un.sun_path)) { |
close(s); |
close(s); |
errno = ENAMETOOLONG; |
errno = ENAMETOOLONG; |
return (-1); |
return (-1); |
} |
} |
if (connect(s, (struct sockaddr *)&sun, sizeof(sun)) < 0) { |
if (connect(s, (struct sockaddr *)&s_un, sizeof(s_un)) < 0) { |
close(s); |
close(s); |
return (-1); |
return (-1); |
} |
} |