1 ! Copyright (C) 2007 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: alien alien.c-types alien.syntax byte-arrays io
4 io.sockets kernel structs math math.parser
5 prettyprint sequences ;
9 { { "char" 6 } "dmac" }
10 { { "char" 6 } "smac" }
13 : >mac-address ( byte-array -- string )
15 [ >hex 2 48 pad-left ] { } map-as ":" join ;
17 : etherneth. ( etherneth -- )
18 [ etherneth-dmac "Dest MAC: " write >mac-address . ] keep
19 [ etherneth-smac "Source MAC: " write >mac-address . ] keep
20 [ etherneth-type "Type : " write .h ] keep
24 { "uchar" "hl|v" } ! hl is 4 bits, v is 4 bits
39 iph-hl|v 0x0f bitand ;
41 : set-iph-hl ( n iph -- )
42 [ iph-hl|v 0x0f bitand >r 4 shift r> bitor ] keep
45 : set-iph-v ( n iph -- )
46 [ iph-hl|v 0xf0 bitand bitor ] keep
60 { "ushort" "check" } ;
73 : tcph-x2 ( iph -- n )
74 tcph-x2|off -4 shift ;
76 : tcph-off ( iph -- n )
77 tcph-x2|off 0x0f bitand ;
79 : set-tcph-x2 ( n iph -- )
80 [ tcph-x2|off 0x0f bitand >r 4 shift r> bitor ] keep
83 : set-tcph-off ( n iph -- )
84 [ tcph-x2|off 0x0f bitand bitor ] keep