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

Commit a49c0ba9 authored by nuccachen's avatar nuccachen
Browse files

get_ai: Allocate socket address space for struct sockaddr_union

Currently socket address space is allocated by the address family. When Netd
does IPv6 prefix synthesis on an IPv4 resource record, Netd can't directly cast
a sockaddr_in pointer to a sockaddr_in6 pointer for reporting synthesized IPv6
address. The size of sockaddr_union is enough for either an IPv6 or IPv4
address. It allows that a socket address can be directly cast as
a protocol-specific (IPv4/IPv6) address structure.

Bug: 78545619
Test: netd_{unit,integration}_test pass
Change-Id: I49fcba89a7de59a5ca49933f84887177c5500425
parent a4b33028
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -731,12 +731,12 @@ static struct addrinfo* get_ai(const struct addrinfo* pai, const struct afd* afd
    assert(afd != NULL);
    assert(addr != NULL);

    ai = (struct addrinfo*) malloc(sizeof(struct addrinfo) + (afd->a_socklen));
    ai = (struct addrinfo*) malloc(sizeof(struct addrinfo) + sizeof(sockaddr_union));
    if (ai == NULL) return NULL;

    memcpy(ai, pai, sizeof(struct addrinfo));
    ai->ai_addr = (struct sockaddr*) (void*) (ai + 1);
    memset(ai->ai_addr, 0, (size_t) afd->a_socklen);
    memset(ai->ai_addr, 0, sizeof(sockaddr_union));

    ai->ai_addrlen = afd->a_socklen;
    ai->ai_addr->sa_family = ai->ai_family = afd->a_af;