Why is it needed to use file-descriptors for returning UDP or TCP traffic in bash? -
i aware 1 needs use file-descriptors in order read tcp or udp sockets. example:
exec 3<>/dev/udp/192.0.2.1/161; echo -n "302902010104067075626c6963a01c02047f14ec98020100020100300e300c06082b060102010105000500" | xxd -r -p >&3; read -n 1 -t 0.2 <&3
however, why isn't possible read sockets directly, e.g:
echo -n "302902010104067075626c6963a01c02047f14ec98020100020100300e300c06082b060102010105000500" | xxd -r -p > /dev/udp/192.0.2.1/161; read -n 1 -t 0.2 < /dev/udp/192.0.2.1/161
a socket single file descriptor can used in 2 directions. usual file operators in bash, <
, >
work on 1 file descriptor in 1 direction.
you overwrite existing descriptor, stdin, , use file descriptor number explicitly. equivalent using separate descriptor.
Comments
Post a Comment