public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
* tcp connects script
@ 2005-09-07 18:02 Hien Nguyen
  0 siblings, 0 replies; only message in thread
From: Hien Nguyen @ 2005-09-07 18:02 UTC (permalink / raw)
  To: SystemTAP

[-- Attachment #1: Type: text/plain, Size: 367 bytes --]

The attached script monitors the tcp connection to the machine, it will 
pritn out the execname, pid and local port.  To test this script
stap -g tcp_connections

then from another machine start an ssh session on the above machine. The 
out put should looks like this

sshd [2185] 22
:

It also demontrates how to pass a struct pointer to an embeded function.

Hien.

[-- Attachment #2: tcp_connections.stp --]
[-- Type: text/plain, Size: 342 bytes --]

%{
#include <net/tcp.h>
#include <net/ip.h>
%}

function get_local_port:long(sk) 
%{
	unsigned long ptr = (unsigned long) THIS->sk;
	struct inet_sock *inet = (struct inet_sock *) ptr;
	THIS->__retvalue = (long long) inet->num;
%}

probe kernel.function("tcp_accept") {
	print(execname()." [".string(pid())."] ".string(get_local_port($sk)))
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-09-07 18:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-07 18:02 tcp connects script Hien Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).