Statistics of the interface

Hi, All!
I hope you know what does “netstat -i” command in QNX4.25 rtos.
Is there any way to obtain this data from C program?
Some parameters of the interface can be obtained by ioctl().
But especially interesting are ways of reception of interface statistics
(in/out packets, bytes, errors, collisions).

I have found in file <net/if.h> this structure:

struct if_data {
/* generic interface information /
u_char ifi_type; /
ethernet, tokenring, etc. /
u_char ifi_addrlen; /
media address length /
u_char ifi_hdrlen; /
media header length /
u_long ifi_mtu; /
maximum transmission unit /
u_long ifi_metric; /
routing metric (external only) /
u_long ifi_baudrate; /
linespeed /
/
volatile statistics /
u_long ifi_ipackets; /
packets received on interface /
u_long ifi_ierrors; /
input errors on interface /
u_long ifi_opackets; /
packets sent on interface /
u_long ifi_oerrors; /
output errors on interface /
u_long ifi_collisions; /
collisions on csma interfaces /
u_long ifi_ibytes; /
total number of octets received /
u_long ifi_obytes; /
total number of octets sent /
u_long ifi_imcasts; /
packets received via multicast /
u_long ifi_omcasts; /
packets sent via multicast /
u_long ifi_iqdrops; /
dropped on input, this interface /
u_long ifi_noproto; /
destined for unsupported protocol /
struct timeval ifi_lastchange; /
last updated */
};

All these values can be very usefull for me. But I failed to find any function
filling this structure.
Of course, it’s possible to obtain data directly from netstat through pipe.
But I hope this is not unique way.
Any suggestion are welcomed :slight_smile:

Sorry for my english.

Roman [SYSTEMPROM]. The best only for you!

If you go through your sales rep., you can request the source to the
netinfo utility, which will give you the information you require.

Previously, Roman St.Zhavnis wrote in qdn.public.qnx4:

Hi, All!
I hope you know what does “netstat -i” command in QNX4.25 rtos.
Is there any way to obtain this data from C program?
Some parameters of the interface can be obtained by ioctl().
But especially interesting are ways of reception of interface statistics
(in/out packets, bytes, errors, collisions).

I have found in file <net/if.h> this structure:

struct if_data {
/* generic interface information /
u_char ifi_type; /
ethernet, tokenring, etc. /
u_char ifi_addrlen; /
media address length /
u_char ifi_hdrlen; /
media header length /
u_long ifi_mtu; /
maximum transmission unit /
u_long ifi_metric; /
routing metric (external only) /
u_long ifi_baudrate; /
linespeed /
/
volatile statistics /
u_long ifi_ipackets; /
packets received on interface /
u_long ifi_ierrors; /
input errors on interface /
u_long ifi_opackets; /
packets sent on interface /
u_long ifi_oerrors; /
output errors on interface /
u_long ifi_collisions; /
collisions on csma interfaces /
u_long ifi_ibytes; /
total number of octets received /
u_long ifi_obytes; /
total number of octets sent /
u_long ifi_imcasts; /
packets received via multicast /
u_long ifi_omcasts; /
packets sent via multicast /
u_long ifi_iqdrops; /
dropped on input, this interface /
u_long ifi_noproto; /
destined for unsupported protocol /
struct timeval ifi_lastchange; /
last updated */
};

All these values can be very usefull for me. But I failed to find any function
filling this structure.
Of course, it’s possible to obtain data directly from netstat through pipe.
But I hope this is not unique way.
Any suggestion are welcomed > :slight_smile:

Sorry for my english.

Roman [SYSTEMPROM]. The best only for you!







\

“Hugh Brown” <hsbrown@qnx.com> wrote in message
news:Voyager.030526075406.28943A@node90.ott.qnx.com

If you go through your sales rep., you can request the source to the
netinfo utility, which will give you the information you require.

Or you can parse (good old popen) the output of netinfo.

Previously, Roman St.Zhavnis wrote in qdn.public.qnx4:
Hi, All!
I hope you know what does “netstat -i” command in QNX4.25 rtos.
Is there any way to obtain this data from C program?
Some parameters of the interface can be obtained by ioctl().
But especially interesting are ways of reception of interface statistics
(in/out packets, bytes, errors, collisions).

I have found in file <net/if.h> this structure:

