Index: svc_dg.c =================================================================== --- svc_dg.c (revision 120171) +++ svc_dg.c (working copy) @@ -222,20 +222,25 @@ svc_dg_recvfrom(int fd, char *buf, int b if (!have_lin) return rlen; lin->sin_family = AF_INET; lin->sin_port = 0; *laddrlen = sizeof(struct sockaddr_in); return rlen; } +/* + * Wrapper that acts like recvfrom. Captures the local address for + * incoming packets so that it can be sent out later using + * IP_SENDSRCADDR. + */ static bool_t svc_dg_recv(xprt, msg) SVCXPRT *xprt; struct rpc_msg *msg; { struct svc_dg_data *su = su_data(xprt); XDR *xdrs = &(su->su_xdrs); char *reply; struct sockaddr_storage ss; socklen_t alen; @@ -273,41 +278,45 @@ again: if (su->su_cache != NULL) { if (cache_get(xprt, msg, &reply, &replylen)) { (void)_sendto(xprt->xp_fd, reply, replylen, 0, (struct sockaddr *)(void *)&ss, alen); return (FALSE); } } return (TRUE); } +/* + * Wrapper for sendto. If laddr is set to a specific address, + * it will be sent out as a source address using IP_SENDSRCADDR. + */ static int svc_dg_sendto(int fd, char *buf, int buflen, const struct sockaddr *raddr, socklen_t raddrlen, const struct sockaddr *laddr, socklen_t laddrlen) { struct msghdr msg; struct iovec msg_iov[1]; struct sockaddr_in *laddr_in = (struct sockaddr_in *)laddr; struct in_addr *lin = &laddr_in->sin_addr; char tmp[CMSG_SPACE(sizeof(*lin))]; struct cmsghdr *cmsg; memset((char *)&msg, 0, sizeof(msg)); msg_iov[0].iov_base = buf; msg_iov[0].iov_len = buflen; msg.msg_iov = msg_iov; msg.msg_iovlen = 1; msg.msg_namelen = raddrlen; msg.msg_name = (char *)raddr; - if (laddr->sa_family == AF_INET) { + if (laddr->sa_family == AF_INET && lin->s_addr != INADDR_ANY) { msg.msg_control = (caddr_t)tmp; msg.msg_controllen = CMSG_LEN(sizeof(*lin)); cmsg = CMSG_FIRSTHDR(&msg); cmsg->cmsg_len = CMSG_LEN(sizeof(*lin)); cmsg->cmsg_level = IPPROTO_IP; cmsg->cmsg_type = IP_SENDSRCADDR; memcpy(CMSG_DATA(cmsg), lin, sizeof(*lin)); } return _sendmsg(fd, &msg, 0);