相关函数:getprotobyname, getprotoent, setprotoent, endprotoent
表头文件:#include
函数定义:struct protoent *getprotobynumber(int proto)
函 数说明:getprotobynumber()会返回一个protoent结构,参数proto为欲查询的网络协议编号。此函数会从 /etc/protocols中查找符合条件的数据并由结构protoent返回。 结构protoent定义请参getprotoent()
返回值 :成功则返回protoent结构指印,若有错误或找不到各个符合的数据则返回NULL指针
范例:
/*取得协议编号0到4的协议数据*/
#include
main()
{
int number;
struct protoent *protocol;
for(number&#61;0; number<5; number&#43;&#43;)
{
protocol &#61; getprotobynumber(number);
if(protocol &#61;&#61; (struct protoent * ) NULL) continue;
printf("%2d: %-10s: %-10s\n", protocol->p_proto, protocol->p_name, protocol->p_aliases[0]);
}
}
例如 &#xff1a;6 对应名字是 tcp
17 对应名字是 UDP
struct protoent结构
在snort.c中的函数void InitProtoNames()的作用是取得协议名放在protocol_names[256]
struct protoent {
char * p_name; //名称
char * p_aliases; //别名
short * p_proto; //编号
}
getprotobyname()&#xff1a;依照通讯协定 (protocol) 的名称来获取该通讯协定的其他资料。
格 式&#xff1a; struct protoent * getprotobyname( const char *name );
参 数&#xff1a; name 通讯协定名称
传回值&#xff1a; 成功 - 一指向 struct protoent 的指针
失败 - NULL 说明&#xff1a; 利用通讯协定的名称来得知该通讯协定的别名、编号等资料。
getprotobynumber()&#xff1a;依照通讯协定的编号来获取该通讯协定的其他资料。
格 式&#xff1a; struct protoent * getprotobynumber( int number );
参 数&#xff1a; number 以 host 排列方式的通讯协定编号
传回值&#xff1a; 成功 - 一指向 struct protoent 的指针
失败 - NULL
说明&#xff1a; 利用通讯协定的编号来得知该通讯协定的名称、别名等资料。
另外,:-)
toupper(char c)将字符c转换为大写英文字母。
d &#61; strdup(char * s)复制字符串s到d,返回指向被复制的字符串的指针&#xff0c;所需空间由malloc()分配且可以由free()释放。
阅读(1230)| 评论(0)