Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Multicast listening



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:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.