tech-net archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Simple multicast question



I use something like this usually ...

int XXX_freebsd_joinmcast(in_addr_t mcast_addr, unsigned short int port) {
        int mcast_s = -1, yes = 1;
        struct sockaddr_in mcast_group;
        struct ip_mreq mreq;

        memset(&mcast_group, 0, sizeof(mcast_group));
        mcast_group.sin_family = AF_INET;
        mcast_group.sin_port = htons(port);
        mcast_group.sin_addr.s_addr = mcast_addr;

        if ((mcast_s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
                perror("recv socket");
                return -1;
        }

        if (setsockopt(mcast_s, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 
0) {
                perror("reuseaddr setsockopt");
                return -1;
        }

        if (bind(mcast_s, (struct sockaddr*)&mcast_group, sizeof(mcast_group)) 
< 0){
                perror("bind");
                return -1;
        }

        memset(&mreq, 0, sizeof(mreq));
        mreq.imr_multiaddr = mcast_group.sin_addr;
        mreq.imr_interface.s_addr = htonl(INADDR_ANY);

        if (setsockopt(mcast_s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq,
sizeof(mreq)) < 0) {
                perror("add_membership setsockopt");
                return -1;
        }

        return mcast_s;
}

Hope you will be able to modify it according to your needs.

/ipv

On Sun, Nov 22, 2009 at 11:17 PM, Frank Kardel <kardel%netbsd.org@localhost> 
wrote:
> Hi!
>
> If I were to
> Â1) create an IPv4, DGRAM (UDP) socket
> Â2) bind that to 224.0.1.1
> Â3) do a IP_ADD_MEMBERSHIP for address 224.0.1.1 and imr_interface =
> INADDR_ANY on that socket
> Â4) start recvmsg-ing on it
>
> Would I be able to read the packets that I see via tcpdump going to
> 224.0.1.1 ?
>
> The thing is I see the packets via tcpdump, IGMP seems to work correctly,
> but nothing arrives in the
> program. Am I missing something or do we have a multicast reception problem
> in NetBSD
> (even for older versions of -current)?
> Short investigation gave that mcast packets can be dropped for the
> mcast-address not being
> in the receiving interface's mcast-address-list (ip_input.c) or when the
> dst-addr/port is not found (udp_usrreq.c).
>
> The interface is wm0 and ifconfig shows the multicast counter going up as
> does the CANTFORWARD IP-statistics counter.
>
> Frank
>



-- 
"UNIX is basically a simple operating system, but you have to be a
genius to understand the simplicity." Dennis Ritchie


Home | Main Index | Thread Index | Old Index