DHCP.H

 
#ifndef DHCP_H
#define DHCP_H

typedef unsigned char INT8U;
typedef unsigned short int WORD;            // 16-bit(全局)
typedef unsigned long LONG;                // 32-bit(全局)
typedef enum _BOOL { FALSE = 0, TRUE } BOOL;

#define SUCCESS                         (1u)
#define FAIL                           (0u)

#define DHCP_TIMEOUT                    (TICK)(2L * TICK_SECOND)
//#define TRUE        1
//#define FALSE       0

#define DHCP_CLIENT_PORT                (68u)
#define DHCP_SERVER_PORT                (67u)

#define BOOT_REQUEST                    (1u)
#define BOOT_REPLY                      (2u)
#define HW_TYPE                         (1u)
#define LEN_OF_HW_TYPE                  (6u)

#define DHCP_MESSAGE_TYPE               (53u)
#define DHCP_MESSAGE_TYPE_LEN           (1u)

#define DHCP_UNKNOWN_MESSAGE            (0u)

#define DHCP_DISCOVER_MESSAGE           (1u)
#define DHCP_OFFER_MESSAGE              (2u)
#define DHCP_REQUEST_MESSAGE            (3u)
#define DHCP_DECLINE_MESSAGE            (4u)
#define DHCP_ACK_MESSAGE                (5u)
#define DHCP_NAK_MESSAGE                (6u)
#define DHCP_RELEASE_MESSAGE            (7u)

#define DHCP_SERVER_IDENTIFIER          (54u)
#define DHCP_SERVER_IDENTIFIER_LEN      (4u)

#define DHCP_PARAM_REQUEST_LIST         (55u)
#define DHCP_PARAM_REQUEST_LIST_LEN     (2u)
#define DHCP_PARAM_REQUEST_IP_ADDRESS       (50u)
#define DHCP_PARAM_REQUEST_IP_ADDRESS_LEN   (4u)
#define DHCP_SUBNET_MASK                (1u)
#define DHCP_ROUTER                     (3u)
#define DHCP_IP_LEASE_TIME              (51u)
#define DHCP_END_OPTION                 (255u)

//#define HALF_HOUR                       (WORD)((WORD)60 * (WORD)30)
//#define INVALID_UDP_SOCKET      (0xff)
//#define INVALID_UDP_PORT        (0L)
#define SIZE_OF_DHCPMES   548   //标准DHCP报文字节大小

INT8U SizeOfOptionsUsed;    //DHCP报文options字段使用的字节
INT8U SizeOfDHCPMesUsed; //DHCP报文全部字段使用字节长度


typedef enum _SM_DHCP
{
// SM_DHCP_INIT_FIRST_TIME,
    SM_DHCP_INIT,
//    SM_DHCP_RESET_WAIT,
    SM_DHCP_BROADCAST,
    SM_DHCP_DISCOVER,
    SM_DHCP_REQUEST,
    SM_DHCP_BIND,
    SM_DHCP_BOUND,
    SM_DHCP_DISABLED,
} SM_DHCP;
#if !defined(THIS_IS_DHCP)
    extern SM_DHCP smDHCPState;
#endif

typedef union DHCP_STATE
{
    struct
    {
        unsigned char bIsBound : 1;
        unsigned char bOfferReceived : 1;
    } bits;
    INT8U Val;
} DHCP_STATE;
#if !defined(THIS_IS_DHCP)
    extern DHCP_STATE DHCPState;
#endif

 

typedef struct _DHCP_MES
{
    INT8U  op   ;
 INT8U  htype ;
 INT8U  hlen   ;
 INT8U   hops   ;
 INT8U  xid [4];
 INT8U  secs [2];
 INT8U  flags [2];
 INT8U  ciaddr [4];
 INT8U  yiaddr [4];
 INT8U  siaddr [4];
 INT8U  giaddr [4];
 INT8U  chaddr [16];
 INT8U  sname [64];
 INT8U  file [128];
 INT8U       options[312];    //长度不定
}  DHCP_MES;

INT8U UDP_GetDHCPMes;


#define DHCPDisable()       (smDHCPState = SM_DHCP_DISABLED)
#define DHCPIsBound()       (DHCPState.bits.bIsBound)


void DHCP_Task(void);
void DHCP_Reset(void);

#endif


 

