Tuesday, October 10, 2006

Erlang DNS Proxy

Last weekend I started learning erlang. I mentioned that I wanted to make a DNS proxy that can do filtering. Right now I have the proxy running. It doesn't modify packets, but it does print them on their way back. You've probably never wondered how names on the internet get resolved to addresses. Either way, this is what a DNS packet looks like.
Packet: {58634,
33152,
1,
1,
2,
2,
[{<<"shaunkruger.com.">>, -- Domain name to resolve
1,
1,
<<192,12,0,1,0,1,0,0,115,20,0
,4,64,20,38,170,192,12,0,2,0,1,0,3,22,20,0,6,3,110,115,50,192,12,192,12,0,2,0,1,0,3,22,20,0,5,2,110,115,192,12,192,79,0,1,0,1,0,3,22,20,0,4,64,20,38,170,192,61,0,1,0,1,0,3,22,20,0,4,63,246,10,45>>}],
[{1,
1,
29460,
4,
{64,20,38,170}, -- Internet address for shaunkruger.com is here
<<192,12,0,2,0,1,0,3,22,20,0,6
,3,110,115,50,192,12,192,12,0,2,0,1,0,3,22,20,0,5,2,110,115,192,12,192,79,0,1,0,1,0,3,22,20,0,4,64,20,38,170,192,61,0,1,0,1,0,3,22,20,0,4,63,246,10,45>>}],
[{2,
1,
202260,
5,
10443014156,
<<192,79,0,1,0,1,0,3,22,20,0,4
,64,20,38,170,192,61,0,1,0,1,0,3,22,20,0,4,63,246,10,45>>},
{2,
1,
202260,
6,
3772913991692,
<<192,12,0,2,0,1,0,3,22,20,0,5
,2,110,115,192,12,192,79,0,1,0,1,0,3,22,20,0,4,64,20,38,170,192,61,0,1,0,1,0,3,22,20,0,4,63,246,10,45>>}],
[{1,1,202260,4,{63,246,10,45},
<<"">>},
{1,
1,
202260,
4,
{64,20,38,170},
<<192,61,0,1,0,1,0,3,22,20,0,4
,63,246,10,45>>}]}

Last time I wrote this in C I had to spend time doing thread synchronization, writing queue abstractions, and making the datatypes I pass around agree somewhat.

It's good to be writing this in erlang. I'm not sure I would be able to do it as well in Lisp. I could possibly do it in C#, but then there is the problem of binary manipulation for parsing the packets. That's never been fun in C#.

For anyone who isn't so into my technical posts, I'm having a fondu party on thursday. I'm pretty sure I'll have something interesting enough to write about from that.

Shaun

No comments: