Re: network traffic statistics
Re: network traffic statistics
- Subject: Re: network traffic statistics
- From: Pavel Hlavnicka <email@hidden>
- Date: Tue, 3 Feb 2009 19:27:36 +0100
thanks this list I've found the solution... followig code is not clean
and elegant but show what I do... the numbers are the same as what
netstat says
#import <net/if.h>
#import <net/if_mib.h>
#import <sys/sysctl.h>
- (void) getBytesIn:(UInt64 *)bytesIn bytesOut:(UInt64 *)bytesOut
forInterface:(NSString *)interfaceName
{
int ifindex = if_nametoindex([interfaceName UTF8String]);
int mibName[6];
mibName[0] = CTL_NET;
mibName[1] = PF_LINK;
mibName[2] = NETLINK_GENERIC;
mibName[3] = IFMIB_IFDATA;
mibName[4] = ifindex;
mibName[5] = IFDATA_GENERAL;
*bytesIn = 0;
*bytesOut = 0;
if (mibName[4] > 0) {
struct ifmibdata if_data;
size_t datalen = sizeof(if_data);
int ret = sysctl(mibName, 6, &if_data, &datalen, NULL, 0);
if (ret == 0) {
*bytesIn = if_data.ifmd_data.ifi_ibytes;
*bytesOut = if_data.ifmd_data.ifi_obytes;
}
}
}
On Tue, Jan 27, 2009 at 11:27 PM, Pavel Hlavnicka
<email@hidden> wrote:
> Dear all,
>
> I'm afraid I'm missing something really obvious, but believe me or not
> I've spent some time on gogole till now.
>
> I'm writing an application that should as one of its features show
> 'network statistic' for a given interface (bound to the airport
> mostly)... nothing perfect, just simple counter for in/out traffic -
> whatever it means - can be protocol dependent or not, TCP/UDP only or
> any packets... really does not matter much. Have checked
> SCNetworkConfiguration.h and did some research for BSD level
> approach... no luck so far...
>
> could anyone to tell me ONE word bringing me one step further.
>
> Thank you very much
>
> Pavel
>
_______________________________________________
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