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 */ } }