When you need to include a double quote within a string, you have to escape it as described at
PHP: Strings - Manual[
^]:
exec("sudo tshark -n -r $filename -R rtp -R \"rtp.ssrc == $ssrc\" -T fields -e rtp.payload | tee payloads");
The
for
loop requires understanding the bash commands:
The for loop is a little bit different from other programming languages. Basically, it let's you iterate over a series of 'words' within a string.
So the outer loop will iterate over the white space separated words of the text file
payloads and store them in the variable
$payload
(
cat payloads
prints the content of text files).
The characters used to detect word boundaries are stored in the
$IFS
variable (see
Advanced Bash-Scripting Guide: Chapter 9. Another Look at Variables[
^]). So
IFS=:
changes this from white spaces to the colon character. The inner
for
loop splits
$payload
into
:
separated words and store them in
$byte
. That is printed out with a "\x" prefix to the file
output.raw.
What the loop finally does is converting a text file with colon separated hex byte values to C style notation skipping all white spaces. Example:
Input : 01:ff:3a:4c 5B:88\n 99:43
Output: \x01\xff\x3a\x4c\x5B\x88\x99\x43