Created
August 14, 2021 16:03
-
-
Save bearice/21cbcd65a8bf49b72119a2534797cf91 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 <assert.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <netinet/in.h> | |
#include <linux/netfilter_ipv6/ip6_tables.h> | |
int main(){ | |
int sk = socket(AF_INET6,SOCK_STREAM,0); | |
printf("sk=%d\n",sk); | |
struct sockaddr_in6 addr={0}; | |
addr.sin6_family = AF_INET6; | |
addr.sin6_port = htons(1111); | |
assert(0==bind(sk,(struct sockaddr*)&addr,sizeof(addr))); | |
assert(0==listen(sk,10)); | |
struct sockaddr_in6 ca; | |
int cal = sizeof(ca); | |
int csk = accept(sk,(struct sockaddr*)&ca,&cal); | |
char buf[INET6_ADDRSTRLEN]; | |
inet_ntop(AF_INET6, &(ca.sin6_addr), buf, INET6_ADDRSTRLEN); | |
printf("client=%s\n",buf); | |
struct sockaddr_in6 sa; | |
int sal = sizeof(sa); | |
getsockopt(csk,SOL_IPV6,IP6T_SO_ORIGINAL_DST,&sa,&sal); | |
inet_ntop(AF_INET6, &(sa.sin6_addr), buf, INET6_ADDRSTRLEN); | |
printf("server=%s\n",buf); | |
return 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
#!/bin/sh | |
gcc ip6t.c -o ip6t | |
./ip6t& | |
sudo ip6tables -t nat -I OUTPUT -d 2001::1 -p tcp -j REDIRECT --to-ports 1111 | |
nc 2001::1 11111 -vN | |
sleep 1 | |
sudo ip6tables -t nat -D OUTPUT -d 2001::1 -p tcp -j REDIRECT --to-ports 1111 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment