Solaris Bandwidth Manager 1.6 の開発

ba_get_class_stats()

名前

ba_get_class_stats() - 指定されたクラスの統計情報を取得します。

形式

#include <netinet/ba_stat.h>

int ba_get_class_stats (
	const char *interface,
	const char *classname,
	ba_class_stats_t *stats
);

説明

ba_get_class_stats() 関数は、指定された管理対象インタフェースの指定されたクラスについての統計情報を取得します。返される情報は次のとおりです。

引数

ba_get_class_stats() 関数には次の引数を渡します。

interface

管理されるインタフェース名が入った文字列を指すポインタ (le0hme0 など)。クラス情報を取得する通信方向を指定するには、インタフェース名に _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 */
	}
}

戻り値

ba_get_class_stats() 関数は、正常に終了した場合には 0、エラー時には -1 を返します。

エラー

ba_get_class_stats() 呼び出しの際にエラーが発生すると、変数 ba_errno表 4-2 に示したエラーコードの 1 つに設定されます。