Script for compiling DHCP options
authorTomas Mudrunka <tomas@mudrunka.cz>
Sat, 2 Nov 2013 13:08:49 +0000 (14:08 +0100)
committerTomas Mudrunka <tomas@mudrunka.cz>
Sat, 2 Nov 2013 13:08:49 +0000 (14:08 +0100)
bash/dhcp-option.sh [new file with mode: 0755]

diff --git a/bash/dhcp-option.sh b/bash/dhcp-option.sh
new file mode 100755 (executable)
index 0000000..c9c5a76
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/bash
+#Experimental BASH script to compile DHCP options
+
+dec_to_hex() {
+       echo 'obase=16; '"$1" | bc
+}
+
+dec_to_hex_right() {
+       echo -n $(while true; do echo -n 0; done | head -c "$2")$(dec_to_hex "$1") | tail -c "$2"
+}
+
+escape() {
+       while read -n 2 i; do
+               [ -n "$i" ] && echo -n '\x'"$i";
+       done
+}
+
+dnsmasq() {
+       sed -e 's/^\\x//g' | sed -e 's/\\x/:/g'
+}
+
+dhcp_option() {
+       separator='\x'
+       option_id="$1"
+       option_data="$2"
+
+       len=$(echo -n "$option_data" | wc -c)
+       dec_to_hex_right $option_id 2 | escape
+       dec_to_hex_right $len 2 | escape
+       printf "$option_data" | xxd -ps -c 256 | escape
+}
+
+pd() {
+       option_id=25
+       iaid='\x00\x00\x00\x00'
+       t1='\x00\x00\x01\x2C'
+       t2='\x00\x00\x01\x2C'
+       ia_pd_opts=''
+       dhcp_option $option_id "$iaid$t1$t2$id_pd_opts"
+}
+
+pd | dnsmasq
+echo
This page took 0.172305 seconds and 4 git commands to generate.