struct if_data {
/* generic interface information /
u_char ifi_type; /
ethernet, tokenring, etc. /
u_char ifi_addrlen; /
media address length /
u_char ifi_hdrlen; /
media header length /
u_long ifi_mtu; /
maximum transmission unit /
u_long ifi_metric; /
routing metric (external only) /
u_long ifi_baudrate; /
linespeed /
/
volatile statistics /
u_long ifi_ipackets; /
packets received on interface /
u_long ifi_ierrors; /
input errors on interface /
u_long ifi_opackets; /
packets sent on interface /
u_long ifi_oerrors; /
output errors on interface /
u_long ifi_collisions; /
collisions on csma interfaces /
u_long ifi_ibytes; /
total number of octets received /
u_long ifi_obytes; /
total number of octets sent /
u_long ifi_imcasts; /
packets received via multicast /
u_long ifi_omcasts; /
packets sent via multicast /
u_long ifi_iqdrops; /
dropped on input, this interface /
u_long ifi_noproto; /
destined for unsupported protocol /
struct timeval ifi_lastchange; /
last updated */
};

All these values can be very usefull for me. But I failed to find any
function
filling this structure.
Of course, it’s possible to obtain data directly from netstat through
pipe.
But I hope this is not unique way.
Any suggestion are welcomed > :slight_smile:

Sorry for my english.

Roman [SYSTEMPROM]. The best only for you!








\

“Mario Charest”: news:

“Hugh Brown” <> hsbrown@qnx.com> > wrote in message
news:> Voyager.030526075406.28943A@node90.ott.qnx.com> …
If you go through your sales rep., you can request the source to the
netinfo utility, which will give you the information you require.
Maybe I can request it directly from QSSL? Is here somebody with whom I can

discuss this question?
:slight_smile:

Or you can parse (good old popen) the output of netinfo.
Yes, I’ve already done it. But I’m sure there is another solution.


Roman [SYSTEMPROM]. The best only for you!

“Roman St.Zhavnis” <programmer@crazy.ru> wrote in message
news:bb18g7$3ur$1@inn.qnx.com

“Mario Charest”: news:

“Hugh Brown” <> hsbrown@qnx.com> > wrote in message
news:> Voyager.030526075406.28943A@node90.ott.qnx.com> …
If you go through your sales rep., you can request the source to the
netinfo utility, which will give you the information you require.
Maybe I can request it directly from QSSL? Is here somebody with whom I
can
discuss this question?
:slight_smile:

Or you can parse (good old popen) the output of netinfo.
Yes, I’ve already done it. But I’m sure there is another solution.

Yes but from experience the parsing is actually not a bad solution at all.
The way netinfo actually does it is rather messy (custom message to most
network driver).


Roman [SYSTEMPROM]. The best only for you!

Previously, Roman St.Zhavnis wrote in qdn.public.qnx4:

“Mario Charest”: news:

“Hugh Brown” <> hsbrown@qnx.com> > wrote in message
news:> Voyager.030526075406.28943A@node90.ott.qnx.com> …
If you go through your sales rep., you can request the source to the
netinfo utility, which will give you the information you require.
Maybe I can request it directly from QSSL? Is here somebody with whom I can
discuss this question?
:slight_smile:

Unfortunately not. This has to go through a sales rep.

Or you can parse (good old popen) the output of netinfo.
Yes, I’ve already done it. But I’m sure there is another solution.


Roman [SYSTEMPROM]. The best only for you!
\

Ok. There are some positive results in my investigation of this question.
First, if_data structure is returned as part of message if_msghdr with the
type RTM_IFINFO:
struct if_msghdr {
u_short ifm_msglen; /* to skip over non-understood msgs /
u_char ifm_version; /
future binary compatability /
u_char ifm_type; /
message type /
int ifm_addrs; /
like rtm_addrs /
int ifm_flags; /
value of if_flags /
u_short ifm_index; /
index for associated ifp /
struct if_data ifm_dat /
statistics and other data about if */
};

Second, to receive this message program must register and read a routing
socket:
sock=socket( PF_ROUTE, SOCK_RAW, AF_UNSPEC);

At last, message appear only when something is happened with the interface
:frowning: The Citation:
/* iface going up/down etc. */
Today my task will be to learn what does “etc” mean :slight_smile:


Roman [SYSTEMPROM]. The best only for you!

Good news!
I’ve found the solution! It was suggested on
http://qnx.org.ru/forum/viewtopic.php?topic=1480&forum=11&8 by darkelf.
The main idea:

  1. Request nlist structure from socket manager.
  2. Read address of pointer to the list of ifnet structures.
  3. Read the next ifnet and compare the name of interface you need with the
    name in ifnet.
  4. Read all statistics required from the ifnet structure (tcp/ip 4.25) or from
    the ifnet.if_data structure (tcp/ip 5.0).


Roman [SYSTEMPROM]. The best only for you!