LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-06-2010, 09:47 AM   #1
GordonAkst
LQ Newbie
 
Registered: Aug 2010
Posts: 9

Rep: Reputation: 0
Receiving UDP multicast


Hi
I am trying to port some MS Visual Studio C++ code to Linux/wxWidgets. The code is socket-based and very similar between Windows and Linux. In Linux the socket, bind, and setsocketopt all return with no error. See:


Code:
BOOL CAV15Input::SetupSocket(BOOL Out)
{
        if(pU->PrDebug)
        {
                sprintf(_send,"CAV15Input::SetupSocket for port %d",pSonar->dPort);
                pU->OutMsg(_send,1,0);
        }
       
        pSonar->UDP_Sock=0;
        pSonar->UDPError=0;
        pSonar->UDP_Sock=socket(AF_INET,SOCK_DGRAM,0);
        if(pSonar->UDP_Sock<0 )
        {
                pU->OutMsg("socket failed on SetupSocket",11,0);
                pSonar->UDP_Sock=0;
                pSonar->UDPError|=4;
                return FALSE;
        }
        //      the AF_INET address family, which contains IP addresses,
        local.sin_family=AF_INET;
        local.sin_addr.s_addr=inet_addr(pSonar->IP_Add_PC);
        local.sin_port=htons(pSonar->dPort);
//      from Dave Goffe:
//>int t = 1;
//>
//>setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&t,sizeof(t));
        int t=1;
        if(setsockopt(pSonar->UDP_Sock,
            SOL_SOCKET,
                SO_REUSEADDR,
                (char *)&t,sizeof(t))
        <0)
        {
                CloseSock();
                pU->OutMsg("set SO_REUSEADDR failed in SetupSocket",11,0);
                pSonar->UDPError|=4;
                return FALSE;
        }

        if(bind(pSonar->UDP_Sock,(sockaddr *)&local,sizeof(local)))
        {
                CloseSock();
                pU->OutMsg("bind failed in SetupSocket",11,0);
                pSonar->UDPError|=8;
                return FALSE;
        }
        if(pU->PrDebug)
        {
                sprintf(_send,"socket setup & bind OK for port %d",pSonar->dPort);
                pU->OutMsg(_send,1,0);
        }
  // Join multicast group
        if(pSonar->datatype)    // for element data
                mreq.imr_multiaddr.s_addr=inet_addr(pSonar->IP_Add_ELD);       
        else    // for beam data
          mreq.imr_multiaddr.s_addr=inet_addr(pSonar->IP_Add_HRB);
        mreq.imr_interface.s_addr=inet_addr(pSonar->IP_Add_PC);
        if(setsockopt(pSonar->UDP_Sock,
            IPPROTO_IP,
                IP_ADD_MEMBERSHIP,
                (char *)&mreq,sizeof(mreq))
        <0)
        {
                CloseSock();
                pU->OutMsg("join multicast failed in SetupSocket",11,0);
                pSonar->UDPError|=16;
                return FALSE;
        }
        if(pU->PrDebug)
        {
                if(pSonar->datatype)    // for element data
                        sprintf(_send,"join multicast OK on %s",pSonar->IP_Add_ELD);   
                else    // for beam data
                        sprintf(_send,"join multicast OK on %s",pSonar->IP_Add_HRB);
                pU->OutMsg(_send,1,0);
        }
        jMCast=1;

        return TRUE;
}
But then when I try
recv(pSonar->UDP_Sock,&pUDP->u_dg_cM.cM[8],reedlen,0);
it blocks as if there is no data. (In Windows this works fine.)
Is there something else in Linux and/or wxWidgets that I'm missing that could prevent UDP datagrams from being received??
Is there some way in Linux to monitor incoming UDP traffic?
Thanks.
Gordon
 
Old 11-06-2010, 10:52 AM   #2
grim76
Member
 
Registered: Jun 2007
Distribution: Debian, SLES, Ubuntu
Posts: 283

Rep: Reputation: 47
I had a friend with a similar problem. Iptables was turned on and blocking multicast traffic.
 
Old 11-08-2010, 03:37 PM   #3
GordonAkst
LQ Newbie
 
Registered: Aug 2010
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks; you were right Iptables was turned on; unfortunately, turning it off did not solve the problem.
Don't know if it's the C++ code or something in Linux.
By the way, I looked at ifconfig and netstat outputs and they show that multicast is setup and that packets are being received with no errors, BUT my app gets nothing (recv returns -1).
Help!
Gordon
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems receiving multicast data perry_mason_i Linux - Networking 0 03-30-2009 12:45 PM
Problem receiving multicast icedown Linux - Networking 1 03-26-2009 10:09 PM
Problems receiving multicast packets, kernel 2.6.24 nathan2225 Linux - Networking 3 08-30-2008 04:39 PM
Strange load oscillation receiving udp multicast nathan2225 Linux - Networking 0 03-28-2007 05:10 AM
java multicast - problems receiving packets champ Programming 2 05-31-2006 11:33 AM


All times are GMT -5. The time now is 05:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration