The solution binds a client-side socket when using Unix domain sockets. Otherwise, the transient path created to send the UDP packet immediately disappears after sendto() , which explains why the client address information is not available on the server side.
See p. 419 “Stevens Network Programming” or see this for an example client implementation that solves this problem: libpix.org/unp/unixdgcli01_8c_source.html
#include "unp.h" int main(int argc, char **argv) { int sockfd; struct sockaddr_un cliaddr, servaddr; sockfd = Socket(AF_LOCAL, SOCK_DGRAM, 0); bzero(&cliaddr, sizeof(cliaddr)); cliaddr.sun_family = AF_LOCAL; strcpy(cliaddr.sun_path, tmpnam(NULL)); Bind(sockfd, (SA *) &cliaddr, sizeof(cliaddr)); bzero(&servaddr, sizeof(servaddr)); servaddr.sun_family = AF_LOCAL; strcpy(servaddr.sun_path, UNIXDG_PATH); dg_cli(stdin, sockfd, (SA *) &servaddr, sizeof(servaddr)); exit(0); }
Note. unp.h defines Bind() , which is just Bind() with some error checking (commonly used in all Stevens networking programs). Similarly, (SA *) equivalent to (struct sockaddr *) .
source share