root@ImmortalWrt:~# tcpdump -i br-lan arp tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on br-lan, link-type EN10MB (Ethernet), snapshot length 262144 bytes 21:37:22.974416 ARP, Request who-has 192.168.2.47 tell 192.168.2.11, length 46 21:37:23.728505 ARP, Request who-has 192.168.2.16 tell 192.168.2.11, length 46 21:37:23.984477 ARP, Request who-has 192.168.2.47 tell 192.168.2.11, length 46 21:37:24.097443 ARP, Request who-has 192.168.2.204 tell 192.168.2.1, length 46 21:37:24.419089 ARP, Request who-has 192.168.2.164 tell 192.168.2.1, length 46 21:37:25.008510 ARP, Request who-has 192.168.2.47 tell 192.168.2.11, length 46 21:37:25.111376 ARP, Request who-has 192.168.2.204 tell 192.168.2.1, length 46 21:37:25.431614 ARP, Request who-has 192.168.2.164 tell 192.168.2.1, length 46 21:37:26.135719 ARP, Request who-has 192.168.2.204 tell 192.168.2.1, length 46 21:37:26.455742 ARP, Request who-has 192.168.2.164 tell 192.168.2.1, length 46 21:37:26.795248 ARP, Request who-has 192.168.2.74 tell 192.168.2.11, length 46 21:37:27.049590 ARP, Request who-has 192.168.2.179 tell 192.168.2.11, length 46 21:37:27.183999 ARP, Request who-has 192.168.2.204 tell 192.168.2.1, length 46 21:37:27.824556 ARP, Request who-has 192.168.2.74 tell 192.168.2.11, length 46 21:37:27.826488 ARP, Request who-has 192.168.2.164 tell 192.168.2.1, length 46 21:37:28.054472 ARP, Request who-has 192.168.2.30 tell 192.168.2.30, length 46 21:37:28.080542 ARP, Request who-has 192.168.2.179 tell 192.168.2.11, length 46 21:37:28.216214 ARP, Request who-has 192.168.2.204 tell 192.168.2.1, length 46 ^C 18 packets captured 18 packets received by filter 0 packets dropped by kernel root@ImmortalWrt:~#root@ImmortalWrt:~# uci show dhcp dhcp.@dnsmasq[0]=dnsmasq dhcp.@dnsmasq[0].domainneeded='1' dhcp.@dnsmasq[0].boguspriv='1' dhcp.@dnsmasq[0].filterwin2k='0' dhcp.@dnsmasq[0].localise_queries='1' dhcp.@dnsmasq[0].rebind_protection='1' dhcp.@dnsmasq[0].rebind_localhost='1' dhcp.@dnsmasq[0].local='/lan/' dhcp.@dnsmasq[0].domain='lan' dhcp.@dnsmasq[0].expandhosts='1' dhcp.@dnsmasq[0].min_cache_ttl='3600' dhcp.@dnsmasq[0].use_stale_cache='3600' dhcp.@dnsmasq[0].cachesize='8000' dhcp.@dnsmasq[0].nonegcache='1' dhcp.@dnsmasq[0].authoritative='1' dhcp.@dnsmasq[0].readethers='1' dhcp.@dnsmasq[0].leasefile='/tmp/dhcp.leases' dhcp.@dnsmasq[0].nonwildcard='1' dhcp.@dnsmasq[0].localservice='1' dhcp.@dnsmasq[0].dns_redirect='1' dhcp.@dnsmasq[0].ednspacket_max='1232' dhcp.@dnsmasq[0].filter_aaaa='0' dhcp.@dnsmasq[0].filter_a='0' dhcp.@dnsmasq[0].noresolv='0' dhcp.@dnsmasq[0].localuse='1' dhcp.@dnsmasq[0].resolvfile='/tmp/resolv.conf.d/resolv.conf.auto' dhcp.lan=dhcp dhcp.lan.interface='lan' dhcp.lan.start='100' dhcp.lan.limit='150' dhcp.lan.leasetime='12h' dhcp.lan.dhcpv4='server' dhcp.lan.ignore='1' dhcp.wan=dhcp dhcp.wan.interface='wan' dhcp.wan.ignore='1' dhcp.odhcpd=odhcpd dhcp.odhcpd.maindhcp='0' dhcp.odhcpd.leasefile='/tmp/hosts/odhcpd' dhcp.odhcpd.leasetrigger='/usr/sbin/odhcpd-update' dhcp.odhcpd.loglevel='4'
最新发布
03-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值