Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 06 Jul 2012 15:53:28 +0400
From:      Budnev Vladimir <vladimir.budnev@gmail.com>
To:        Nikolay Denev <zndenev@gmail.com>, freebsd-questions@freebsd.org
Subject:   Re: how to correctly distinguish broadcast udp packets vs unicast (socket, pcap or bpf)?
Message-ID:  <4FF6D1B8.3080108@gmail.com>
In-Reply-To: <4FF46498.2070901@gmail.com>
References:  <4FF45C81.3030907@gmail.com> <07EA7CC9-19CF-4EFE-A9E2-6A94DCA3F1AC@gmail.com> <4FF46498.2070901@gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Tnx!
Worked like a charm, with skipped init and other checks, just the 
control point parts:
<...>
             int optval=1;

             setsockopt(root_socket, IPPROTO_IP, IP_RECVDSTADDR, 
&optval, sizeof(optval))
<...>
             char t[200];
             unsigned int sender_len;
             struct msghdr msg;
             struct iovec iov;
             struct sockaddr_in from;
             sender_len = sizeof(from);
             msg.msg_name = &from;
             msg.msg_namelen = sender_len;
             msg.msg_iov = &iov;
             msg.msg_iovlen = 1;
             msg.msg_iov->iov_base = &u;
             msg.msg_iov->iov_len = sizeof(packet_container);
             msg.msg_control = t;
             msg.msg_controllen = sizeof(t);
             msg.msg_flags = 0;
<...>
             result = recvmsg(root_socket,&msg,0);
<...>
             struct cmsghdr *cmsg=NULL;
             uint32_t* dst_ip=NULL;
             for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; cmsg = 
CMSG_NXTHDR(&msg,cmsg)) {
                 if (cmsg->cmsg_level == IPPROTO_IP && cmsg->cmsg_type 
== IP_RECVDSTADDR) {
                     dst_ip=(uint32_t*)CMSG_DATA(cmsg);
                     break;
                 }
             }
<...>
And at that point we have destination ip in dst_ip var:)




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4FF6D1B8.3080108>