Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 5 of 6 · Worked example · 25 min · revision 1

Display filters, conversations and stream reassembly

Work through a noisy capture with Wireshark's tools in their tshark form: map it with the conversation view, narrow it with display filters whose current semantics you can predict, rebuild one failing exchange with Follow TCP Stream, and decode IP, UDP and ICMP headers field by field.

Contentsand lesson path

What you will learn

  • Analyse captures with display filters, conversation and stream views, decoding Ethernet, IP, TCP and UDP headers.

Prerequisites: Networking Basics

01. The problem: one failing checkout in a noisy capture

Suppose an online shop's checkout service at 203.0.113.50 sometimes answers 503 Service Unavailable. The service host also answers health checks from two monitoring addresses, refuses connections on a port nobody should use, and receives telemetry datagrams over UDP. Someone captured on the service's interface while the error happened. You must find the failing request and the response body that explains it, and check what else in the file deserves attention.

The constraints: the capture is already taken, so no tighter capture filter; many short connections look alike, so scrolling does not scale; and the error is in the application layer under a lot of lower-layer noise. The method goes from an overview to a filter to one reassembled conversation, reading headers only where the numbers matter.

Step 0 builds the capture so you can run everything yourself, in the lab shell from the capture labs (unshare -c -n --keep-caps bash) with Wireshark 4.0 or later (on Ubuntu 22.04, from the wireshark-dev/stable PPA, as the lab explains); outputs were recorded with tshark 4.6.9. Each step names the matching Wireshark window.

Terminal · Step 0: build the namespaces, the app and mixed.pcap
export LC_ALL=C
mkdir -p ~/pca-we05 && cd ~/pca-we05
cat > app.py <<'PY'
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
calls = {"checkout": 0}
class App(BaseHTTPRequestHandler):
    def reply(self, code, obj):
        body = json.dumps(obj).encode()
        self.send_response(code)
        self.send_header("Content-Type", "application/json")
        self.send_header("Content-Length", str(len(body)))
        self.end_headers()
        self.wfile.write(body)
    def do_GET(self):
        if self.path == "/checkout":
            calls["checkout"] += 1
            if calls["checkout"] == 2:
                return self.reply(503, {"error": "inventory timeout"})
            return self.reply(200, {"order": calls["checkout"]})
        self.reply(200, {"status": "ok"})
    def log_message(self, *args): pass
HTTPServer(("203.0.113.50", 8080), App).serve_forever()
PY
unshare -n sleep infinity & C=$!
unshare -n sleep infinity & V=$!
sleep 0.5
ip link add c0 address 02:00:00:00:05:10 type veth peer name v0 \
  address 02:00:00:00:05:50
ip link set c0 netns $C && ip link set v0 netns $V
nsenter -t $C -n sh -c "ip link set lo up && ip addr add 203.0.113.10/24 dev c0 \
  && ip addr add 203.0.113.11/24 dev c0 && ip link set c0 up"
nsenter -t $V -n sh -c "ip link set lo up && ip addr add 203.0.113.50/24 dev v0 \
  && ip link set v0 up"
nsenter -t $V -n python3 app.py & APP=$!
sleep 1
nsenter -t $V -n tcpdump -Z root --immediate-mode -U -i v0 -w mixed.pcap \
  "not ip6" 2> mixed.log & CAP=$!
sleep 1
for p in health cart health checkout health checkout; do
  nsenter -t $C -n curl -s -o /dev/null http://203.0.113.50:8080/$p
done
for p in health health; do
  nsenter -t $C -n curl -s -o /dev/null --interface 203.0.113.11 \
    http://203.0.113.50:8080/$p
done
nsenter -t $C -n curl -s -o /dev/null http://203.0.113.50:8081/ || true
nsenter -t $C -n bash -c \
  'printf "edge-07 cpu=93 mem=71 disk=88 temp=64\n" > /dev/udp/203.0.113.50/9999'
sleep 1
kill -INT $CAP; wait $CAP
kill $APP $C $V
tail -n 3 mixed.log
Expected output (illustrative: the count varies by a few packets)
107 packets captured
107 packets received by filter
0 packets dropped by kernel

02. Step 1: Map the conversations before you filter

Why an overview first? A filter needs addresses and ports, and an unfamiliar file does not say which matter. Wireshark's Statistics > Conversations window lists every pair of endpoints with packet and byte counts, one tab per layer; tshark -q -z conv,<type> prints the same tables. A conversation is the traffic between two endpoints, and the layer decides what an endpoint is: an address on the IPv4 tab, an address plus a port on the TCP and UDP tabs, so each TCP connection gets its own row.

Terminal · IPv4 and TCP conversation tables
tshark -r mixed.pcap -q -z conv,ip
tshark -r mixed.pcap -q -z conv,tcp
Expected output (illustrative: ports and times vary; each 150-column table row shown over two labelled lines)
================================================================================
IPv4 Conversations
Filter:<No Filter>
203.0.113.10 <-> 203.0.113.50   frames <- 38, -> 40, total 78
  bytes <- 3579 bytes, -> 3234 bytes, total 6813 bytes; start 0.000039000, dur 0.1843
203.0.113.11 <-> 203.0.113.50   frames <- 12, -> 13, total 25
  bytes <- 1130 bytes, -> 1048 bytes, total 2178 bytes; start 0.129079000, dur 0.0229
================================================================================
================================================================================
TCP Conversations
Filter:<No Filter>
203.0.113.10:46130 <-> 203.0.113.50:8080   frames <- 6, -> 7, total 13
  bytes <- 565 bytes, -> 557 bytes, total 1122 bytes; start 0.000039000, dur 0.0006
203.0.113.10:46172 <-> 203.0.113.50:8080   frames <- 6, -> 7, total 13
  bytes <- 565 bytes, -> 557 bytes, total 1122 bytes; start 0.084692000, dur 0.0006
203.0.113.11:44476 <-> 203.0.113.50:8080   frames <- 6, -> 7, total 13
  bytes <- 565 bytes, -> 557 bytes, total 1122 bytes; start 0.151340000, dur 0.0006
203.0.113.10:46136 <-> 203.0.113.50:8080   frames <- 6, -> 6, total 12
  bytes <- 565 bytes, -> 489 bytes, total 1054 bytes; start 0.022121000, dur 0.0005
203.0.113.10:46150 <-> 203.0.113.50:8080   frames <- 6, -> 6, total 12
  bytes <- 565 bytes, -> 491 bytes, total 1056 bytes; start 0.044590000, dur 0.0006
203.0.113.10:46160 <-> 203.0.113.50:8080   frames <- 6, -> 6, total 12
  bytes <- 561 bytes, -> 493 bytes, total 1054 bytes; start 0.064693000, dur 0.0005
203.0.113.10:46180 <-> 203.0.113.50:8080   frames <- 6, -> 6, total 12
  bytes <- 596 bytes, -> 493 bytes, total 1089 bytes; start 0.107068000, dur 0.0009
203.0.113.11:44466 <-> 203.0.113.50:8080   frames <- 6, -> 6, total 12
  bytes <- 565 bytes, -> 491 bytes, total 1056 bytes; start 0.129079000, dur 0.0005
203.0.113.10:35006 <-> 203.0.113.50:8081   frames <- 1, -> 1, total 2
  bytes <- 54 bytes, -> 74 bytes, total 128 bytes; start 0.175008000, dur 0.0000
================================================================================

Two talkers, nine TCP connections. Eight look alike: about a dozen frames and a thousand bytes each, the shape of one small HTTP request. The ninth, to port 8081, has one frame in each direction and no data, the shape of a refused connection. The UDP datagram and its ICMP reply are counted in the IPv4 row of 203.0.113.10 but have no TCP row; -z conv,udp would list the datagram. The overview tells you where to filter next: the port 8080 connections, and the two client addresses.

03. Step 2: Display filters, and what != means today

A display filter is an expression over the fields Wireshark's dissectors decode, such as ip.addr, tcp.port or http.response.code. It runs on packets already in the file and only hides the others. Some fields appear twice in one packet: ip.addr stands for the source and the destination address, tcp.port for both ports. A test with == is true if any occurrence matches, which is why tcp.port == 8080 keeps both directions while tcp.dstport == 8080 keeps only the client's half.

