Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4b9774fe authored by Tao Wu's avatar Tao Wu Committed by android-build-merger
Browse files

Merge "Fallback to IPv6 when IPv4 is not available in adb" am: c32d7fd6 am: 5b7c6772

am: 27c6c4cf

Change-Id: I2ceb40b4589dfc2721197065ae5a85e9dc83b907
parents 7e671b34 27c6c4cf
Loading
Loading
Loading
Loading
+4 −1
Original line number Original line Diff line number Diff line
@@ -598,7 +598,10 @@ inline int network_loopback_client(int port, int type, std::string* error) {
}
}


inline int network_loopback_server(int port, int type, std::string* error) {
inline int network_loopback_server(int port, int type, std::string* error) {
  return _fd_set_error_str(socket_loopback_server(port, type), error);
  int fd = socket_loopback_server(port, type);
  if (fd < 0 && errno == EAFNOSUPPORT)
      return _fd_set_error_str(socket_loopback_server6(port, type), error);
  return _fd_set_error_str(fd, error);
}
}


inline int network_inaddr_any_server(int port, int type, std::string* error) {
inline int network_inaddr_any_server(int port, int type, std::string* error) {
+1 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,7 @@ cutils_socket_t socket_network_client(const char* host, int port, int type);
int socket_network_client_timeout(const char* host, int port, int type,
int socket_network_client_timeout(const char* host, int port, int type,
                                  int timeout, int* getaddrinfo_error);
                                  int timeout, int* getaddrinfo_error);
int socket_loopback_server(int port, int type);
int socket_loopback_server(int port, int type);
int socket_loopback_server6(int port, int type);
int socket_local_server(const char* name, int namespaceId, int type);
int socket_local_server(const char* name, int namespaceId, int type);
int socket_local_server_bind(int s, const char* name, int namespaceId);
int socket_local_server_bind(int s, const char* name, int namespaceId);
int socket_local_client_connect(int fd, const char *name, int namespaceId,
int socket_local_client_connect(int fd, const char *name, int namespaceId,
+31 −12
Original line number Original line Diff line number Diff line
@@ -31,24 +31,18 @@


#include <cutils/sockets.h>
#include <cutils/sockets.h>


/* open listen() port on loopback interface */
static int _socket_loopback_server(int family, int type, struct sockaddr * addr, size_t size)
int socket_loopback_server(int port, int type)
{
{
    struct sockaddr_in addr;
    int s, n;
    int s, n;


    memset(&addr, 0, sizeof(addr));
    s = socket(family, type, 0);
    addr.sin_family = AF_INET;
    if(s < 0)
    addr.sin_port = htons(port);
        return -1;
    addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

    s = socket(AF_INET, type, 0);
    if(s < 0) return -1;


    n = 1;
    n = 1;
    setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &n, sizeof(n));
    setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (const char *) &n, sizeof(n));


    if(bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
    if(bind(s, addr, size) < 0) {
        close(s);
        close(s);
        return -1;
        return -1;
    }
    }
@@ -67,3 +61,28 @@ int socket_loopback_server(int port, int type)
    return s;
    return s;
}
}


/* open listen() port on loopback IPv6 interface */
int socket_loopback_server6(int port, int type)
{
    struct sockaddr_in6 addr;

    memset(&addr, 0, sizeof(addr));
    addr.sin6_family = AF_INET6;
    addr.sin6_port = htons(port);
    addr.sin6_addr = in6addr_loopback;

    return _socket_loopback_server(AF_INET6, type, (struct sockaddr *) &addr, sizeof(addr));
}

/* open listen() port on loopback interface */
int socket_loopback_server(int port, int type)
{
    struct sockaddr_in addr;

    memset(&addr, 0, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(port);
    addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

    return _socket_loopback_server(AF_INET, type, (struct sockaddr *) &addr, sizeof(addr));
}