Linux, UUE, Packet Switching, and AWK: A Practical Approach
Practice 1: Introduction to Linux
Linux Basic Commands
- pwd: Displays the current working directory.
- ls: Lists the contents of the current directory. If you pass the argument “-l”, it shows extended information.
- chmod: Changes the permissions of a file.
- Example:
chmod 777 file.c
would set the file permissions to rwxrwxrwx (owner, group, and others).
- Example:
- cd: Changes the directory.
- mkdir: Creates a directory.
- mv: Moves files.
- rm: Removes a directory.
- cat / more: Displays the contents of a file to standard output.
- cp: Copies files and directories.
- ps: Lists active processes of the operating system.
- kill: Kills a process given its PID.
Pipes and Redirections
process1 | process2
:process1
redirects its output to the input ofprocess2
.process1 > file
:process1
redirects the output and writes its result to a file.
Practice 2: Application Services
UUE Encoding Algorithm
- The bytes of the binary file are always processed in groups of 3 bytes.
- From each group of 3 bytes, four groups of 6 bits are extracted in an orderly manner from left to right, from the first through the third byte.
- Each group of 6 bits has two “0” bits added to create a new byte (the group of 6 bits is packed to the “right” of the byte). Each new byte represents a character.
- Final ASCII characters must be included among the allowed ASCII characters. Each byte is added to 32. This ensures that the value of all characters generated falls within the 32-96 range. If the byte is 0x00, the ASCII character 0x96 (`) is used directly. This should be taken into account when decoding.
Using the Algorithm in Email
When you encode a binary file for email, you get something like this:
begin filename.ext
M <W1A <G1? 7P! L: 6) C + G-O + C8 `<‘5 T8VAA <@! S = & 1O = 70` <W1R97) R, W ( `9G! R
M: 6YT9 @!? 7V1E <F5G :7-T97)? 9G) A; 65?: 6YF; P! F <F5A9 `! F8VQO <V4` <W1D
E 9 & EN7W5S960 `7U] D871A7W-T87) T`%]? 9VUO, E] S = &% R =%]?`#$`
end
The result consists of a header (begin + filename), the trailer (a single line formed by “end” indicates the end of the file), and the lines that carry information whose first character (byte counter) indicates the original number of bytes encoded in the line, added in 32 units to be compatible with ASCII.
UUE Decoding Algorithm
- Groups of 4 characters are taken.
- Subtract 32 from each character.
- Two zeros are removed from each group.
- Bits are grouped into 3 groups of 8 bits, where each group corresponds to a byte of the original sequence.
Practice 3: Store & Forward Switching
Message Switching
In message switching, the message (m) is always added with a header (H), and the set is sent at the same time, forming a single block of bytes.
Packet Switching
In packet switching, the message (m) is divided into several packets of size (p). Each packet is always added with a header (H), and each set H + p packet header is sent as a byte sequence to form smaller blocks.
Packet Switching with Fixed Length
Practice 4: The AWK Programming Language
Implementation of AWK
awk -F, -f file.awk captura.txt
-F
: Indicates the field separator, in this case, commas.-f
: File containing the AWK code to execute.
Internal Variables
$0
Represents the entire current row.$1
Represents the value of column 1 of the current row.$n
Represents the value of column n of the current row.
Examples
Example 1
($8 == "ICMP") {
# The action pattern is executed only for lines that meet the condition
print "Pattern results ICMP";
print "Line number is:", NR;
print "Capture number:", $1;
}
Example 2
/ARP/
# Pattern without action, displays the rows that match
{
# Action without pattern, is executed for all lines
count = count + 1;
print "We are on the line:", count;
}
Example 3
T_Final = $(2)
($8 != "ICMP") {count = count - 1}
BEGIN {
# Action to be executed at the beginning of a file before processing any line
print "Start example 6";
counter = 8; # Begin variable count to 8
}
END {
# Action to be executed at the end of the file, after processing all lines
print "Number of captured frames:", NR;
print "Instant capture of the last frame:", T_Final
}
Example 4
{protocol[$4] = protocol[$4] + 1;}
END {
for (name_protocol in protocol) {
if (name_protocol != "ARP")
print name_protocol, protocol[name_protocol]
}
}