views:

238

answers:

3

I'm wondering how to go about monitoring network traffic on my Mac. Like the way activity monitor does it, showing the bytes / packets in and out.

I know it's a bit vague, but I'm unsure of the best place to start.

EDIT: I forgot to mention, I'm wanting to do this in code, not use an existing piece of software.

A: 

Use tcpdump for quick-n-dirty low-level command-line monitoring, and wireshark for the kitchen sink.

OTOH, if you just want to know the number of bytes/packets (as opposed to their contents), try (Net Monitor)[http://homepage.mac.com/rominar/net.html], which is commercial, unfortunately.

Marcelo Cantos
He wants to do it in a program, not use a product...
calmh
I wrote my answer before the OP added the qualifier.
Marcelo Cantos
+1  A: 

You may want to look into programming with pcap. That's the library which drives tcpdump.

Josh
Way overkill for getting the number of bytes/packets that passes an interface...
calmh
@calmh: Post your solution as an answer then so he can accept it.
Josh
+1 for pcap if you want to do it in program.
Jack
It's in the question linked in the comment above. No need to repeat what has already been well answered by someone else.
calmh
@calmh But @Tom can't accept a comment as an answer.
Josh
A: 

I just found the open source project, MenuMeters. It's got exactly what I'm looking for.

Tom Irving
you just said that you want to do this in code and not existing tool/software.
Jack
Hence the 'Open Source'.
Tom Irving