Re: UDP sockets bound to ANY send answers with wrong src ip address

From: Julian Anastasov
Date: Fri Jun 11 2004 - 08:54:04 EST



Hello,

On Fri, 11 Jun 2004, Denis Vlasenko wrote:

> Hmmm... do I have to set a *routing dest address* field
> to set src ip address of my UDP packet?

Try such function:

static int my_send(int fd, unsigned srcip, (struct sockaddr *) remote,
char *data, int len)
{
struct iovec iov = { data, len };
struct {
struct cmsghdr cm;
struct in_pktinfo ipi;
} cmsg = {
.cm = {
.cmsg_len = sizeof(struct cmsghdr) +
sizeof(struct in_pktinfo),
.cmsg_level = SOL_IP,
.cmsg_type = IP_PKTINFO,
},
.ipi = {
.ipi_ifindex = 0,
.ipi_spec_dst = srcip,
},
};
struct msghdr m = {
.msg_name = remote,
.msg_namelen = sizeof(struct sockaddr_in),
.msg_iov = &iov,
.msg_iovlen = 1,
.msg_control = &cmsg,
.msg_controllen = sizeof(cmsg),
.msg_flags = 0,
};

return sendmsg(fd, &m, MSG_NOSIGNAL|MSG_DONTWAIT);
}

Regards

--
Julian Anastasov <ja@xxxxxx>

-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html