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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



	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@ssi.bg>

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

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux