ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
err, shouldn't the destination address be the address of the machine running the program?, there may be methods to allow you to peer further down the stack if there is a question of multiple interfaces.
err, shouldn't the destination address be the address of the machine running the program?
I receive multicast packets, destination address of such packet is a multicast group address. That's the thing I want to know - address of multicast group received packet was sent to.
ok, try this, use the recvfrom (check on the man pages) call to receive the data. This will give you a sockaddr pointer containing the data about the incoming connection. The sockaddr structure contains a sa_data member which is simply a 14 byte char array. Somewhere in this array is the data you need.
ok, look at "man 7 ip". In there is an option called IP_PKTINFO. This gives some info about the ip packet, including the header destination address.
First set IP_PKTINFO using setsockpt. Then when the data is recieved, use recvmsg to extract the packet information, which should contain the destination address in the header. This only works for datagram/udp transactions. Let me know how you get on, as I've never done this.
Last edited by gearoid_murphy; 11-17-2007 at 09:42 AM.
ok, look at "man 7 ip". In there is an option called IP_PKTINFO. This gives some info about the ip packet, including the header destination address.
First set IP_PKTINFO using setsockpt. Then when the data is recieved, use recvmsg to extract the packet information, which should contain the destination address in the header. This only works for datagram/udp transactions. Let me know how you get on, as I've never done this.
Thanks, this works fine.
I use recvmsg function to read from socket and receive struct in_pktinfo via msg_control member of struct msghdr. The only thing is I have to pass 24-byte buffer as msg_control (not 12-byte that gives sizeof(struct in_pktinfo)) and use latter 12 bytes of that buffer as struct in_pktinfo after successful call to recvmsg. I use Red Hat Enterprise Linux AS release 4 (Nahant Update 4).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.