Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  IP packet parsing

epteflo
Posted: Wed Aug 16, 2006 2:49 pm Reply with quote
Joined: 16 Aug 2006 Posts: 5
Hi,

I would like to write an IP packet handler program in Erlang, which would be able to grab IP packets from an interface, modify it, and send forward. Could you help me find the best way to do it?

Thanks
Peter
View user's profile Send private message
Mazen
Posted: Thu Aug 17, 2006 9:50 am Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
Hi

I would suggest you take a look at the inet and gen_tcp modules in the documentation. they provide some nice interfaces, however i dont think you are able to pick up any package received at a specific network interface though (eth1.. etc) but Im not sure. I took a look at it once and didnt see anything that provided an interface for it but if anyone else knows how that would be great to know.

if you want you could do a C driver for accessing the stack directly but in that case you might as well do it in C? Reading the IP packages cant be that hard, however I dont know if you are allowed to manipulate them without the right user in *nix systems (I have a very strong feeling that Windows is even worse but I could be wrong).

Hope some of this jibbersh help Smile
View user's profile Send private message
epteflo
Posted: Thu Aug 17, 2006 10:54 am Reply with quote
Joined: 16 Aug 2006 Posts: 5
Thanks for the advice!

In fact I have already wrote this functionality in C using other existing codes, but in that way the system is too complex, complicated, and big, you know, it seems to be "hacked". I would like to find an easier way, to have a simplier code. That is why I turned to Erlang.

I would like to run this code on Unix OS, but It would be very cool, when it would be runable on Win (but I dont see any chance for it Smile ).

So, Ok, Im going to take a look into the modules you mentioned. Thanks again.
View user's profile Send private message
epteflo
Posted: Thu Aug 17, 2006 11:44 am Reply with quote
Joined: 16 Aug 2006 Posts: 5
Thanks for the advice!

In fact I have already wrote this functionality in C using other existing codes, but in that way the system is too complex, complicated, and big, you know, it seems to be "hacked". I would like to find an easier way, to have a simplier code. That is why I turned to Erlang.

I would like to run this code on Unix OS, but It would be very cool, when it would be runable on Win (but I dont see any chance for it Smile ).

So, Ok, Im going to take a look into the modules you mentioned. Thanks again.
View user's profile Send private message
epteflo
Posted: Thu Aug 17, 2006 12:37 pm Reply with quote
Joined: 16 Aug 2006 Posts: 5
Thanks for the advice!

In fact I have already wrote this functionality in C using other existing codes, but in that way the system is too complex, complicated, and big, you know, it seems to be "hacked". I would like to find an easier way, to have a simplier code. That is why I turned to Erlang.

I would like to run this code on Unix OS, but It would be very cool, when it would be runable on Win (but I dont see any chance for it Smile ).

So, Ok, Im going to take a look into the modules you mentioned. Thanks again.
View user's profile Send private message
epteflo
Posted: Thu Aug 17, 2006 12:40 pm Reply with quote
Joined: 16 Aug 2006 Posts: 5
Sorry for that many reply.... it was my microsoft explorer...no comment....
View user's profile Send private message
Mazen
Posted: Fri Aug 18, 2006 10:40 am Reply with quote
User Joined: 20 Jul 2006 Posts: 164 Location: London
By the way, I came across this package at erlang.org ... it seems interesting for what you are after... its using C stuff though Embarassed

http://www.erlang.org/contrib/erlsnoop-1.0.tgz
View user's profile Send private message
francesco
Posted: Mon Aug 21, 2006 9:09 am Reply with quote
User Joined: 07 Jul 2006 Posts: 249 Location: London
You should be using the bit syntax when writing your application. Parsing an IP header is as easy as:

<<4:4/integer, % Ip Version
Hd_Len:4/integer, % Header Length
Tos:8/integer, % Tos
Len:16/big-integer, % Packet Length
Frg_Id:16/big-integer, % Fragment Id
_:2/integer, % Two first flags... bah
Mf:1/integer, % More Fragments flag
Offset:13/big-integer, % Fragment Offset
TTL:8/integer, % TTL
Protocol:8/integer, % Upper layer protocol
Checksum:16/big-integer, % Checksum
Src_Ip:32/big-integer, % Where this pile of shit came from...
Dst_Ip:32/big-integer, % Should check this against our Ip
Options/binary>> = Ip_Header, % Options

This would be for a rfc791 Ip packet. (The example was taken from the erlang mailing list).

Francesco
View user's profile Send private message Visit poster's website

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum