From: Tomas Mudrunka Date: Sat, 2 Nov 2013 13:08:49 +0000 (+0100) Subject: Script for compiling DHCP options X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=b118cefd1c56620cc1e2af8f4abf526b518b395f;p=mirrors%2FPrograms.git Script for compiling DHCP options --- 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