ba_get_class_stats() -- retrieve statistics for a given class
#include <netinet/ba_stat.h> int ba_get_class_stats ( const char *interface, const char *classname, ba_class_stats_t *stats );
The function ba_get_class_stats() retrieves statistics information about a given class for a given managed interface. It returns the following information:
Number of packets sent
Number of bytes sent
Number of attempts made to borrow bandwidth
Number of packets dropped
Number of bytes dropped
The function ba_get_class_stats() is passed the following arguments:
|
interface |
Pointer to a character string that contains the name of the managed interface. For example, le0, hme0. To specify the direction for which you want class information, append _in or _out to the interface name. If you do not specify the direction, it is assumed to be _out. |
|
classname |
Pointer to a character string that contains the class name. |
|
stats |
Pointer to a structure of type ba_class_stats_t. This is the buffer into which statistics for the specified class are written. |
Structures of type ba_class_stats_t are defined as follows:
typedef struct {
ba_name_t interface; /* name and direction of the interface */
ba_name_t classname; /* name of the class */
u_int npackets; /* packets sent in this class */
u_int nbytes; /* bytes sent in this class */
u_int borrows; /* # times tried to borrow */
u_int drops; /* packets dropped */
u_int bdrops; /* bytes dropped */
hrtime_t lastseen; /* timestamp of last packet sent */
*/
} ba_class_stats_t;
You must allocate sufficient memory for the buffer, either statically or dynamically. For example:
/* static allocation */
{
class_stats_t stats;
if (ba_get_class_stats("hme0", "root", &stats) != -1) {
printf("Number of bytes sent: %d\n", stats.nbytes);
} else {
/* error handling */
}
}
/* dynamic allocation */
{
class_stats_t *statsp;
statsp = (class_stats_t *) malloc(sizeof class_stats_t);
if (ba_get_class_stats("hme0", "root", statsp) != -1) {
printf("Number of bytes sent: %d\n", statsp->nbytes);
} else {
/* error handling */
}
}
The function ba_get_class_stats() returns 0 on success, and -1 on error.
If an error occurs during a call to ba_get_class_stats(), the variable ba_errno is set to one of the error codes listed in Table 4-2.