Fix error when PF_UNIX is passed as protocol to create unix socket
Zero and PF_UNIX are both supported as protocol when creating unix socket.
This commit is contained in:
parent
e166382923
commit
7a87d77509
@ -184,12 +184,13 @@ enum Status {
|
|||||||
impl UnixSocket {
|
impl UnixSocket {
|
||||||
/// C/S 1: Create a new unix socket
|
/// C/S 1: Create a new unix socket
|
||||||
pub fn new(socket_type: c_int, protocol: c_int) -> Result<Self> {
|
pub fn new(socket_type: c_int, protocol: c_int) -> Result<Self> {
|
||||||
if socket_type == libc::SOCK_STREAM && protocol == 0 {
|
if socket_type == libc::SOCK_STREAM && (protocol == 0 || protocol == libc::PF_UNIX) {
|
||||||
Ok(UnixSocket {
|
Ok(UnixSocket {
|
||||||
obj: None,
|
obj: None,
|
||||||
status: Status::None,
|
status: Status::None,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
// Return different error numbers according to input
|
||||||
return_errno!(ENOSYS, "unimplemented unix socket type")
|
return_errno!(ENOSYS, "unimplemented unix socket type")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ int create_connected_sockets(int *sockets, char *sock_path) {
|
|||||||
THROW_ERROR("failed to listen");
|
THROW_ERROR("failed to listen");
|
||||||
}
|
}
|
||||||
|
|
||||||
int client_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
int client_fd = socket(AF_UNIX, SOCK_STREAM, PF_UNIX);
|
||||||
if (client_fd == -1) {
|
if (client_fd == -1) {
|
||||||
close(listen_fd);
|
close(listen_fd);
|
||||||
THROW_ERROR("failed to create a unix socket");
|
THROW_ERROR("failed to create a unix socket");
|
||||||
|
Loading…
Reference in New Issue
Block a user