Not-equal is where old advice goes wrong. Since Wireshark 3.6, a != b means that every occurrence must differ, the negation of == for packets that have the field (3.6 release notes), so ip.addr != X hides every packet to or from X. Before 3.6 it meant "any occurrence differs", true for almost every packet, and guides from that era said never to use it. The old meaning is still available as any_ne, or since Wireshark 4.0 !== (wireshark-filter(4), 4.0 release notes); 3.6, the version Ubuntu 22.04 packages, rejects !== and spells it ~=. Frames without the field are where != and !(...) part: any comparison on a missing field is false, so ip.addr != X also hides ARP, while !(ip.addr == X) keeps it. The block counts the frames each filter keeps; tshark -Y applies a display filter exactly as the filter bar does.

Terminal · Count the frames that each display filter keeps
for f in "tcp.dstport == 8080" "tcp.port == 8080" "ip.addr != 203.0.113.11" \
  "ip.addr !== 203.0.113.11" "!(ip.addr == 203.0.113.11)" "arp"; do
  printf '%-28s %s frames\n' "$f" "$(tshark -r mixed.pcap -Y "$f" | wc -l)"
done
tshark -r mixed.pcap | wc -l
Expected output (illustrative: counts vary by a few frames between runs; the differences do not)
tcp.dstport == 8080          51 frames
tcp.port == 8080             99 frames
ip.addr != 203.0.113.11      78 frames
ip.addr !== 203.0.113.11     103 frames
!(ip.addr == 203.0.113.11)   82 frames
arp                          4 frames
107

Check the arithmetic in the output shown, because it proves the semantics. The file has 107 frames. 203.0.113.11 was in 25 of them (the IPv4 table above), and 4 are ARP. !(ip.addr == ...) keeps 107 − 25 = 82. != keeps 82 − 4 = 78: the same minus the frames without an IP header. !== keeps 107 − 4 = 103, because every IP packet has at least one address that is not .11, so it hides nothing but ARP. And tcp.dstport == 8080 keeps 51 of the 99 frames on port 8080, roughly half, because it sees only one direction.

04. Step 3: Find the error and follow its stream

Filtering on the HTTP status is the direct way in: http.response.code >= 500 matches any server error, not only the one you heard about. It lands on the response, so the command also prints tcp.stream, Wireshark's index of the connection, and http.request_in, the frame of the matching request. In the window, right-click the response and choose Follow > TCP Stream (User's Guide, section 7.2): Wireshark sets the filter tcp.stream eq 5 and shows that connection's bytes in order, client and server in different colours. -z follow,tcp,ascii,5 prints the same view.

Terminal · Locate server errors, then reassemble stream 5
tshark -r mixed.pcap -Y "http.response.code >= 500" -T fields \
  -e frame.number -e tcp.stream -e http.response.code -e http.request_in
tshark -r mixed.pcap -q -z follow,tcp,ascii,5
Expected output (illustrative: frame numbers, ports and the Date header vary)
72    5    503    68

