接昨天的dhcp option82 包解析小记 (之一)
解析的原理很简单。
接到dhcp包以后,使用指针跳转到option82的value部分的地址,因为dhcp header是定长的,而option是变长的,因此此过程需要使用遍历,方法很多,不管使用什么方法,找到option82后,得到地址,然后使用强之类型转换转为我们预定义好的结构,然后取出我们所需要的值并传给处理函数。
option 82结构 (思科),参考文档:switch 2950 Configuring DHCP Features
struct dhcp_cisco_option82
{
u_int8_t subop1_type; /*sub option 1:type */
u_int8_t subop1_length; /*sub option 1: length*/
u_int8_t circuit_id;
u_int8_t circuit_length;
u_int16_t vlan;
u_int8_t module;
u_int8_t port;
u_int8_t subop21_type; /*sub option 2:type */
u_int8_t subop2_length; /*sub option 2: length*/
u_int8_t remote_id;
u_int8_t remote_length;
u_int8_t mac[6];
};
类型转换和取值:
char switchmac[20] = {0},vlan[8] = {0},port[12] = {0};
if(info->op82rai)
{
struct dhcp_cisco_option82 *op82 = (dhcp_cisco_option82 *)(info->op82rai);
format(op82->mac,switchmac,0 );
sprintf(vlan,”%u”,ntohs(op82->vlan));
sprintf(port,”%u/%u”,op82->module,(op82->port+1));
}
注:info->op82rai 是指向 [...]
-
关注
-
工具
-
Categories
-
Tags
中秋节 主机 交大 人生 出差 地震 学习 安顺 家 岩山 峨眉山 微距 忆成都 惭愧 感动 成都 月亮 桂林 漓江 联通 衡阳 阳朔 龙芯 龙芯盒子 3G 7230 cdma2000 csdn debian dhcp option82 包解析 dhcp option82 c feed feedsky lighttpd Linux loongson loongson 2F mobile mysql nokia phone php s65 safari,中文bug修复 TD-SCDMA WCDMA -
Recent Comments
-
Archives
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- November 2005
- July 2004