Multicast recvfrom not working??????
- From: cs3266@xxxxxxxxx
- Date: 23 Jun 2006 11:03:56 -0700
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;
}
}
.
- Follow-Ups:
- Re: Multicast recvfrom not working??????
- From: Phil Frisbie, Jr.
- Re: Multicast recvfrom not working??????
- Prev by Date: IP Addresses With No PTR Record
- Next by Date: relation between iptables and webmin's Linux firewall
- Previous by thread: IP Addresses With No PTR Record
- Next by thread: Re: Multicast recvfrom not working??????
- Index(es):
Relevant Pages
|