-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for AF_UNIX #674
base: latestw_all
Are you sure you want to change the base?
Changes from all commits
3a77587
f7a8825
6dd4311
b31d181
6cc801b
705ed7e
8ca026c
36e5db5
fd096f5
0d38b15
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ | |
#include <sys\utime.h> | ||
#include "misc_internal.h" | ||
#include "debug.h" | ||
#include "../../../config.h" | ||
|
||
/* internal table that stores the fd to w32_io mapping*/ | ||
struct w32fd_table { | ||
|
@@ -298,9 +299,9 @@ w32_socket(int domain, int type, int protocol) | |
errno = 0; | ||
if (min_index == -1) | ||
return -1; | ||
|
||
if (domain == AF_UNIX && type == SOCK_STREAM) { | ||
pio = fileio_afunix_socket(); | ||
pio = fileio_afunix_socket(); | ||
if (pio == NULL) | ||
return -1; | ||
pio->type = NONSOCK_FD; | ||
|
@@ -309,7 +310,70 @@ w32_socket(int domain, int type, int protocol) | |
if (pio == NULL) | ||
return -1; | ||
pio->type = SOCK_FD; | ||
} | ||
} | ||
|
||
fd_table_set(pio, min_index); | ||
debug4("socket:%d, socktype:%d, io:%p, fd:%d ", pio->sock, type, pio, min_index); | ||
return min_index; | ||
} | ||
|
||
int | ||
w32_afunix_socket(struct sockaddr_un* addr) | ||
{ | ||
#ifdef HAVE_AFUNIX_H | ||
/* | ||
If HAVE_AFUNIX_H is defined, we can be dealing with the ssh-agent named pipe or | ||
a AF_UNIX socket if ssh forwarding is enabled. If the addr->sun_path is the | ||
the well known named pipe, we open the socket with w32_fileio. | ||
*/ | ||
int len = wcslen(AGENT_PIPE_ID); | ||
char* pipeid = (char*)malloc(len + 1); | ||
memset(pipeid, 0, len + 1); | ||
|
||
if(wcstombs(pipeid, AGENT_PIPE_ID, len + 1) != (size_t) -1 && strcmp(addr->sun_path, pipeid) == 0) | ||
return w32_fileio_socket(SOCK_STREAM, 0); | ||
else | ||
return w32_unix_socket(SOCK_STREAM, 0); | ||
Comment on lines
+333
to
+336
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand the code correctly, you could technically just call Besides, instead of checking whether There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Originally I was thinking of behaving this way just for this implementation but I think the prefix makes sense in order to support other implementations. |
||
#else | ||
return w32_socket(AF_UNIX, SOCK_STREAM, 0); | ||
#endif | ||
} | ||
|
||
int | ||
w32_unix_socket(int type, int protocol) | ||
{ | ||
int domain = AF_UNIX; | ||
int min_index = fd_table_get_min_index(); | ||
struct w32_io* pio = NULL; | ||
|
||
errno = 0; | ||
if (min_index == -1) | ||
return -1; | ||
|
||
pio = socketio_socket(domain, type, protocol); | ||
if (pio == NULL) | ||
return -1; | ||
pio->type = SOCK_FD; | ||
|
||
fd_table_set(pio, min_index); | ||
debug4("socket:%d, socktype:%d, io:%p, fd:%d ", pio->sock, type, pio, min_index); | ||
return min_index; | ||
} | ||
|
||
int | ||
w32_fileio_socket(int type, int protocol) | ||
{ | ||
int min_index = fd_table_get_min_index(); | ||
struct w32_io* pio = NULL; | ||
|
||
errno = 0; | ||
if (min_index == -1) | ||
return -1; | ||
|
||
pio = fileio_afunix_socket(); | ||
if (pio == NULL) | ||
return -1; | ||
pio->type = NONSOCK_FD; | ||
|
||
fd_table_set(pio, min_index); | ||
debug4("socket:%d, socktype:%d, io:%p, fd:%d ", pio->sock, type, pio, min_index); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this
#ifdef
condition necessary? IfIPPROTO_TCP
does not work for some reason, would it be possible to always useIPPROTO_IP
(or just0
)? man socket(2) suggests that specifying0
(which is the value ofIPPROTO_IP
) will use the default, which again is TCP.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would need to try this out. I don't recall if
IPPROTO_TCP
was not working.