In mod_proxy_fdpass there is a function socket_connect_un():

https://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/proxy/mod_proxy_fdpass.c

which contains the code:

        rv = connect(rawsock, (struct sockaddr*)sa,
                               sizeof(*sa) + strlen(sa->sun_path));

Can some explain to me why it is using:

sizeof(*sa) + strlen(sa->sun_path)

rather than just:

sizeof(*sa)

It just doesn't seem right.

One does find on the Internet examples which use:

#define SERV_PATH "./serv.path" struct sockaddr_un serv_addr; int servlen;
bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sun_family =
AF_UNIX; strcpy(serv_addr.sun_path, SERV_PATH); servlen =
strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family); connect(sockfd,
(struct sockaddr *) &serv_addr, servlen);

That is, the sockaddr_un structure length is calculated as:

servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family)

It almost looked like someone started with something similar, but rather
than replace the whole thing with:

sizeof(*sa)

replaced just the part:

sizeof(serv_addr.sun_family)

and then wrongly still added the length of the sun_path member of the
struct to that.

Any comments? Is there something else funny going on with mod_proxy_fdpass
that requires it be done this way?

Graham

Reply via email to