Skip to content

Instantly share code, notes, and snippets.

-module(hawk_uds).
%% API
-export([start_link/1,
init/1]).
-export([accept/1, handle/1]).
start_link(File) ->
{ok, spawn_link(?MODULE, init, [File])}.
@msantos
msantos / xu.erl
Created July 25, 2015 15:39
xu: unix socket echo client
-module(xu).
-export([start/1,start/4]).
-export([connect/5]).
-define(RESPONSE_TIMEOUT, 20000).
-define(NUM_CLIENTS, 10).
-define(DELAY, 1000).
-define(NUM_REQUESTS, 100).
-module(xecho).
-export([listen/0, listen/1]).
listen() ->
listen(0).
listen(Port) ->
{ok, S} = gen_tcp:listen(Port, [binary, inet, {reuseaddr,true}, {backlog,1024}]),
io:format("Listening on: ~p~n", [inet:port(S)]),
accept(S).
-module(iecho).
-include_lib("procket/include/procket.hrl").
-export([listen/0, listen/1]).
%%%
%%% Warning: error handling omitted, leaks fd's on error
%%%
listen() ->
-module(xt).
-export([start/1,start/4]).
-export([connect/5]).
-define(RESPONSE_TIMEOUT, 20000).
-define(NUM_CLIENTS, 10).
-define(DELAY, 1000).
-define(NUM_REQUESTS, 100).
@msantos
msantos / wastrel.erl
Created January 7, 2015 15:18
Tunnel over erlang distribution, randomly drops/delays frames
-module(wastrel).
-export([start/5]).
start(Node, SrcIP, DstIP, Drop, Delay) ->
random:seed(now()),
Pid = peer(Node, addr(SrcIP), addr(DstIP), Drop, Delay),
{ok, Dev} = tuncer:create("wastrel", [tap, no_pi, {active, true}]),
ok = tuncer:up(Dev, SrcIP),
proxy(Dev, Pid, Drop, Delay).
@msantos
msantos / br.erl
Last active December 26, 2015 23:29
Simple Erlang switch for LXC
-module(br).
-export([start/0]).
% git clone https://github.com/msantos/tunctl
% sudo ./start.sh
@msantos
msantos / sut.erl
Created March 29, 2012 20:30
Erlang IPv6 in IPv4 tunnel (RFC 4213)
-module(sut).
%%% Erlang 6in4 tunnel (RFC 4213)
%%%
%%% Not RFC compliant yet and probably buggy, but works!
%%%
%%% * Dependencies:
%%%
%%% https://github.com/msantos/procket
%%% https://github.com/msantos/pkt
@msantos
msantos / serctl.erl
Created September 22, 2011 15:28
"Low level" Erlang serial interface
%% Copyright (c) 2011, Michael Santos <michael.santos@gmail.com>
%% All rights reserved.
%%
%% Redistribution and use in source and binary forms, with or without
%% modification, are permitted provided that the following conditions
%% are met:
%%
%% Redistributions of source code must retain the above copyright
%% notice, this list of conditions and the following disclaimer.
%%
@msantos
msantos / serctl.c
Created September 22, 2011 15:27
"Low level" serial interface
/* Copyright (c) 2011, Michael Santos <michael.santos@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*