Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix sockets with getaddrinfo() in C

Does anyone know if it's possible to use getaddrinfo with unix sockets in C (AF_UNIX). I've tried a couple of things but I can't make it work. This is basically what I'm trying:

struct addrinfo hints, *res;

memset(&hints, 0, sizeof(hints));
hints.ai_family   = AF_UNIX;
hints.ai_socktype = SOCK_STREAM;
if(getaddrinfo("What should I put here?", "What should I put here?", &hints, &res) != 0){
    //do sth about
}

My question is how to fill the node and service fields, in case that is possible to use it with unix sockets.
Thanks in advance.

like image 564
esteban Avatar asked Sep 04 '25 17:09

esteban


1 Answers

Some implementations of getaddrinfo() have supported AF_UNIX socket addresses, but they no longer do so due to security concerns.

You don't really need a function to "look up" an AF_UNIX address anyway - if you know the socket path, then you can just copy it straight into a sockaddr_un of sufficient size. There's no resolution step for AF_UNIX addresses - the socket name is the socket address.

like image 62
caf Avatar answered Sep 07 '25 08:09

caf