|
Programming C, bash, Python, Perl, PHP, Java, you name it. |
|
Thread Tools | Display Modes |
|
|||
OpenBSD multicast
How to send multicast datagram via non-default network interface?
I try this: Code:
#include <sys/types.h> #include <sys/socket.h> #include <sys/stat.h> #include <netinet/in.h> #include <arpa/inet.h> #include <err.h> #include <fcntl.h> #include <netdb.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #define IFACE_ADDR "192.168.2.1" #define MCAST_ADDR "239.1.2.3" #define MCAST_PORT 1234 int main(void) { struct sockaddr_in ifaddr, mcaddr; int sock, on; char msg[] = "test test test"; if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) err(1, "socket"); on = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof on) == -1) err(1, "setsockopt(SO_REUSEADDR)"); ifaddr.sin_addr.s_addr = inet_addr(IFACE_ADDR); if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &ifaddr.sin_addr.s_addr, sizeof(ifaddr.sin_addr.s_addr)) == -1) err(1, "setsockopt(IP_MULTICAST_IF)"); memset(&mcaddr, 0, sizeof mcaddr); mcaddr.sin_family = AF_INET; mcaddr.sin_addr.s_addr = inet_addr(MCAST_ADDR); mcaddr.sin_port = (unsigned short)htons(MCAST_PORT); if (sendto(sock, msg, sizeof msg, 0, (struct sockaddr *)&mcaddr, sizeof mcaddr) == -1) err(1, "sendto"); close(sock); return (0); } |
|
|||
How about adding the missing route?
Code:
$ sudo route delete 224/4 delete net 224/4 $ sudo route add 224/4 192.168.2.1 add net 224/4: gateway 192.168.2.1 $ netstat -rn -f inet Routing tables Internet: Destination Gateway Flags Refs Use Mtu Prio Iface default 192.168.222.10 UGS 7 10755 - 8 re0 127/8 127.0.0.1 UGRS 0 0 33152 8 lo0 127.0.0.1 127.0.0.1 UH 2 0 33152 4 lo0 127.0.0.10 127.0.0.10 UH 0 0 33152 4 lo1 192.168.2.1 192.168.2.1 UH 1 0 33152 4 lo2 192.168.222/24 link#1 UC 2 0 - 4 re0 192.168.222.10 00:10:5a:14:52:a5 UHLc 1 1163 - 4 re0 192.168.222.20 127.0.0.1 UG 0 0 33152 56 lo0 192.168.222.200 link#1 UHLc 1 3 - 4 re0 224/4 192.168.2.1 UGS 0 0 33152 8 lo2 Code:
$ sudo ifconfig lo2 create $ sudo ifconfig lo2 192.168.2.1 $ ifconfig lo2 lo2: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33152 priority: 0 groups: lo inet6 fe80::1%lo2 prefixlen 64 scopeid 0x6 inet 192.168.2.1 netmask 0xffffff00
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
|||
Thanks for yours reply!
Sure, yours solution shuld works. But actualy it makes lo2 "primary network interface" for multicast traffic. My goal send few datagrams from an interface without modifying system wide defaults. man 4 ip: Quote:
ps: sorry for my english. Last edited by unkmail; 20th May 2013 at 12:51 PM. Reason: spelling |
|
|||
Instead of messing around with the complete 224/4 block, you could add a more specific route:
Code:
$ sudo route add 239.1.2.3 192.168.2.1 add host 239.1.2.3: gateway 192.168.2.1 See http://www.openbsd.org/mail.html
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump |
|
|||
Thanks! This was my stupid bug in pf.conf:
block return on $wifi_if pass in quick on $wifi_if inet proto udp from any to any port 1234 |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Playing IPTV Multicast stream | tomageeni | OpenBSD General | 2 | 18th July 2010 09:28 PM |