# 为虚拟网络接口 utun0 配置 IP 地址 10.0.0.33 和子网掩码 255.255.255.0 网关地址 10.0.0.1
sudo ifconfig utun0 10.0.0.33 10.0.0.1 netmask 255.255.255.0
# 配置目标地址是网段 192.168.1.0/24 的流量走 10.0.0.1 网关
sudo route add 192.168.1.0/24 10.0.0.1
# 将 6.11.20.10 这个单一地址(因为掩码是 32)路由到 192.168.4.1 这个网关
sudo route add 6.11.20.10/32 192.168.4.1
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 <stdlib.h> | |
#include <unistd.h> | |
#include <sys/socket.h> | |
void child(int sock) { | |
char buf[1024]; | |
while (1) { | |
ssize_t n = read(sock, buf, sizeof(buf)); | |
if (n <= 0) { |
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
use log::{info, LevelFilter}; | |
use reqwest; | |
use serde_json::Value; | |
use std::fs::File; | |
use std::io::prelude::*; | |
use std::time::SystemTime; | |
use tokio; | |
// https://github.com/shadowsocks/shadowsocks-rust/blob/master/acl/genacl_proxy_gfw_bypass_china_ip.py |
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
use core::{ | |
future::Future, | |
pin::Pin, | |
task::{Context, Poll, RawWaker, RawWakerVTable, Waker}, | |
}; | |
use std::collections::VecDeque; | |
fn dummy_raw_waker() -> RawWaker { | |
fn no_op(_: *const ()) {} | |
fn clone(_: *const ()) -> RawWaker { |
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 <sys/types.h> | |
#include <sys/ioctl.h> | |
#include <sys/socket.h> | |
#include <sys/sys_domain.h> | |
#include <sys/kern_control.h> | |
#include <net/if_utun.h> | |
#include <errno.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <syslog.h> |
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
use libc::{ | |
c_int, c_long, c_uint, c_void, freeifaddrs, getifaddrs, ifaddrs, sockaddr, sockaddr_in, | |
sockaddr_in6, AF_INET, AF_INET6, IFF_BROADCAST, IFF_LOOPBACK, IFF_MULTICAST, IFF_RUNNING, | |
IFF_UP, RTF_GATEWAY, | |
}; | |
use std::{ | |
ffi::CStr, | |
io, mem, | |
net::{IpAddr, Ipv4Addr}, | |
ptr, |
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
// | |
// tokio = { version = "1.36", features = ["full"] } | |
// | |
use std::{env, error::Error}; | |
use tokio::{ | |
io::{AsyncReadExt, AsyncWriteExt}, | |
net::{TcpListener, ToSocketAddrs, UdpSocket}, | |
}; | |
const TCP_TIMEOUT: u64 = 10 * 1000; // 10sec |
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
// | |
// [dependencies] | |
// windows = { version = "0.51", features = [ | |
// "Win32_System_SystemInformation", | |
// "Win32_Networking_WinSock", | |
// "Win32_System_Memory", | |
// "Win32_Foundation", | |
// "Win32_System_IO", | |
// "Win32_System_Threading", | |
// "Win32_Security", |
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 <WINSOCK2.H> | |
#include <stdio.h> | |
#define PORT 5150 | |
#define MSGSIZE 1024 | |
#pragma comment(lib, "ws2_32.lib") | |
typedef enum { | |
RECV_POSTED | |
} OPERATION_TYPE; |
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
use smoltcp::wire::{IpProtocol, Ipv4Packet, Ipv6Packet}; | |
fn extract_udp_packet(packet: &[u8]) -> Result<UdpPacket, Box<dyn std::error::Error>> { | |
if let Ok(ipv4_packet) = Ipv4Packet::new_checked(packet) { | |
let src_addr = ipv4_packet.src_addr(); | |
let dst_addr = ipv4_packet.dst_addr(); | |
let protocol = ipv4_packet.next_header(); | |
let payload = ipv4_packet.payload(); | |
if protocol == IpProtocol::Udp { | |
let udp_packet = smoltcp::wire::UdpPacket::new_checked(payload)?; |