ba_get_class_stats() 関数には次の引数を渡します。
interface |
管理されるインタフェース名が入った文字列を指すポインタ (le0、hme0 など)。クラス情報を取得する通信方向を指定するには、インタフェース名に _in または _out を追加する。通信方向を省略した場合には、_out が追加されたと見なされる |
classname |
クラス名が入った文字列を指すポインタ |
stats |
ba_class_stats_t 型の構造体を指すポインタ。これは、指定されたクラスの統計情報が書き込まれるバッファーである |
ba_class_stats_t 型の構造体は次のように定義されています。
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; |
バッファーには、静的にあるいは動的に十分なメモリーを割り当てる必要があります。次に例を示します。
/* 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 */ } } |