• 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: network traffic statistics
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: network traffic statistics


  • Subject: Re: network traffic statistics
  • From: Peter Sichel <email@hidden>
  • Date: Tue, 27 Jan 2009 19:34:09 -0500

On Jan 27, 2009, at 5:27 PM, Pavel Hlavnicka wrote:

I'm writing an application that should as one of its features show
'network statistic' for a given interface (bound to the airport
mostly)...

could anyone to tell me ONE word bringing me one step further.

I use this in my own IPNetMonitorX:

	NSArray* mibNumber;
	NSData* data;
	int interfaceIndex;

	// call sysctl with NET_RT_IFLIST command to return the interface info
	interfaceIndex = if_nametoindex([bsdName cString]);
	mibNumber = [NSArray arrayWithObjects:
		[NSNumber numberWithInt:CTL_NET],
		[NSNumber numberWithInt:AF_ROUTE],
		[NSNumber numberWithInt:0],
		[NSNumber numberWithInt:AF_INET],
		[NSNumber numberWithInt:NET_RT_IFLIST],
		[NSNumber numberWithInt:interfaceIndex],
		nil];
	data = [self getSysctlParameter:mibNumber];
	// parse the response
	do {
		NSNumber* num;
		struct if_msghdr *ifm;
		if (!data) break;
		ifm = (struct if_msghdr *)[data bytes];
		if (ifm->ifm_type != RTM_IFINFO) {
			NSLog(@"linkStats: unexpected sysctl response");
			break;
		}
		// sent packets
		num = [NSNumber numberWithInt:ifm->ifm_data.ifi_opackets];
		[sentPackets setObjectValue:num];
		// send errors
		num = [NSNumber numberWithInt:ifm->ifm_data.ifi_oerrors];
		[sendErrors setObjectValue:num];
		// receive packets
		num = [NSNumber numberWithInt:ifm->ifm_data.ifi_ipackets];
		[receivePackets setObjectValue:num];
		// receive errors
		num = [NSNumber numberWithInt:ifm->ifm_data.ifi_ierrors];
		[receiveErrors setObjectValue:num];
		// collisions
		num = [NSNumber numberWithInt:ifm->ifm_data.ifi_collisions];
		[collisions setObjectValue:num];
		// dropped
		num = [NSNumber numberWithInt:ifm->ifm_data.ifi_iqdrops];
		[dropped setObjectValue:num];

	} while (false);
}

See "if_var.h" for a list of the interface information available.
You can read more about sysctl in Steven's UNIX Network Programming.

Kind Regards,

- Peter Sichel
  Sustainable Softworks
  http://www.sustworks.com

_______________________________________________
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: 
 >network traffic statistics (From: Pavel Hlavnicka <email@hidden>)

  • Prev by Date: Re: network traffic statistics
  • Next by Date: Custom SSL trust settings
  • Previous by thread: Re: network traffic statistics
  • Next by thread: Custom SSL trust settings
  • Index(es):
    • Date
    • Thread