/*
* tcpsnoop.d - snoop TCP network packets by process.
* Written using DTrace (Solaris 10 3/05)
*
* This analyses TCP network packets and prints the responsible PID and UID,
* plus standard details such as IP address and port. This captures traffic
* of newly created TCP connections that were established while this program
* was running. It can help identify which processes is causing TCP traffic.
*
* WARNING: This script may only work on Solaris 10 3/05, since it uses the
* fbt provider to trace the raw operation of a specific version of the kernel.
* In the future, a 'stable' network provider should exist which will allow
* this to be written for that and subsequent versions of the kernel. In the
* meantime, check for other versions of this script in the /Net directory,
* and read the Notes/ALLfbt_notes.txt for more background on fbt.
*
* $Id: tcpsnoop.d 69 2007-10-04 13:40:00Z brendan $
*
* USAGE: tcpsnoop.d
*
* FIELDS:
* UID user ID
* PID process ID
* CMD command
* LADDR local IP address
* RADDR remote IP address
* LPORT local port number
* RPORT remote port number
* DR direction
* SIZE packet size, bytes
*
* SEE ALSO: snoop -rS
*
* COPYRIGHT: Copyright (c) 2005, 2006 Brendan Gregg.
*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* See the License for the specific language governing permissions
* and limitations under the License.
*
* CDDL HEADER END
*
* Author: Brendan Gregg [Sydney, Australia]
*
* TODO: IPv6
*
* 09-Jul-2004 Brendan Gregg Created this.
* 12-Mar-2005 " " Changed probes, size info now printed.
* 02-Jul-2005 " " Many more probes. Renamed "tcpsnoop.d".
* 03-Dec-2005 " " Fixed tcp_accept_finish bug, now 100% correct
* execname. Thanks Kias Belgaied for expertise.
* 20-Apr-2006 " " Fixed SS_TCP_FAST_ACCEPT bug in build 31+.
* 20-Apr-2006 " " Last update.
*/
#include <sys/byteorder.h>
/*
* Print header
*/
{
/* print main headers */
printf("%5s %6s %-15s %5s %2s %-15s %5s %5s %s\n",
"UID", "PID", "LADDR", "LPORT", "DR", "RADDR", "RPORT",
"SIZE", "CMD");
}
/*
* TCP Process inbound connections
*
* 0x00200000 has been hardcoded. It was SS_TCP_FAST_ACCEPT, but was
* renamed to SS_DIRECT around build 31.
*/
{
}
{
}
{
}
{
}
/*
* TCP Process outbound connections
*/
{
}
/*
* TCP Data translations
*/
{
/* fetch ports */
#if defined(_BIG_ENDIAN)
#else
#endif
/* fetch IPv4 addresses */
/* convert type for use with lltostr() */
/* stringify addresses */
/* fix direction and save values */
/* all systems go */
}
/*
* TCP Clear connp
*/
{
/* Q_TO_CONN */
}
/*
* TCP Process "port closed"
*/
{
/* split addresses */
/* stringify addresses */
}
/*
* TCP Fetch "port closed" ports
*/
{
#if defined(_BIG_ENDIAN)
#else
#endif
}
/*
* TCP Print "port closed"
*/
{
printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n",
printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n",
}
/*
* TCP Process Write
*/
{
}
{
/* follow inetd -> in.* transitions */
}
/*
* TCP Process Read
*/
{
}
{
/* follow inetd -> in.* transitions */
}
/*
* TCP Complete printing outbound handshake
*/
{
/* this packet occured before connp was fully established */
printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n",
}
/*
* TCP Complete printing inbound handshake
*/
{
/* these packets occured before connp was fully established */
printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n",
printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n",
printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n",
}
/*
* Print output
*/
{
/* print output line */
printf("%5d %6d %-15s %5d %2s %-15s %5d %5d %s\n",
}
/*
* TCP Clear connect variables
*/
{
}
/*
* TCP Clear r/w variables
*/
{
}