How to specify interface in multicast?

Hi! I have a quick question. If I have a multi home PC, Where do I specify which interface to use when sending out multicast msg? Below is my code, this is not the best example out there, could someone please pass me a good example how to construct a multicast socket to send message? Many thanks in advance!

struct sockaddr_in addr ;
memset(&dddr, 0, sizeof(addr));
addr.sin_addr.s_addr = htonl(INADDR_ANY);
addr.sin_family = AF_INET;
address.sin_port = htons(port) ;

int s = socket(PF_INET,SOCK_DGRAM, 0) ;
reusePort(s) ;

bind(s,(struct sockaddr *) &addr, sizeof(addr)) ;

addr.sin_addr.s_addr = inet_addr("239.192.88.53") ;
::connect(s, (struct sockaddr *)&addr, sizeof(addr) ;
return ::send(s, "Test Msg", 8, 0) ;
Work like a charm. Thanks buddy!
One more question though. How do I verify(from shell) which interface am I using to send the packets? I had to ask our network admin to check from the router, but that's sort of inconvenient ...

netstat -ng only shows you subscription, but not sending.
See IP_MULTICAST_IF in: http://tldp.org/HOWTO/Multicast-HOWTO-6.html

You can verify what's going out where with a network sniffer like wireshark.
Thanks again. I found tcpdump works just fine. except it needs sudo ...
Topic archived. No new replies allowed.