Modernize code2network()

This function had before a mixture of sed and tr commands
which was now replaced by bash internal functions. It makes
the code better, performance gain in the LAN is neglectable (1s).

This brings code2network somewhat in line with socksend(). This
function does basically the same (and thus is probably prone
to extinction ;-) ). Albeit there the good thing is it does
conversion and sending in one shot.
This commit is contained in:
Dirk Wetter 2020-03-06 19:25:44 +01:00
parent 5aadc1951d
commit 0d8abd131e

View File

@ -10462,8 +10462,18 @@ send_close_notify() {
# Format string properly for socket # Format string properly for socket
# ARG1: any commented sequence of two bytes hex, separated by commas. It can contain comments, new lines, tabs and white spaces # ARG1: any commented sequence of two bytes hex, separated by commas. It can contain comments, new lines, tabs and white spaces
# NW_STR holds the global with the string prepared for printf, like '\x16\x03\x03\' # NW_STR holds the global with the string prepared for printf, like '\x16\x03\x03\'
# As opposed to socksend() below this is the function where the hexbytes are NOT preceeded by x (mainly they are @ heartbleed,
# ccs and # ticketbleed). Best would be to settle on one function and remove the need for NW_STR, i.e. do everything in one shot.
code2network() { code2network() {
NW_STR=$(sed -e 's/,/\\\x/g' <<< "$1" | sed -e 's/# .*$//g' -e 's/ //g' -e '/^$/d' | tr -d '\n' | tr -d '\t') local temp="" line=""
NW_STR=$(while read -r line; do
[[ -z "$line" ]] && continue # blank line
temp="${line%%\#*}" # remove comments
temp="${temp//,/\\\x}" # comma to \x
temp="${temp//[\t ]/}" # blank and tabs
printf "%s" "$temp"
done <<< "$1")
} }
# sockets inspired by http://blog.chris007.de/?p=238 # sockets inspired by http://blog.chris007.de/?p=238