===================================================================
Follow: tcp,ascii
Filter: tcp.stream eq 5
Node 0: 203.0.113.10:46180
Node 1: 203.0.113.50:8080
89
GET /checkout HTTP/1.1
Host: 203.0.113.50:8080
User-Agent: curl/7.81.0
Accept: */*


    162
HTTP/1.0 503 Service Unavailable
Server: BaseHTTP/0.6 Python/3.10.12
Date: Fri, 27 Nov 2026 04:05:44 GMT
Content-Type: application/json
Content-Length: 30


    30
{"error": "inventory timeout"}
===================================================================

The response is frame 72, its request frame 68, and the stream reads like a transcript: 89 bytes of request, 162 bytes of response headers and a 30-byte body naming the cause, {"error": "inventory timeout"}. A dependency timed out; the network delivered every byte, and the connection then closed normally with FIN segments.

The stream number belongs to this file: Wireshark numbers TCP connections from 0 in the order it first sees them. The next block keeps only frames 30 onwards and asks again; the same connection, same ports, is now stream 3.

Terminal · The same connection in a shorter file
editcap -r mixed.pcap late.pcap 30-1000
tshark -r late.pcap -Y "http.response.code >= 500" -T fields \
  -e frame.number -e tcp.stream -e tcp.srcport -e tcp.dstport
Expected output (frame, stream, ports)
43    3    8080    46180

05. Step 4: Decode the UDP datagram and its ICMP reply

The telemetry datagram shows how header arithmetic tells you whether a capture is complete. The command prints, for each UDP or ICMP frame, the frame length, IPv4 total and header lengths, the UDP length field, the data length and the ICMP type and code; Wireshark shows these field names in its status bar when you click a field. Then editcap -s 64 writes a copy cut to 64 bytes per frame, as if captured with -s 64.

Terminal · UDP and ICMP header fields, then a truncated copy
tshark -r mixed.pcap -Y "udp or icmp" -T fields -e frame.number -e frame.len \
  -e ip.len -e ip.hdr_len -e udp.length -e data.len -e icmp.type -e icmp.code
editcap -s 64 mixed.pcap mixed64.pcap
tshark -r mixed64.pcap -Y udp -T fields -e frame.len -e frame.cap_len \
  -e udp.length -e data.len
Expected output (frame, frame.len, ip.len, ip.hdr_len, udp.length, data.len, ICMP type, code)
106    80    66    20    46    38
107    108    94,66    20,20    46    38    3    3
80    64    46    22

Read frame 106 from the outside in. The frame is 80 bytes: a 14-byte Ethernet header and a 66-byte IPv4 packet. The IPv4 header is 20 bytes, leaving 46 for UDP, and the UDP length field says 46 too, because it counts its own 8-byte header plus the data, as RFC 768 defines. That leaves 38 bytes of data, exactly the telemetry line the client sent.

Frame 107 is the server's answer: ICMP type 3, code 3 (port unreachable), since nothing listens on UDP port 9999. Its two ip.len values, 94 and 66, show that the ICMP message carries a copy of the offending IP header and the start of its data. In the truncated copy the frame is still 80 bytes on the wire but only 64 were saved: headers intact, 22 of the 38 data bytes left. When frame.cap_len is below frame.len, take sizes from the header length fields and treat the saved bytes as a prefix.

What if checkout moved to HTTPS? Conversations, ip.addr, tcp.port and Follow TCP Stream would still work, but http.response.code would match nothing and the stream would show the ClientHello followed by ciphertext. Reading the HTTP inside needs session keys from an endpoint (such as a client key log file), under the same authorisation as the capture. Windows and retransmissions continue in TCP & UDP.

Terminal · When you have finished with the files, remove the work directory
cd ~ && rm -rf ~/pca-we05
test -d ~/pca-we05 || echo "work directory removed"
Expected output
work directory removed

06. Check your understanding

Practice check · 3 questions

Filters, streams and header fields

Predict what Wireshark will show before you check the options.

Q1. You find a failing request at `tcp.stream eq 5` in your capture and send that filter to a colleague. They apply it to a capture of the same incident taken on another sensor and see an unrelated connection. Why?
Q2. An old runbook says `ip.addr != 198.51.100.5` cannot hide that host. In Wireshark 4.6 you apply it to a capture with traffic between `198.51.100.5` and other hosts, plus some ARP frames. Which frames stay on screen?
Q3. A trace taken with `-s 96` shows a UDP datagram with `frame.len` 1042, `frame.cap_len` 96 and `udp.length` 1008. A developer counts the 54 data bytes Wireshark shows and says the agent only sends tiny messages. What do the fields say?
Practice only: not graded, not saved, not evidence.

07. Apply it

Open the capture you made for the skill practice in the previous lab (a DNS lookup and an HTTPS request). Without help from this page, list its conversations at the IP, UDP and TCP layers, write one display filter that shows only the DNS exchange and one that shows only the TLS handshake (try tls.handshake.type == 1), follow the TCP stream of the HTTPS connection and explain what you can and cannot read, and decode one DNS frame from frame length to UDP data length. Record frame numbers for each answer.

From here, IPv4 Addressing & Subnetting explains the addresses you have been reading, and Network Troubleshooting puts captures into a wider diagnostic method.

08. Review prompt

Explain, without looking back, the path from an unfamiliar capture to one failing request: what the conversation view tells you, how ==, !=, !== and !(... == ...) treat a field that appears twice or not at all, what Follow TCP Stream reassembles and why its stream number cannot be shared, and how to tell from frame.len, frame.cap_len, the IP total length and the UDP length whether you are looking at a whole datagram.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check