in reply to Hooking the winsock

Slam dunk: Ethereal does what you want.

But assuming you still need to write your own logging app, check out winpcap, which Ethereal also uses. There's a Perl interface to it on cpan... here

Peace,
-McD