| 1 |
<?xml version='1.0'?> |
| 2 |
<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [ |
| 3 |
]> |
| 4 |
|
| 5 |
|
| 6 |
<section id="tcpdumplikesect"> |
| 7 |
<title>Monitoring TCP Packets</title> |
| 8 |
<indexterm> |
| 9 |
<primary>script examples</primary> |
| 10 |
<secondary>monitoring TCP packets</secondary> |
| 11 |
</indexterm> |
| 12 |
|
| 13 |
<indexterm> |
| 14 |
<primary>examples of SystemTap scripts</primary> |
| 15 |
<secondary>monitoring TCP packets</secondary> |
| 16 |
</indexterm> |
| 17 |
|
| 18 |
<indexterm> |
| 19 |
<primary>monitoring TCP packets</primary> |
| 20 |
<secondary>examples of SystemTap scripts</secondary> |
| 21 |
</indexterm> |
| 22 |
<indexterm> |
| 23 |
<primary>TCP packets, monitoring</primary> |
| 24 |
<secondary>examples of SystemTap scripts</secondary> |
| 25 |
</indexterm> |
| 26 |
<indexterm> |
| 27 |
<primary>TCP packets, monitoring</primary> |
| 28 |
<secondary>examples of SystemTap scripts</secondary> |
| 29 |
</indexterm> |
| 30 |
<!-- |
| 31 |
<indexterm> |
| 32 |
<primary>script examples</primary> |
| 33 |
<secondary>net/socket.c, tracing functions from</secondary> |
| 34 |
</indexterm> |
| 35 |
|
| 36 |
<indexterm> |
| 37 |
<primary>examples of SystemTap scripts</primary> |
| 38 |
<secondary>net/socket.c, tracing functions from</secondary> |
| 39 |
</indexterm> |
| 40 |
|
| 41 |
<indexterm> |
| 42 |
<primary>net/socket.c, tracing functions from</primary> |
| 43 |
<secondary>examples of SystemTap scripts</secondary> |
| 44 |
</indexterm> |
| 45 |
--> |
| 46 |
|
| 47 |
<para> |
| 48 |
This section illustrates how to monitor TCP packets received by the system. This is useful in |
| 49 |
analyzing network traffic generated by applications running on the system. |
| 50 |
</para> |
| 51 |
|
| 52 |
|
| 53 |
<formalpara id="tcpdumplike"> |
| 54 |
<title>tcpdumplike.stp</title> |
| 55 |
<para> |
| 56 |
<programlisting> <xi:include parse="text" href="../testsuite/systemtap.examples/network/tcpdumplike.stp" xmlns:xi="http://www.w3.org/2001/XInclude" /></programlisting> |
| 57 |
</para> |
| 58 |
</formalpara> |
| 59 |
|
| 60 |
<para> |
| 61 |
While <xref linkend="tcpdumplike"/> is running, it will print out the following information |
| 62 |
about any received TCP packets in real time: |
| 63 |
</para> |
| 64 |
|
| 65 |
<itemizedlist> |
| 66 |
<listitem><para>Source and destination IP address (<command>saddr</command>, |
| 67 |
<command>daddr</command>, respectively)</para></listitem> |
| 68 |
<listitem><para>Source and destination ports (<command>sport</command>, <command>dport</command>, |
| 69 |
respectively)</para></listitem> |
| 70 |
<listitem><para>Packet flags</para></listitem> |
| 71 |
</itemizedlist> |
| 72 |
|
| 73 |
<para> |
| 74 |
To determine the flags used by the packet, <xref linkend="tcpdumplike"/> uses the following |
| 75 |
functions: |
| 76 |
</para> |
| 77 |
|
| 78 |
<itemizedlist> |
| 79 |
<listitem><para><command>urg</command> - urgent</para></listitem> |
| 80 |
<listitem><para><command>ack</command> - acknowledgement</para></listitem> |
| 81 |
<listitem><para><command>psh</command> - push</para></listitem> |
| 82 |
<listitem><para><command>rst</command> - reset</para></listitem> |
| 83 |
<listitem><para><command>syn</command> - synchronize</para></listitem> |
| 84 |
<listitem><para><command>fin</command> - finished</para></listitem> |
| 85 |
</itemizedlist> |
| 86 |
|
| 87 |
<para> |
| 88 |
The aforementioned functions return <command>1</command> or <command>0</command> to |
| 89 |
specify whether the packet uses the corresponding flag. |
| 90 |
</para> |
| 91 |
|
| 92 |
<example id="tcpdumplikeoutput"> |
| 93 |
<title><xref linkend="tcpdumplike"/> Sample Output</title> |
| 94 |
<screen>----------------------------------------------------------------- |
| 95 |
Source IP Dest IP SPort DPort U A P R S F |
| 96 |
----------------------------------------------------------------- |
| 97 |
209.85.229.147 10.0.2.15 80 20373 0 1 1 0 0 0 |
| 98 |
92.122.126.240 10.0.2.15 80 53214 0 1 0 0 1 0 |
| 99 |
92.122.126.240 10.0.2.15 80 53214 0 1 0 0 0 0 |
| 100 |
209.85.229.118 10.0.2.15 80 63433 0 1 0 0 1 0 |
| 101 |
209.85.229.118 10.0.2.15 80 63433 0 1 0 0 0 0 |
| 102 |
209.85.229.147 10.0.2.15 80 21141 0 1 1 0 0 0 |
| 103 |
209.85.229.147 10.0.2.15 80 21141 0 1 1 0 0 0 |
| 104 |
209.85.229.147 10.0.2.15 80 21141 0 1 1 0 0 0 |
| 105 |
209.85.229.147 10.0.2.15 80 21141 0 1 1 0 0 0 |
| 106 |
209.85.229.147 10.0.2.15 80 21141 0 1 1 0 0 0 |
| 107 |
209.85.229.118 10.0.2.15 80 63433 0 1 1 0 0 0 |
| 108 |
[...]</screen> |
| 109 |
</example> |
| 110 |
|
| 111 |
</section> |
| 112 |
|