Sunday, 15 February 2015

c - Send multicast from eth0 to eth1 -



c - Send multicast from eth0 to eth1 -

i need send multicast info eth0 interface , receive on eth1 on linux machine. have 2 programs in c, prog-1 setsockopt ip_multicast_if send eth0, prog-2 bring together mcast grouping on eth1 ( verified netstat -ng) can't see multicast traffic on eth1. can see multicast info on eth0. increased ttl no help. there way receive multicast sent eth0 on eth1? ip_multicast_loop not help either, works when both programs working on same interface, , no me. it's custom protocol on ipv4.

sender code:

sock_fd = socket( af_inet, sock_raw, 100 ); srcip = inet_addr("10.1.231.112"); /* src mcast eth0 */ ret_val = setsockopt( sock_fd, ipproto_ip, ip_multicast_if, &srcip, sizeof( srcip )); ttl = 0x2; ret_val = setsockopt( sock_fd, ipproto_ip, ip_multicast_ttl, ( char * ) &ttl, sizeof( ttl )); dest_addr.sin_addr.s_addr = inet_addr("224.100.1.102"); dest_addr.sin_family = af_inet; dest_addr.sin_port = 0; ret_val = sendto(sock_fd, (char *) buf, (size_t) 64, 0, /* no flags */ (struct sockaddr *) &dest_addr, addr_len);

receiver code:

sock_fd = socket( af_inet, sock_raw, 100 ); mreq.imr_multiaddr.s_addr = inet_addr("224.100.1.102"); mreq.imr_interface.s_addr = inet_addr("10.0.3.15"); /* bring together on eth1 */ ret_val = setsockopt( sock_fd, ipproto_ip, ip_add_membership, ( char * ) &mreq, sizeof( mreq )); msglen = recvfrom(sock_fd, buf, 4096, 0, (struct sockaddr*)&addr_struct, &addr_len);

i verified netstat -ng receiver joined grouping on eth1, message sent sender visible on eth0 (wireshark on eth1 not capture anything).

let me explain exact problem i'm facing. have production code runs on proprietary hardware. piece of software network communication. communication done via multicast. architecture there tx task sending multicast info other devices in network, unfortunately there rx task joining same grouping tx task sends info to, because other network devices communicating device on same mcast address. on production code have multicast loop disabled , ok, rx task not receive tx task sending. decided run software on linux machine testing purposes, on same machine want run software simulating other boxes. wanted accomplish "bind" mcast sockets on production code eth0 , on simulator on eth1. can't have them communicate each other. can configure network interfaces need, add together vlans, interfaces or anything, create communicate 1 another. can't alter architecture of software.

take @ igmpproxy http://sourceforge.net/projects/igmpproxy/ receives multicast packets on 1 interface , broadcasts specified others.

c linux multicast

No comments:

Post a Comment