Networking Forums

Networking Forums > Computer Networking > Linux Networking > Multicast recvfrom not working??????

Reply
Thread Tools Display Modes

Multicast recvfrom not working??????

 
 
cs3266@gmail.com
Guest
Posts: n/a

 
      06-23-2006, 06:03 PM
I'm trying to setup a multicast client that listens in on eth1 witht
the address: 172.16.90.11
the address on which the stream is coming in is: 239.7.7.1
the socket is setup fine without any problems but i still don't get any
data....in the recvfrom call
i've gone through almost every reference i've found...but still can't
figure out whats going on...can anyone help...
below is the code that I'm using to set it up:

//all the used variables are defined in the header file (no compile
issues here):
//running it on a debian box enabled for multicast

memset(&mcast_addr, 0, sizeof(mcast_addr));
mcast_addr.sin_family = AF_INET;
mcast_addr.sin_port = htons(mPort);
mcast_addr.sin_addr.s_addr = inet_addr("239.7.7.1");

memset(&cli_addr, 0, sizeof(cli_addr));
cli_addr.sin_family = AF_INET;
cli_addr.sin_port = htons(mPort);
cli_addr.sin_addr.s_addr = inet_addr("172.16.90.11");

if((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP))< 0)
exit(-1);

int iSize = 65535;
if(setsockopt(sock, SOL_SOCKET, SO_RCVBUF, (const char*)&iSize,
sizeof(iSize)) < 0)
exit(-1);


int bTrue = 1;
if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &bTrue, sizeof(bTrue))
< 0){
exit(-1);

int ret;
if ((ret = bind(sock, (struct sockaddr*)&cli_addr, sizeof(cli_addr))
)< 0)
exit(-1);


//unsigned long Addr = cli_addr.sin_addr.s_addr;
struct in_addr interface_addr;
if(inet_aton("172.16.90.11", &(interface_addr) ) != 1)
cout << "the addr thing failed" << endl;

if(setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF,
(char*)&interface_addr, sizeof(interface_addr)) < 0)
exit(-1);


if(inet_aton(mAddress.c_str() , &(mreq.imr_multiaddr) ) != 1)
cout << "imr_multiaddr failed" << endl;
if(inet_aton("172.16.90.11", &(mreq.imr_interface)) != 1)
cout << "imr_interface failed" << endl;


if(setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mreq,
sizeof(mreq)) < 0)
exit(-1);

int iTTL =0;
if(setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&iTTL,
sizeof(iTTL)) < 0)
exit(-1);


if(setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, (char*)&bFalse,
sizeof(bFalse)) < 0)
exit(-1);



while(true){
int iFromLen = sizeof(from);
if(recvfrom(sock, mBuffer, MAX_SIZE, 0, &from,
(socklen_t*)&iFromLen) > 0){
cout << "got a message" << endl;
}
}

 
Reply With Quote
 
 
 
 
Phil Frisbie, Jr.
Guest
Posts: n/a

 
      06-23-2006, 10:25 PM
(E-Mail Removed) wrote:

> I'm trying to setup a multicast client that listens in on eth1 witht
> the address: 172.16.90.11
> the address on which the stream is coming in is: 239.7.7.1


While 239.7.7.1 is a multicast address, it is not in the recommended range of
234.0.0.0 to 238.255.255.255

> memset(&mcast_addr, 0, sizeof(mcast_addr));
> mcast_addr.sin_family = AF_INET;
> mcast_addr.sin_port = htons(mPort);
> mcast_addr.sin_addr.s_addr = inet_addr("239.7.7.1");
>
> memset(&cli_addr, 0, sizeof(cli_addr));
> cli_addr.sin_family = AF_INET;
> cli_addr.sin_port = htons(mPort);
> cli_addr.sin_addr.s_addr = inet_addr("172.16.90.11");


It is usually a good idea to use INADDR_ANY.

