update,
This commit is contained in:
1
_ref/computer-networks-project1_elec3120-c33fe69569bd/project-1_elec3120/utils/.gitignore
vendored
Normal file
1
_ref/computer-networks-project1_elec3120-c33fe69569bd/project-1_elec3120/utils/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.pcap
|
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (C) 2023 Carnegie Mellon University and
|
||||
# Hong Kong University of Science and Technology
|
||||
|
||||
# This repository is adopted from the TCP in the
|
||||
# Wild course project from the Computer Networks
|
||||
# course taught at Carnegie Mellon University, and
|
||||
# is used for the Computer Networks (ELEC 3120)
|
||||
# course taught at Hong Kong University of Science
|
||||
# and Technology.
|
||||
|
||||
# No part of the project may be copied and/or
|
||||
# distributed without the express permission of
|
||||
# the course staff. Everyone is prohibited from
|
||||
# releasing their forks in any public places.
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
HOST=$(hostname)
|
||||
IFNAME=$(ifconfig | grep -B1 10.0.1. | grep -o "^\w*")
|
||||
FUNCTION_TO_RUN=$1
|
||||
PCAP_NAME=$2
|
||||
|
||||
if [ -z "$FUNCTION_TO_RUN" ]
|
||||
then
|
||||
echo "usage: ./capture_packets.sh < start | stop | analyze > PCAP_NAME"
|
||||
echo "Expecting name of function to run: start, stop, or analyze."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$PCAP_NAME" ]
|
||||
then
|
||||
PCAP_NAME=$HOST.pcap
|
||||
echo NO PCAP_NAME PARAM SO USING DEFAULT FILE: $PCAP_NAME
|
||||
fi
|
||||
|
||||
start() {
|
||||
sudo tcpdump -i $IFNAME -w $PCAP_NAME udp > /dev/null 2> /dev/null < \
|
||||
/dev/null &
|
||||
}
|
||||
|
||||
stop() {
|
||||
sudo pkill -f "tcpdump -i $IFNAME -w $PCAP_NAME udp"
|
||||
}
|
||||
|
||||
analyze() {
|
||||
tshark -X lua_script:$DIR/tcp.lua -R "cmutcp and not icmp" -r $PCAP_NAME \
|
||||
-T fields \
|
||||
-e frame.time_relative \
|
||||
-e ip.src \
|
||||
-e cmutcp.source_port \
|
||||
-e ip.dst \
|
||||
-e cmutcp.destination_port \
|
||||
-e cmutcp.seq_num \
|
||||
-e cmutcp.ack_num \
|
||||
-e cmutcp.hlen \
|
||||
-e cmutcp.plen \
|
||||
-e cmutcp.flags \
|
||||
-e cmutcp.advertised_window \
|
||||
-e cmutcp.extension_length \
|
||||
-E header=y -E separator=, \
|
||||
-2
|
||||
}
|
||||
|
||||
$FUNCTION_TO_RUN
|
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright (C) 2023 Carnegie Mellon University and
|
||||
# Hong Kong University of Science and Technology
|
||||
|
||||
# This repository is adopted from the TCP in the
|
||||
# Wild course project from the Computer Networks
|
||||
# course taught at Carnegie Mellon University, and
|
||||
# is used for the Computer Networks (ELEC 3120)
|
||||
# course taught at Hong Kong University of Science
|
||||
# and Technology.
|
||||
|
||||
# No part of the project may be copied and/or
|
||||
# distributed without the express permission of
|
||||
# the course staff. Everyone is prohibited from
|
||||
# releasing their forks in any public places.
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||
|
||||
echo "Preparing submission..."
|
||||
echo "Make sure to commit all files that you want to submit."
|
||||
|
||||
cd $SCRIPT_DIR/../..
|
||||
git archive -o handin.tar.gz HEAD
|
||||
|
||||
echo "Upload handin.tar.gz to Gradescope."
|
@@ -0,0 +1,72 @@
|
||||
-- Copyright (C) 2023 Carnegie Mellon University and
|
||||
-- Hong Kong University of Science and Technology
|
||||
|
||||
-- This repository is adopted from the TCP in the
|
||||
-- Wild course project from the Computer Networks
|
||||
-- course taught at Carnegie Mellon University, and
|
||||
-- is used for the Computer Networks (ELEC 3120)
|
||||
-- course taught at Hong Kong University of Science
|
||||
-- and Technology.
|
||||
|
||||
-- No part of the project may be copied and/or
|
||||
-- distributed without the express permission of
|
||||
-- the course staff. Everyone is prohibited from
|
||||
-- releasing their forks in any public places.
|
||||
|
||||
tcp = Proto("cmutcp", "CMU TCP")
|
||||
|
||||
local f_identifier = ProtoField.uint32("cmutcp.identifier", "Identifier")
|
||||
local f_source_port = ProtoField.uint16("cmutcp.source_port", "Source Port")
|
||||
local f_destination_port = ProtoField.uint16("cmutcp.destination_port", "Destination Port")
|
||||
local f_seq_num = ProtoField.uint32("cmutcp.seq_num", "Sequence Number")
|
||||
local f_ack_num = ProtoField.uint32("cmutcp.ack_num", "ACK Number")
|
||||
local f_hlen = ProtoField.uint16("cmutcp.hlen", "Header Length")
|
||||
local f_plen = ProtoField.uint16("cmutcp.plen", "Packet Length")
|
||||
local f_flags = ProtoField.uint8("cmutcp.flags", "Flags")
|
||||
local f_advertised_window = ProtoField.uint16("cmutcp.advertised_window", "Advertised Window")
|
||||
local f_extension_length = ProtoField.uint16("cmutcp.extension_length", "Extension Length")
|
||||
local f_extension_data = ProtoField.string("cmutcp.extension_data", "Extension Data")
|
||||
|
||||
tcp.fields = { f_identifier, f_source_port, f_destination_port, f_seq_num, f_ack_num, f_hlen, f_plen, f_flags, f_advertised_window, f_extension_length , f_extension_data}
|
||||
|
||||
function tcp.dissector(tvb, pInfo, root) -- Tvb, Pinfo, TreeItem
|
||||
if (tvb:len() ~= tvb:reported_len()) then
|
||||
return 0 -- ignore partially captured packets
|
||||
-- this can/may be re-enabled only for unfragmented UDP packets
|
||||
end
|
||||
|
||||
local t = root:add(tcp, tvb(0,25))
|
||||
t:add(f_identifier, tvb(0,4))
|
||||
t:add(f_source_port, tvb(4,2))
|
||||
t:add(f_destination_port, tvb(6,2))
|
||||
t:add(f_seq_num, tvb(8,4))
|
||||
t:add(f_ack_num, tvb(12,4))
|
||||
t:add(f_hlen, tvb(16,2))
|
||||
t:add(f_plen, tvb(18,2))
|
||||
local f = t:add(f_flags, tvb(20,1))
|
||||
t:add(f_advertised_window, tvb(21,2))
|
||||
t:add(f_extension_length, tvb(23,2))
|
||||
local extension_length = tvb(23,1):int()
|
||||
t:add(f_extension_data, tvb(25,extension_length))
|
||||
|
||||
|
||||
local flag = tvb(20,1):uint()
|
||||
|
||||
if bit.band(flag, 8) ~= 0 then
|
||||
f:add(tvb(20,1), "SYN")
|
||||
end
|
||||
if bit.band(flag, 4) ~= 0 then
|
||||
f:add(tvb(20,1), "ACK")
|
||||
end
|
||||
if bit.band(flag, 2) ~= 0 then
|
||||
f:add(tvb(20,1), "FIN")
|
||||
end
|
||||
|
||||
pInfo.cols.protocol = "CMU TCP"
|
||||
end
|
||||
|
||||
-- have to put the port for the server here
|
||||
local udpDissectorTable = DissectorTable.get("udp.port")
|
||||
udpDissectorTable:add("15441", tcp)
|
||||
|
||||
io.stderr:write("tcp.lua is successfully loaded\n")
|
Reference in New Issue
Block a user