Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/v1.x' into v1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Dec 26, 2023
2 parents ea2a9ee + 1dd0ab1 commit dfb3911
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 12 deletions.
17 changes: 13 additions & 4 deletions src/unix/pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ int uv_pipe_bind2(uv_pipe_t* handle,
char* pipe_fname;
int sockfd;
int err;
socklen_t addrlen;

pipe_fname = NULL;

Expand Down Expand Up @@ -100,12 +101,15 @@ int uv_pipe_bind2(uv_pipe_t* handle,
* We unlink the file later but abstract sockets disappear
* automatically since they're not real file system entities.
*/
if (*name != '\0') {
if (*name == '\0') {
addrlen = offsetof(struct sockaddr_un, sun_path) + namelen;
} else {
pipe_fname = uv__malloc(namelen + 1);
if (pipe_fname == NULL)
return UV_ENOMEM;
memcpy(pipe_fname, name, namelen);
pipe_fname[namelen] = '\0';
addrlen = sizeof saddr;
}

err = uv__socket(AF_UNIX, SOCK_STREAM, 0);
Expand All @@ -117,7 +121,7 @@ int uv_pipe_bind2(uv_pipe_t* handle,
memcpy(&saddr.sun_path, name, namelen);
saddr.sun_family = AF_UNIX;

if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
if (bind(sockfd, (struct sockaddr*)&saddr, addrlen)) {
err = UV__ERR(errno);
/* Convert ENOENT to EACCES for compatibility with Windows. */
if (err == UV_ENOENT)
Expand Down Expand Up @@ -251,6 +255,7 @@ int uv_pipe_connect2(uv_connect_t* req,
int new_sock;
int err;
int r;
socklen_t addrlen;

if (flags & ~UV_PIPE_NO_TRUNCATE)
return UV_EINVAL;
Expand Down Expand Up @@ -285,9 +290,13 @@ int uv_pipe_connect2(uv_connect_t* req,
memcpy(&saddr.sun_path, name, namelen);
saddr.sun_family = AF_UNIX;

if (*name == '\0')
addrlen = offsetof(struct sockaddr_un, sun_path) + namelen;
else
addrlen = sizeof saddr;

do {
r = connect(uv__stream_fd(handle),
(struct sockaddr*)&saddr, sizeof saddr);
r = connect(uv__stream_fd(handle), (struct sockaddr*)&saddr, addrlen);
}
while (r == -1 && errno == EINTR);

Expand Down
29 changes: 24 additions & 5 deletions src/unix/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,32 @@ static int uv__is_ipv6_link_local(const struct sockaddr* addr) {


static int uv__ipv6_link_local_scope_id(void) {
/* disable link local on AIX & PASE for now */
struct sockaddr_in6* a6;
int rv;
#if defined(_AIX)
return 0;
/* AIX & IBM i do not have ifaddrs
* so fallback to use uv_interface_addresses */
uv_interface_address_t* interfaces;
uv_interface_address_t* ifa;
int count, i;

if (uv_interface_addresses(&interfaces, &count))
return 0;

rv = 0;

for (ifa = interfaces; ifa != &interfaces[count]; ifa++) {
if (uv__is_ipv6_link_local((struct sockaddr*) &ifa->address)) {
rv = ifa->address.address6.sin6_scope_id;
break;
}
}

uv_free_interface_addresses(interfaces, count);

#else
struct sockaddr_in6* a6;
struct ifaddrs* ifa;
struct ifaddrs* p;
int rv;

if (getifaddrs(&ifa))
return 0;
Expand All @@ -244,8 +262,9 @@ static int uv__ipv6_link_local_scope_id(void) {
}

freeifaddrs(ifa);
#endif /* defined(_AIX) */

return rv;
#endif
}


Expand Down
7 changes: 4 additions & 3 deletions test/test-pipe-getsockname.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ static void pipe_client_connect_cb(uv_connect_t* req, int status) {

if (*buf == '\0') { /* Linux abstract socket. */
const char expected[] = "\0" TEST_PIPENAME;
ASSERT_GE(len, sizeof(expected));
ASSERT_MEM_EQ(buf, expected, sizeof(expected));
ASSERT_EQ(len, sizeof(expected) - 1);
ASSERT_MEM_EQ(buf, expected, len);
} else {
ASSERT_NE(0, buf[len - 1]);
ASSERT_MEM_EQ(buf, TEST_PIPENAME, len);
Expand Down Expand Up @@ -191,7 +191,8 @@ TEST_IMPL(pipe_getsockname_abstract) {
ASSERT_OK(uv_pipe_init(uv_default_loop(), &pipe_server, 0));
ASSERT_OK(uv_pipe_bind2(&pipe_server, name, sizeof(name) - 1, 0));
ASSERT_OK(uv_pipe_getsockname(&pipe_server, buf, &buflen));
ASSERT_MEM_EQ(name, buf, sizeof(name));
ASSERT_UINT64_EQ(sizeof(name) - 1, buflen);
ASSERT_MEM_EQ(name, buf, buflen);
ASSERT_OK(uv_listen((uv_stream_t*) &pipe_server,
0,
pipe_server_connection_cb));
Expand Down

0 comments on commit dfb3911

Please sign in to comment.