<snip>
> int bTrue = 1;
> if(setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &bTrue, sizeof(bTrue))
> < 0){
> exit(-1);


I assume you are using the SO_REUSEADDR socket option because the client and
server are on the same computer?

<snip>
> if(setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF,
> (char*)&interface_addr, sizeof(interface_addr)) < 0)
> exit(-1);


Generally you never need to set the IP_MULTICAST_IF option unless you have a
multihomed computer.

<snip>
> int iTTL =0;
> if(setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&iTTL,
> sizeof(iTTL)) < 0)
> exit(-1);


Why are you setting the TTL to 0? I believe it needs to be 1 even for loopback
on the same computer.

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com
 
Reply With Quote
 
cs3266@gmail.com
Guest
Posts: n/a

 
      06-24-2006, 06:32 AM
thanks Phil

> While 239.7.7.1 is a multicast address, it is not in the recommended range of
> 234.0.0.0 to 238.255.255.255


the address 239.7.7.1 is what the servers uses, unfortunately I can't
do much about it.

> It is usually a good idea to use INADDR_ANY.


I am notusing INADDR_ANY since I'm certain that eth1 is connected
receives the multicast packets, but should that cause any problems?

> I assume you are using the SO_REUSEADDR socket option because the client and
> server are on the same computer?


No. The client and the server are running on two different machines. My
client is on the same LAN. If i don't use that option, bind fails for
some reason.

> Generally you never need to set the IP_MULTICAST_IF option unless you have a
> multihomed computer.


Could you please explain what you mean by a multihomed computer?

> Why are you setting the TTL to 0? I believe it needs to be 1 even for loopback
> on the same computer.


I don't plan to send out messages, so I don't expect setting TTL to 0
causing any problems

I'm going to try all that you have suggested, and see if it works.
Besides the above, do you have any other clues as to why i'm not
getting anything in the recvfrom call?

 
Reply With Quote
 
Phil Frisbie, Jr.
Guest
Posts: n/a

 
      06-26-2006, 04:17 PM
(E-Mail Removed) wrote:

>>It is usually a good idea to use INADDR_ANY.

>
> I am notusing INADDR_ANY since I'm certain that eth1 is connected
> receives the multicast packets, but should that cause any problems?


It makes your software more fragile, and one more thing the user must set up in
a config file. Just use INADDR_ANY and let the OS use the proper address.

>>I assume you are using the SO_REUSEADDR socket option because the client and
>>server are on the same computer?

>
> No. The client and the server are running on two different machines. My
> client is on the same LAN. If i don't use that option, bind fails for
> some reason.


If bind() fails then there is already another application bound to that port.
You need to find out what that is and either shut it down or use another port.

>>Generally you never need to set the IP_MULTICAST_IF option unless you have a
>>multihomed computer.

>
> Could you please explain what you mean by a multihomed computer?


Multihomed means you have two or more network cards attached to different networks.

>>Why are you setting the TTL to 0? I believe it needs to be 1 even for loopback
>>on the same computer.

>
> I don't plan to send out messages, so I don't expect setting TTL to 0
> causing any problems


Then just leave it at the default which is 1.

> I'm going to try all that you have suggested, and see if it works.
> Besides the above, do you have any other clues as to why i'm not
> getting anything in the recvfrom call?


I suspect the bind() problem could be the cause, but keep us posted.

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
python recvfrom not working when on different ip ambu.sreedharan Linux Networking 1 06-16-2011 05:52 PM
Socket: recvfrom sathya Linux Networking 1 05-07-2009 01:08 PM
Can Microsoft's RRAS be configured for multicast? Such as in cases where you want to make it a multicast rendevous point? Spin Windows Networking 0 10-26-2006 01:06 PM
problem with recvfrom Omega Linux Networking 0 11-21-2005 08:17 PM
Multicast not working over WiFi? Roy Smith Wireless Internet 3 03-15-2005 03:30 PM



1 2 3 4 5 6 7 8 9 10 11