Thread: tcpdump & wireshark get multicast packets, receiver doesn't

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    3

    tcpdump & wireshark get multicast packets, receiver doesn't

    This is both a java/c problem. I'm taking over a MC project that sends data from computer A to Computer B, but not the other way around (it physically can't). The MC comes through to Computer B, I can see this on WireShark & tcpdump, but I can't figure out how to troubleshoot exactly why my program won't read any MC packet. I took a project that I made a year ago and tried it, I have also used other people's projects online, but the only project that ever picked up a MC project at all was a java project, it grabbed 4 packets during 1 run, and 1 packet during another. When I use a sender/receiver on a regular network everything works fine. Does anyone have any ideas about what the problem could be?

    Note: Yes this code is borrowed from another website, but I assure you I can do it on my own. I don't want to accidentally post proprietary info and end up getting fired.

    It never goes past this line of code. I've quadruple checked the ports & ip addresses (so have a few other people). If we hook a separate computer (that makes this bidirectional) and use a different sender, everything works just fine.
    Code:
        
    recvfrom(fd,msgbuf,MSGBUFSIZE,0, (struct sockaddr *) &addr,&addrlen))
    Here's a receiver that I'm using:
    Code:
    #include <sys/types.h> 
    #include <sys/socket.h> 
    #include <netinet/in.h> 
    #include <arpa/inet.h> 
    #include <time.h> #include <string.h> 
    #include <stdio.h>  
    
    //////changed from actual 
    #define HELLO_PORT 12345 
    #define HELLO_GROUP "225.0.0.37" 
    #define MSGBUFSIZE 256  
    
    int main(int argc, char *argv[]) 
    {      
       struct sockaddr_in addr;      
       int fd, nbytes,addrlen;      
       struct ip_mreq mreq;      
       char msgbuf[MSGBUFSIZE];       
       u_int yes=1;
         
        if ((fd=socket(AF_INET,SOCK_DGRAM,0)) < 0) 
        {       
           perror("socket");       
           exit(1);      
        }
        
        if (setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) 
        {        
           perror("Reusing ADDR failed");        
           exit(1);        
        } 
         
        memset(&addr,0,sizeof(addr));      
        addr.sin_family=AF_INET;      
        addr.sin_addr.s_addr=htonl(INADDR_ANY);      
        addr.sin_port=htons(HELLO_PORT);            
        if (bind(fd,(struct sockaddr *) &addr,sizeof(addr)) < 0) 
        {       
           perror("bind");       
           exit(1);      
        }            
        mreq.imr_multiaddr.s_addr=inet_addr(HELLO_GROUP);
         
        mreq.imr_interface.s_addr=htonl(INADDR_ANY//changed to listening interface ip address);      
        if (setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof(mreq)) < 0) 
        {       
           perror("setsockopt");       
           exit(1);      
        }       
        while (1) 
        {       
           addrlen=sizeof(addr);       
           if((nbytes=recvfrom(fd,msgbuf,MSGBUFSIZE,0, (struct sockaddr *) &addr,&addrlen)) < 0) 
           {            
              perror("recvfrom");            
             exit(1);       
           }       
           puts(msgbuf);      
        } 
       return 0;
    }
    Last edited by gnub; 01-12-2012 at 12:50 PM. Reason: Formatting

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Likely a dumb question; but, I will ask it any way.
    Are you positive the sender is using UDP instead of TCP protocol?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    3
    100% Sure =D
    tcpdump -i [interface] -A dst [multicast group] and port [port]
    tcpdump -i eth1 -A dst 235.35.3.5 and port 23535 (just an example of what I'm doing) and I'm getting all messages that are being sent from Computer A.
    Last edited by gnub; 01-12-2012 at 01:08 PM.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    I have glanced at a few Google pages; and I think I might try recvmsg() instead of recvfrom().
    An example was used in one way pipes; so, it might work for one way IP connects.

    Tim S.

    recvmsg() -- receive message from socket and store in structure

    http://www.developer.nokia.com/Commu...ecvmsg_methods
    Last edited by stahta01; 01-12-2012 at 02:17 PM. Reason: grammer
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Jan 2012
    Posts
    3
    Same thing! Thanks anyways. I'll keep messing around with it though.
    That was a good idea! I'm thinking it might be the interface I'm trying to connect to.
    It gives an error if I put in one that doesn't exist, but I'm wondering if the interface is set up in a way that causes problems.
    Code:
    mreq.imr_interface.s_addr=inet_addr("192.168.1.1");
    Last edited by gnub; 01-12-2012 at 02:46 PM.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Did you look at the last example in this link?

    Open C Sockets: recv, recvfrom, recvmsg methods - Nokia Developer Wiki

    It does not use structure ip_mreq instead it uses msghdr.

    Tim S.
    Last edited by stahta01; 01-12-2012 at 03:03 PM.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. raw sockets/wireshark
    By odomae in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-12-2011, 04:16 PM
  2. UDP receiver not receiving packets
    By chris24300 in forum Networking/Device Communication
    Replies: 15
    Last Post: 08-27-2009, 04:15 PM
  3. GPS Receiver
    By hdragon in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 07-29-2007, 08:07 PM
  4. TCP/IP Packet Sender/Receiver
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 02-23-2002, 09:57 AM
  5. TCPDUMP question.
    By William in forum C Programming
    Replies: 1
    Last Post: 09-10-2001, 03:00 AM

Tags for this Thread