Re: Multicast listening
Re: Multicast listening
- Subject: Re: Multicast listening
- From: Mohacsi Janos <email@hidden>
- Date: Wed, 9 Jan 2008 12:12:56 +0100 (CET)
Hi Alex,
Receiving multicast packets slightly more tricky than sending
multicast:
- Sending multicast is easy - you just specify the multicast destination
- Receiving you have to ask the kernel to notify the first hop router (and
all the router along the path) that your node is interested in a certain
multicast group (kernel will do the IGMP and MLD depending IPv4 or
IPv6...) To request or levave a certain multicast group you have to use
the setsockopt().
See some examples:
http://www.nmsl.cs.ucsb.edu/MulticastSocketsBook/
or
http://www.cs.utah.edu/~swalton/listings/sockets/programs/
Regards,
Janos Mohacsi
Network Engineer, Research Associate, Head of Network Planning and Projects
NIIF/HUNGARNET, HUNGARY
Key 70EF9882: DEC2 C685 1ED4 C95A 145F 4300 6F64 7B00 70EF 9882
On Wed, 9 Jan 2008, Alex Tarter wrote:
I have a problem with my socket program. I have written a program to
listen for multicast UDP packets and to respond to them.
If the destination address of the packets is not multicast but unicast
to my ip address it works fine. But if I change to a multicast address
and subscribe the program doesn't receive the packets.
What is strange is that if I run wireshark at the same time then the
program works fine and see and responds to the multicast packets. Is
wireshark activating the IP driver to receive multicast packets
somehow??
Its just a little annoying to have to run wireshark just to get my
program working.
My stripped down code is as follows:
int buffer_sfd;
struct sockaddr_in my_sin, buffer_sin;
socklen_t addr_len;
struct ip_mreq stmreq0;
char buf[MAXBUFLEN];
if ((buffer_sfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("buffer empty socket");
exit(1);
}
my_sin.sin_family = AF_INET;
my_sin.sin_port = htons(48640);
my_sin.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(buffer_sfd, (struct sockaddr *)&my_sin,
sizeof(my_sin)) < 0) {
perror("bind");
exit(1);
}
stmreq0.imr_multiaddr.s_addr = inet_addr("239.192.12.0");
stmreq0.imr_interface.s_addr = INADDR_ANY;
if((numbytes = recvfrom(buffer_sfd, buf, MAXBUFLEN-1, 0,
(struct sockaddr *)&buffer_sin, &addr_len)) < 0) {
perror("recvfrom");
exit(1);
}
Any help would be most appreciated!
This e-mail from Ultra Electronics Limited and any attachments to it are confidential to the intended recipient and may also be privileged. If you have received it in error please notify the sender and delete it from your system. If you are not the intended recipient you must not copy it or use it for any purpose nor disclose or distribute its contents to any other person. All communications may be subject to interception or monitoring for operational and/or security purposes. Please rely on your own virus checking as the sender cannot accept any liability for any damage arising from any bug or virus infection. Ultra Electronics Limited is a company registered in England and Wales, registration number 2830644. The address of its registered office is 417 Bridport Road, Greenford, Middlesex, UB6 8UA.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden