Created
May 12, 2023 20:49
-
-
Save tonusoo/3c878cad74094a15ca8c338475151fb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <unistd.h> | |
#include <netinet/igmp.h> | |
#include <linux/mroute.h> | |
#include <arpa/inet.h> | |
// socket configuration is based on https://github.com/pali/igmpproxy | |
int main() { | |
int s = -1; | |
int Va = 1; | |
struct vifctl VifCtl; | |
struct ip_mreqn mreq; | |
// strace: socket(AF_INET, SOCK_RAW, IPPROTO_IGMP) = 3 | |
s = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP); | |
// strace: setsockopt(3, SOL_IP, 0xc8 /* IP_??? */, [1], 4) = 0 | |
setsockopt(s, IPPROTO_IP, MRT_INIT,(void *)&Va, sizeof( Va )); | |
/* | |
* root@mr3:~# ip a sh dev ens4 | |
* 4: ens4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 | |
* link/ether 52:54:00:13:97:a2 brd ff:ff:ff:ff:ff:ff | |
* inet 10.0.2.1/24 brd 10.0.2.255 scope global ens4 | |
* valid_lft forever preferred_lft forever | |
* root@mr3:~# | |
*/ | |
VifCtl.vifc_vifi = 1; | |
VifCtl.vifc_flags = VIFF_USE_IFINDEX; | |
VifCtl.vifc_lcl_ifindex = 4; | |
VifCtl.vifc_lcl_addr.s_addr = 0x4; | |
VifCtl.vifc_rmt_addr.s_addr = INADDR_ANY; | |
VifCtl.vifc_threshold = 1; | |
VifCtl.vifc_rate_limit = 0; | |
// strace: setsockopt(3, SOL_IP, 0xca /* IP_??? */, "\1\0\10\1\0\0\0\0\4\0\0\0\0\0\0\0", 16) = 0 | |
setsockopt(s, IPPROTO_IP, MRT_ADD_VIF, (char *)&VifCtl, sizeof( VifCtl )); | |
mreq.imr_multiaddr.s_addr = inet_addr("224.0.0.2"); | |
mreq.imr_address.s_addr = inet_addr("10.0.2.1"); | |
// strace: setsockopt(3, SOL_IP, IP_ADD_MEMBERSHIP, {imr_multiaddr=inet_addr("224.0.0.2"), imr_interface=inet_addr("10.0.2.1")}, 12) = 0 | |
setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP,(char *)&mreq, sizeof(mreq)); | |
printf("sleeping for 30s..\n"); | |
sleep(30); | |
close(s); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment