Network Layer Protocol Statistics

The network layer of the TCP/IP stack, as you have already seen in Chapter 1, is responsible for the packetization, addressing, and routing of data. By using the IPHelper library, you can query both the ICMP and IP protocols for statistical information regarding the data packets and messages that the network adapter has received.

Internet Control Message Protocol (ICMP)

Because ICMP is a "support" protocol, it is generally used for sending informational, control, and error messages between two network endpoints. To find out more information about the ICMP messages that a device is sending and receiving, you can use the GetIcmpStatistics() function:

 DWORD GetIcmpStatistics(MIB_ICMP *pStats); 

When you call this function, it will return to you a MIB_ICMP structure in the variable that you pointed to using the pStats parameter. The structure is defined as follows:

 typedef struct _MIB_ICMP {    MIBICMPINFO stats; } MIB_ICMP,*PMIB_ICMP; 

The MIB_ICMP structure simply contains another structure that is defined as follows:

 typedef      struct _MIBICMPINFO {    MIBICMPSTATS icmpInStats;    MIBICMPSTATS icmpOutStats; } MIBICMPINFO; 

The MIBICMPINFO structure contains two additional MIBICMPSTATS structures containing the statistical data for ICMP. The first field, icmpInStats, contains information about incoming messages, whereas the icmpOutStats field is for outgoing messages. The MIBICMPSTATS structure is defined as follows:

 typedef struct _MIBICMPSTATS {    DWORD dwMsgs;    DWORD dwErrors;    DWORD dwDestUnreachs;    DWORD dwTimeExcds;    DWORD dwParmProbs;    DWORD dwSrcQuenchs;    DWORD dwRedirects;    DWORD dwEchos;    DWORD dwEchoReps;    DWORD dwTimestamps;    DWORD dwTimestampReps;    DWORD dwAddrMasks;    DWORD dwAddrMaskReps; } MIBICMPSTATS; 

Table 3.4 describes the fields of the MIBICMPSTATS structure.

Table 3.4. MIBICMPSTATS Field Descriptions

Member

Description

dwMsgs

The number of messages sent or received.

dwErrors

The number of errors sent or received.

dwDestUnreachs

The number of messages that were marked as destination unreachable.

dwTimeExcds

The number of TTL-exceeded messages that were sent or received. See the SetIpTTL() function for more information.

dwParmProbs

The number of parameter problem messages sent or received.

dwSrcQuenchs

The number of source "quench" messages sent or received.

dwRedirects

The number of redirect messages sent or received.

dwEchos

The number of echo request messages sent or received.

dwEchoReps

The number of echo reply messages sent or received.

dwTimestamps

The number of timestamp request messages sent or received.

dwTimestampReps

The number of timestamp reply messages sent or received.

dwAddrMasks

The number of address mask request messages sent or received.

dwAddrMaskReps

The number of address mask reply messages sent or received.

Internet Protocol (IP)

The Internet Protocol (IP) is the hardware-independent method that TCP/IP uses for the fragmentation and reassembly of data packets (known as datagrams). You can use IPHelper to find out more information about the current IP status by calling GetIpStatistics():

 DWORD GetIpStatistics(MIB_IPSTATS *pStats); 

The only parameter you need to pass in, pStats, is a pointer to a MIB_IPSTATS structure that will receive the statistical data when the function returns. The MIB_IPSTATS structure is defined as follows:

 typedef struct _MIB_IPSTATS {    DWORD dwForwarding;    DWORD dwDefaultTTL;    DWORD dwInReceives;    DWORD dwInHdrErrors;    DWORD dwInAddrErrors;    DWORD dwForwDatagrams;    DWORD dwInUnknownProtos;    DWORD dwInDiscards;    DWORD dwInDelivers;    DWORD dwOutRequests;    DWORD dwRoutingDiscards;    DWORD dwOutDiscards;    DWORD dwOutNoRoutes;    DWORD dwReasmTimeout;    DWORD dwReasmReqds;    DWORD dwReasmOks;    DWORD dwReasmFails;    DWORD dwFragOks;    DWORD dwFragFails;    DWORD dwFragCreates;    DWORD dwNumIf;    DWORD dwNumAddr;    DWORD dwNumRoutes; } MIB_IPSTATS, *PMIB_IPSTATS; 

MIB_IPSTATS provides a lot of interesting information regarding incoming and outgoing datagrams. Table 3.5 describes the fields of MIB_IPSTATS.

The dwDefaultTTL value for a datagram defines how long an IP packet can "live" on the network. As a packet travels across the Internet, TCP/IP requires each router it crosses to decrement the TTL field of the datagram's header. If the TTL field reaches 0 before it gets to its destination address, TCP/IP destroys the packet and notifies the sending host through an ICMP message.

To turn IP forwarding (also known as routing) on or off, or to change the default time to live (TTL) for a datagram, you can use the SetIpStatistics() function:

 DWORD SetIpStatistics(MIB_IPSTATS *pIpStats); 

The pIpStats parameter is a pointer to a MIB_IPSTATS structure that has either the dwForwarding or the dwDefaultTTL field completed. If you want to preserve the default value for either, you set the field to either MIB_USE_CURRENT_TTL or MIB_USE_CURRENT_FORWARDING.

Table 3.5. MIB_IPSTATS Field Descriptions

Member

Description

dwForwarding

Specifies whether IP forwarding is enabled or not.

dwDefaultTTL

Specifies the time to live (TTL) for datagrams that are sent from the device. This value can be changed using the SetIpTTL function.

dwInReceives

The number of datagrams received.

dwInHdrErrors

The number of datagrams that have header errors.

dwInAddrErrors

The number of datagrams that have been received with address errors.

dwForwDatagrams

The number of datagrams forwarded.

dwInUnknownProtos

The number of datagrams received with an unknown protocol.

dwInDiscards

The number of datagrams received that were discarded.

dwInDelivers

The number of datagrams received that were delivered.

dwOutRequests

The number of datagrams that IP has been requested to transmit. This does not include forwarded datagrams.

dwRoutingDiscards

The number of outgoing datagrams that were discarded.

dwOutDiscards

The number of datagrams sent that were discarded.

dwOutNoRoutes

The number of datagrams that did not have a routing destination.

dwReasmTimeout

The maximum amount of time that a fragmented datagram needs to arrive.

dwReasmReqds

The number of datagrams that require reassembly.

dwReasmOks

The number of datagrams that were successfully reassembled.

dwReasmFails

The number of datagrams that could not be reassembled.

dwFragOks

The number of datagrams that were successfully fragmented.

dwFragFails

The number of datagrams that could not be fragmented.

dwFragCreates

The number of datagram fragments created.

dwNumIf

The number of IP interfaces on the device.

dwNumAddr

The number of IP addresses on the device.

dwNumRoutes

The number of routes in the IP routing table.

If you only need to configure IP's TTL value, you can also call SetIpTTL():

 DWORD SetIpTTL(UINT nTTL); 

The only parameter, nTTL, is the new time-to-live value for datagrams on the device.



Pocket PC Network Programming
Pocket PC Network Programming
ISBN: 0321133528
EAN: 2147483647
Year: 2005
Pages: 90

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net