Skip to content

Commit

Permalink
Merge pull request #27 from PacBrew/getaddrinfo
Browse files Browse the repository at this point in the history
fix getaddrinfo
  • Loading branch information
Cryptogenic authored Feb 1, 2022
2 parents 0c57951 + 1d8ffc7 commit c03d323
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/network/res_msend.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
#include "syscall.h"
#include "lookup.h"

#if PS4
#include <fcntl.h>
#endif

static void cleanup(void *p)
{
int errno1 = errno;
Expand Down Expand Up @@ -48,6 +52,9 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,
int cs;
struct pollfd pfd;
unsigned long t0, t1, t2;
#if PS4
int flags;
#endif

pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);

Expand All @@ -72,11 +79,27 @@ int __res_msend_rc(int nqueries, const unsigned char *const *queries,

/* Get local address and open/bind a socket */
sa.sin.sin_family = family;
#if PS4
fd = socket(family, SOCK_DGRAM, 0);
flags = fcntl(fd, F_GETFL, 0);
if(fcntl(fd, F_SETFL, flags | O_CLOEXEC | O_NONBLOCK) < 0) {
return -1;
}
#else
fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
#endif

/* Handle case where system lacks IPv6 support */
if (fd < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) {
#if PS4
fd = socket(AF_INET, SOCK_DGRAM, 0);
flags = fcntl(fd, F_GETFL, 0);
if(fcntl(fd, F_SETFL, flags | O_CLOEXEC | O_NONBLOCK) < 0) {
return -1;
}
#else
fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
#endif
family = AF_INET;
}
if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) {
Expand Down

0 comments on commit c03d323

Please sign in to comment.