• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Tracking the amount of inbound/outbound network traffic
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Tracking the amount of inbound/outbound network traffic


  • Subject: Re: Tracking the amount of inbound/outbound network traffic
  • From: Quinn <email@hidden>
  • Date: Thu, 12 Jul 2007 11:45:50 +0100

At 11:06 -0400 11/7/07, Simon Raisin wrote:
I'm new to network programming on the Mac. I'd like to create an application (using Objective-C and Cocoa) that would allow me to monitor the amount of network traffic on a given machine. Actually I'm only interested in tracking the _amount_ of data that is sent/received from the internet (anything that occurs locally shouldn't be tracked). I don't care about the content of the data, just the size.

There are a bunch of ways that you might achieve this. I'm assuming you're interested in just the aggregate traffic, not the size of each packet. That is, you more-or-less want to show what Activity Monitor shows.


In that case, you can do what Activity Monitor does. Activity Monitor (actually, the pmTool that's bundled with it) fetches network statistics via libtop. libtop isn't considered an API on Mac OS X, but it is part of Darwin, so you can just look at its code. In general, that's probably not wise, because libtop uses all sorts of scary low-level APIs to do what it does. However, in the case of network information, the interface is pretty clean (it's based on <x-man-page://3/getifaddrs>) and I have no qualms about recommending it.

To that end, take a look at libtop_p_networks_sample in the following file.

<http://www.opensource.apple.com/darwinsource/10.4/top-15/libtop.c>

[This link requires an APSL <http://www.opensource.apple.com/apsl/>
account.]

Make sure to read the comment above libtop_p_networks_sample, which describes some of the edge cases that you might not have considered.

Share and Enjoy
--
Quinn "The Eskimo!"                    <http://www.apple.com/developer/>
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Tracking the amount of inbound/outbound network traffic (From: "Simon Raisin" <email@hidden>)

  • Prev by Date: Re: Well known port typo?
  • Next by Date: tcp checksum calculation incorrect - off by 2
  • Previous by thread: Tracking the amount of inbound/outbound network traffic
  • Next by thread: Well known port typo?
  • Index(es):
    • Date
    • Thread