Re: Multicast listening
Re: Multicast listening
- Subject: Re: Multicast listening
- From: "Hamish Allan" <email@hidden>
- Date: Wed, 9 Jan 2008 18:17:32 +0000
On Jan 9, 2008 3:29 PM, Alex Tarter <email@hidden> wrote:
> OK here is the code I'm using,
I get a bus error when I run your code, but if I pare it down to the
core multicast receive (see below) it works okay.
If I then run "nc -u 239.192.12.0 48640" in another window and type a
line of characters, your code confirms their receipt.
I'm running 10.5.1, and I'm not running Wireshark.
Is it possible that Wireshark is leaving your network interface in a
sorry state after it exits? Have you tried running your code after
rebooting, before running Wireshark?
Hamish
int main (int argc, char * const argv[]) {
int buffer_sfd;
struct sockaddr_in my_sin, buffer_sin;
struct ip_mreq stmreq0;
char buf[MAXBUFLEN];
int iTmp, numbytes;
socklen_t addr_len;
if ((buffer_sfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("buffer empty socket");
exit(1);
}
iTmp = 1;
setsockopt(buffer_sfd, SOL_SOCKET, SO_REUSEADDR, (char *)&iTmp,
sizeof(iTmp));
my_sin.sin_family = AF_INET;
my_sin.sin_port = htons(48640);
my_sin.sin_addr.s_addr = htonl(INADDR_ANY);
if(bind(buffer_sfd, (struct sockaddr *)&my_sin, sizeof(my_sin)) < 0) {
perror("bind");
exit(1);
}
stmreq0.imr_multiaddr.s_addr = inet_addr("239.192.12.0");
stmreq0.imr_interface.s_addr = INADDR_ANY;
setsockopt(buffer_sfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char
*)&stmreq0, sizeof(stmreq0));
addr_len = sizeof(buffer_sin);
while (1) {
memset(buf, '\0', sizeof(buf));
if((numbytes = recvfrom(buffer_sfd, buf, MAXBUFLEN-1,
0, (struct sockaddr *)&buffer_sin, &addr_len)) < 0) {
perror("recvfrom");
exit(1);
}
cout << "received " << numbytes << endl;
}
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden