Skip to content

Instantly share code, notes, and snippets.

@msantos
msantos / apscan.erl
Created August 1, 2011 16:26
Passive scan for wireless access points in Erlang
-module(apscan).
-include("include/wierl_frame.hrl").
-export([start/0, start/3]).
start() ->
start(<<"wlan0">>, 1, 11).
start(Ifname, Min, Max) when is_binary(Ifname), Min =< Max, Min > 0, Max < 12 ->
@msantos
msantos / vpwn.erl
Created June 11, 2011 14:30
VPN over Erlang Distribution Protocol
-module(vpwn).
-export([start/3]).
start(Node, SrcIP, DstIP) ->
Pid = peer(Node, SrcIP, DstIP),
{ok, Dev} = tuncer:create(),
ok = tuncer:up(Dev, SrcIP),
@msantos
msantos / dump.erl
Created April 24, 2011 01:30
Erlang BPF packet sniffer
-module(dump).
-export([start/0,start/2]).
start() ->
start("en1", []).
start(Dev, Filter) when is_list(Dev), is_list(Filter) ->
{ok, Socket, Length} = bpf:open(Dev),
filter(Socket, Length, Filter).
@msantos
msantos / filt.erl
Created April 24, 2011 00:47
Erlang BPF filters
-module(filt).
-include("bpf.hrl").
-export([
rarp/0,
ip/0,
finger/0,
ip/1,
tcp/2
@msantos
msantos / annoy.erl
Created April 24, 2011 00:37
Peer to peer QoS using ARP
-module(annoy).
-export([er/3, arp/2]).
-include("pkt.hrl").
-include("bpf.hrl").
-record(state, {
arp,
fd,
len = 0,
@msantos
msantos / bpf.c
Last active September 5, 2024 02:33
Example of using bpf to capture packets
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <err.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
@msantos
msantos / wierl.erl
Created March 7, 2011 22:17
Erlang wireless AP scanner
-module(wierl).
-export([start/1]).
-define(UINT16, 2/native-unsigned-integer-unit:8).
-define(UINT32, 4/native-unsigned-integer-unit:8).
-define(UINT64, 8/native-unsigned-integer-unit:8).
-define(IFNAMSIZ, 16).
-define(SIOCSIWSCAN, 16#8B18). % Trigger a scan
@msantos
msantos / mem.erl
Created January 2, 2011 20:42
malloc/free example NIF
-module(mem).
-export([
alloc/1,
free/1
]).
-on_load(on_load/0).
on_load() ->
erlang:load_nif("./mem", []).
@msantos
msantos / mem.c
Created January 2, 2011 20:41
malloc/free example NIF
/* gcc -fPIC -shared -o mem.so mem.c -I /usr/local/lib/erlang/usr/include */
#include <stdio.h>
#include <string.h>
#include "erl_nif.h"
static ERL_NIF_TERM atom_ok;
static ERL_NIF_TERM atom_error;
@msantos
msantos / unix_stream.erl
Created December 25, 2010 12:17
Erlang Unix stream socket
-module(unix_stream).
-export([client/1, server/0]).
-define(PF_LOCAL, 1).
-define(SOCK_STREAM, 1).
-define(UNIX_PATH_MAX, 108).
-define(BACKLOG, 5).
-define(PATH, <<"/tmp/unix_stream.sock">>).