Created
April 16, 2025 00:37
-
-
Save kazu-yamamoto/27e15ba0d86616b7829a51b627a65f64 to your computer and use it in GitHub Desktop.
System event for QUIC client migration
This file contains hidden or 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 <sys/socket.h> | |
#include <sys/types.h> | |
#ifdef MacOS | |
#include <sys/ioctl.h> | |
#include <sys/kern_event.h> | |
int open_socket () { | |
struct kev_request filter = { 0 }; | |
int s = socket(PF_SYSTEM, SOCK_RAW, SYSPROTO_EVENT); | |
filter.vendor_code = KEV_VENDOR_APPLE; | |
filter.kev_class = KEV_NETWORK_CLASS; | |
filter.kev_subclass = KEV_DL_SUBCLASS; | |
ioctl(s, SIOCSKEVFILT, &filter); | |
return s; | |
} | |
int watch_socket(int s) { | |
struct kern_event_msg msg; | |
int ret = recv(s, &msg, sizeof(msg), 0); | |
if (ret < 0) { | |
return -1; | |
} else { | |
return 0; | |
} | |
} | |
#endif | |
#ifdef LINUX | |
#include <linux/netlink.h> | |
#include <linux/rtnetlink.h> | |
int open_socket () { | |
struct sockaddr_nl filter = { 0 }; | |
int s = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); | |
filter.nl_family = AF_NETLINK; | |
filter.nl_groups = RTMGRP_IPV4_ROUTE | RTMGRP_IPV6_ROUTE; | |
bind(s, (struct sockaddr *)&filter, sizeof(filter)); | |
return s; | |
} | |
int watch_socket(int s) { | |
char msg[4096] = {0}; | |
int ret = recv(s, msg, sizeof(msg), 0); | |
if (ret < 0) { | |
return -1; | |
} else { | |
return 0; | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment