From b118cefd1c56620cc1e2af8f4abf526b518b395f Mon Sep 17 00:00:00 2001 From: Tomas Mudrunka Date: Sat, 2 Nov 2013 14:08:49 +0100 Subject: [PATCH] Script for compiling DHCP options --- bash/dhcp-option.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 bash/dhcp-option.sh diff --git a/bash/dhcp-option.sh b/bash/dhcp-option.sh new file mode 100755 index 0000000..c9c5a76 --- /dev/null +++ b/bash/dhcp-option.sh @@ -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 -- 2.30.2