2 #Experimental BASH script to compile DHCP options
5 echo 'obase=16; '"$1" |
bc
9 echo -n $
(while true
; do echo -n 0; done |
head -c "$2")$
(dec_to_hex
"$1") |
tail -c "$2"
13 #Adds \x escapes to hexdump string
16 [ -n "$i" ] && echo -n '\x'"$i";
21 #Converts \x00\x00 notation to 00:00 notation
23 sed -e 's/^\\x//g' |
sed -e 's/\\x/:/g'
27 #Compile DHCP option using option number and data.
28 #Generates hex string including header with option number and data length.
34 len
=$
(echo -n "$option_data" |
wc -c)
35 dec_to_hex_right
$option_id 2 | escape
36 dec_to_hex_right
$len 2 | escape
37 printf "$option_data" | xxd
-ps -c 256 | escape
41 #Generate prefix sub-option to be included in PD option of DHCPv6
44 lifetime_preferred
='\x00\x00\x01\x2C'
45 lifetime_valid
='\x00\x00\x01\x2C'
49 prefix
='\x20\x01\x06\x7c\x21\x90\x1a\x01''\x00\x00\x00\x00\x00\x00\x00\x00'
51 prefix_length_hex
=$
(dec_to_hex
$prefix_length)
53 #echo $prefix_length_hex
54 dhcp_option
$option_id "$lifetime_preferred$lifetime_valid$prefix_length_hex$prefix"
58 #Generate data of PF option of DHCPv6
60 iaid
='\x00\x00\x00\x00'
63 ia_pd_opts
="$(pd_prefix)"
64 echo -n "$iaid$t1$t2$ia_pd_opts"
68 #Generate PD option of DHCPv6 (including header)
71 dhcp_option
$option_id "$(pd)"
This page took 0.639138 seconds and 4 git commands to generate.