Skip to content

Instantly share code, notes, and snippets.

@vi
vi / bug_58691.sh
Last active December 17, 2015 16:39
Script to reproduce bug 58691 in linux kernel
#!/bin/bash
# Reproduce https://bugzilla.kernel.org/show_bug.cgi?id=58691
# Depends: sshd listening :22, ssh, unshare, setkey(ipsec-tools), iproute2, ip6_tunnel.ko, veth, radvd
modprobe ip6_tunnel
export MYPID=$$
rm /tmp/unshare_pid
@vi
vi / udprelay.c
Created June 25, 2013 21:29
UDP relay - for implementing other programs working with UDP
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <string.h>
#ifndef WIN32
#include <netdb.h>
#include <sys/socket.h>
@vi
vi / simplecow.rs
Last active December 19, 2015 18:49
Sluggish attempt to test how Rust binds to C code
/* automatically generated by rust-bindgen */
// sources: https://raw.github.com/vi/forsnapshotfs/master/simplecow.h https://raw.github.com/vi/forsnapshotfs/master/simplecow.c
use std::libc::*;
//pub type backing_read_t = *u8;
pub type Struct_simplecow = c_void;
#[link_args = "-lsimplecow"]
@vi
vi / log.txt
Last active December 24, 2015 08:39
Failed attempt to upload a file into a release
$ curl -v -H 'Authorization: token <skipped>' -H "Accept: application/vnd.github.manifold-preview" -H "Content-Type: application/zip" --data-binary @virtual_touchscreen.jar "https://uploads.github.com/repos/vi/virtual_touchscreen/releases/54927/assets?name=virtual_touchscreen.jar"
* About to connect() to uploads.github.com port 443 (#0)
* Trying 192.30.252.97...
* connected
* Connected to uploads.github.com (192.30.252.97) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
@vi
vi / vethify.c
Created October 19, 2013 15:58
Copy packets between two network network interfaces (for workarounds)
/* vethify - multiplex packets between two ethernet interfaces
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@vi
vi / unix2udp.c
Created October 22, 2013 16:50
Turn a pair of packet AF_UNIX sockets into a UDP connection Primary use case: forward individual UDP stream into other network namespace though the shared filesystem (TCP case can be done with socat).
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
@vi
vi / filedistance
Last active May 2, 2019 07:31
Calculate "distance" between files using compression as metric
#!/bin/bash
COMPRESSOR="xz --lzma2=dict="
OVERHEAD=60
if [ -z "$2" ]; then
echo "Usage: filedistance file1 file2"
echo " Outputs similarity metric using between two small files using compression"
echo " 0 - completely similar; 1 - completely dissimilar"
exit 1
@vi
vi / traitinherit.rs
Last active January 3, 2016 07:39
Attempt to play with trait ingeritence in Rust
trait Drawable { fn draw(&self); }
trait VeryDrawable : Drawable + Clone { fn draw_twice(&self) { self.draw(); self.draw(); } }
#[deriving(Eq, Clone)]
enum Circle { Circle }
#[deriving(Eq, Clone)]
struct Rectangle;
impl Drawable for Circle { fn draw(&self) { println("C"); } }
impl Drawable for Rectangle { fn draw(&self) { println("R"); } }
@vi
vi / Makefile
Last active August 29, 2015 13:56
I2P daily graph extraction framework
#wget 'http://127.0.0.1:7657/viewstat.jsp?stat=tunnel.participatingTunnels&showEvents=false&period=60000&periodCount=1500&end=1744&width=2400&height=600' -O 2014-03-01.png
INITIAL_DAY=2014-01-28
WIDTH=1200
HEIGHT=600
ADDR=http://127.0.0.1:7657
DATE_NOW=$(date -u +'%Y-%m-%d')
@vi
vi / setup_ipv6_hacky_router.sh
Created March 19, 2014 01:09
A script to set up IPv6 router advertisment proxy for single peer
#!/bin/bash
set -e
if [ -z "$2" ]; then
echo "Script to set up router advertising proxy for one peer"
echo "Usage: setup_ipv6_hacky_router UPLINK DOWNLIK"
echo "Example: setup_ipv6_hacky_router eth0 wlan0"
exit 1
fi