Bind browser to eth0
mouse 48 · person cloud · link
Last update
2024-11-09
2024
11-09
« — »
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// connect_eth0.c
#define _GNU_SOURCE
#include <unistd.h>
#include <string.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/syscall.h>

#define IFACE_NAME "eth0"
//#define IPV6_TO_BIND "fddd:bbbb::2"

//static void set_bind_addr6 (int fd) {
//  struct sockaddr_in6 addr;
//
//  memset(&addr, 0, sizeof(addr));
//  addr.sin6_family = AF_INET6;
//  inet_pton(AF_INET6, IPV6_TO_BIND, &addr.sin6_addr);
//  bind(fd, (struct sockaddr *)&addr, sizeof(addr));
//}//set_bind_addr6

int connect (int fd, const struct sockaddr *daddr, socklen_t addrlen) {
  int family = daddr->sa_family;

  if (family == AF_INET || family == AF_INET6) {
    //if (family == AF_INET6) set_bind_addr6(fd);
    setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, IFACE_NAME, sizeof(IFACE_NAME));
  }//if

  return syscall(__NR_connect, fd, daddr, addrlen);
}//connect
1
2
gcc -fpic -fPIC -Wall -Wextra -shared -O3 connect_eth0.c -o connect_eth0.so
LD_PRELOAD=/path/to/connect_eth0.so chromium https://ipinfo.io/ip

Source: askubuntu