lkml.org 
[lkml]   [2004]   [Jun]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: UDP sockets bound to ANY send answers with wrong src ip address

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>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:03    [W:1.371 / U:0.244 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site