📄 dhcp.h
字号:
/** Copyright (c) 1998-2001 by NETsilicon Inc.** This software is copyrighted by and is the sole property of* NETsilicon. All rights, title, ownership, or other interests* in the software remain the property of NETsilicon. This* software may only be used in accordance with the corresponding* license agreement. Any unauthorized use, duplication, transmission,* distribution, or disclosure of this software is expressly forbidden.** This Copyright notice may not be removed or modified without prior* written consent of NETsilicon.** NETsilicon, reserves the right to modify this software* without notice.** NETsilicon* 411 Waverley Oaks Road USA 781.647.1234* Suite 227 http://www.netsilicon.com* Waltham, MA 02452 AmericaSales@netsilicon.com*************************************************************************** $Name: Fusion 6.52 Fusion 6.51 $* $Date: 2002/01/16 12:57:47 $* $Source: M:/psisrc/dhcp_cli/incl/rcs/dhcp.h $*************************************************************************** - Revision Log - ** Who When Why** FND 10/19/01 Reduce the ARP_REPLY_TIMEOUT to 1 second.** FND 05/29/02 Add os_printf() prototype so DHCP_DEBUGx works.** FND 10/09/02 Changed 1 bit fields to unsigned to remove* TCS 2.2 compiler warning error. TCS 4.0F does not* issue a warning.*************************************************************************** File Description:* DHCP include file. For use by DHCP library files only.***************************************************************************/#ifndef _DHCP_HDR_#define _DHCP_HDR_#include "select.h"#include "dhcpapi.h"#ifndef NULL#define NULL 0#endif#define TICKS_PER_SEC (1000/MS_PER_TICK) /* ticks per second */#define HTYPE_ETHER 1 /* Hardware type (htype) value of Ethernet */#define DHCP_CACHE_FILE "/var/run/dhcpcd-cache." /* DHCP cache file name */#define PIDFILE "/var/run/dhcpcd-%s.pid"#define HOST_INFO_DIR "/etc/dhcpc"#define HOST_INFO_FILE "hostinfo"#define MAGIC_COOKIE 0x63825363 /* magic cookie in the option field */#define MAGIC_COOKIE_U8 99,130,83,99 /* equiv to MAGIC_COOKIE in dhcp.h */#define ARP_REPLY_TIMEOUT 1 /* timeout for arp reply msg in sec *//* #define ARP_REPLY_TIMEOUT 15 */ /* timeout for arp reply msg in sec */#define F_BROADCAST 0x8000 /* broadcast flag in 'flags' field */#undef NEED_MACBCAST_RESPONSE /* define this if MAC broadcast response * is necessary in receiving DHCPOFFER, * DHCPACK, and DHCPNAK message */#define DEFAULT_LEASE_TIME 180*60 /* default lease time in second */#define INFINITE_LEASE_TIME 0xffffffffL /* infinite lease time */#define N_REXMIT_DISCOVER 4 /* # of rexmit of DHCPDISCOVER msg */#define N_REXMIT_REQUEST 10#define N_REXMIT_REQ_REBOOT 4/* UDP port numbers for DHCP */#define DHCP_SERVER_PORT 67 /* from client to server */#define DHCP_CLIENT_PORT 68 /* from server to client *//* DHCP message OP code */#define BOOTREQUEST 1#define BOOTREPLY 2/* DHCP message type */#define DHCP_DISCOVER 1#define DHCP_OFFER 2#define DHCP_REQUEST 3#define DHCP_DECLINE 4#define DHCP_ACK 5#define DHCP_NAK 6#define DHCP_RELEASE 7#define DHCP_INFORM 8/* DHCP client states */enum { INIT_REBOOT, INIT, INIT_1, REBOOTING, REBOOTING_1, REBOOTING_2, REBOOTING_3, REBOOTING_4, REBOOTING_5, REBOOTING_6, SELECTING, SELECTING_1, SELECTING_2, REQUESTING, REQUESTING_1, REQUESTING_2, REQUESTING_3, REQUESTING_4, REQUESTING_5, BOUND, BOUND_1, RENEWING, RENEWING_1, RENEWING_2, RENEWING_3, REBINDING, REBINDING_1, REBINDING_2, REBINDING_3, REBINDING_4, WAIT_CHK_REXMIT_MSG, RCV_AND_CHECK_DHCP_MSG, DHCP_DELAY, DHCP_WAIT_FOR_ARP, DHCP_MAX_STATES, /* number of states */ EXCEPTION};/* Timeout control */#define INIT_TIMEOUT 0#define NEXT_TIMEOUT 1typedef u8 DHCP_MESSAGE;#define DHCP_OP 0 /* message type, 1 byte */#define DHCP_HTYPE DHCP_OP+1 /* hardware address type, 1 byte */#define DHCP_HLEN DHCP_HTYPE+1 /* hardware address length, 1 byte */#define DHCP_HOPS DHCP_HLEN+1 /* should be zero in client's message, 1 byte */#define DHCP_XID DHCP_HOPS+1 /* transaction id, 4 bytes */#define DHCP_SECS DHCP_XID+4 /* elapssed time in sec. from trying to boot, 2 bytes */#define DHCP_FLAGS DHCP_SECS+2 /* 2 bytes */#define DHCP_CIADDR DHCP_FLAGS+2 /* (previously allocated) client IP address, 4 bytes */#define DHCP_YIADDR DHCP_CIADDR+4 /* 'your' client IP address, 4 bytes */#define DHCP_SIADDR DHCP_YIADDR+4 /* should be zero in client's messages, 4 bytes */#define DHCP_GIADDR DHCP_SIADDR+4 /* should be zero in client's messages, 4 bytes */#define DHCP_CHADDR DHCP_GIADDR+4 /* client's hardware address, 16 bytes */#define DHCP_SNAME DHCP_CHADDR+16 /* server host name, null terminated string, 64 bytes */#define DHCP_FILE DHCP_SNAME+64 /* boot file name, null terminated string, 128 bytes */#define DHCP_OPTIONS DHCP_FILE+128 /* message options, MAXOPT bytes */#define SIZEOF_DHCP_MESSAGE (DHCP_OPTIONS + MAXNOPT)/* Option index in the DHCP message option field */enum { OmsgType = 0, /* DHCP message type */ OserverInaddr = 1, /* DHCP server IP address */ OleaseTime = 2, /* lease time */ OrenewalTime = 3, /* renewal time */ OrebindTime = 4, /* rebind time */ Onetmask = 5, /* netmask */ ObcastInaddr = 6, /* broadcast address */ OdhcpMessage = 7, /* DHCP message */ OdhcpClassId = 8, /* DHCP class identifier */ OntpServer = 9, /* NTP server's IP address */ OtimeServer = 10, /* time server's IP address */ Odns = 11, /* Domain Name Server's IP address */ OlprServer = 12, /* lpr server's IP address */ OhostName = 13, /* hostname */ OdomainName = 14, /* domainname */ OnisDomName = 15, /* NIS domainname */ Orouter = 16, /* routers on the client's subnet */ N_SUPPORT_OPTIONS = 17 /* number of supported options */};#define ETH_P_ARP 0x0806#define ETH_P_IP 2048#define ARPOP_REQUEST 1#define ARPOP_REPLY 2#define ARPHRD_ETHER 1 #define IFNAMSIZ 16#define isClassA(_addr) (!(_addr & htonl(0x80000000L)))#define isClassB(_addr) ((_addr & htonl(0xc0000000L)) == htonl(0x80000000L))#define isClassC(_addr) ((_addr & htonl(0xe0000000L)) == htonl(0xc0000000L))typedef struct IF_INFO { char ifname[IFNAMSIZ]; int current_state; /* current state */ int previous_state; /* previous state */ int execution_state; /* current execution state */ int state_1; /* saved states */ int state_2; int state_3; int state_4; unsigned suspend:1, /* suspend execution of state machine */ arp_check:1, /* state machine waiting for ARP */ arp_received:1, /* ARP received from specified IP */ first_bind_request:1; /* first IP bind request */ u32 second_timer; /* timer (ticks), counts to 1 second */ u32 timer; /* timer (seconds) (counts down) */ void (*p_initialize_callback)(DHCP_USER_INFO *); void (*p_bind_fail_callback)(DHCP_USER_INFO *); void (*p_lease_bound_callback)(DHCP_USER_INFO *); void (*p_lease_renew_callback)(DHCP_USER_INFO *); void (*p_lease_expire_callback)(DHCP_USER_INFO *); netdev *ndp; /* interface's network device ptr. */ u32 addr; /* network byte order */ u32 mask; /* network byte order */ u32 bcast; /* network byte order */ u8 haddr[6]; /* interface's hardware address */ u16 flags; int Ssend; /* socket fd for send */ int Srecv; /* socket fd for receive */ int retry; /* retry counter */ sel select_array[1]; /* added for nselect change */ struct in_sockaddr sock_addr; u32 waitMsgType; /* type of message(s) waited on */ /* local state machine function vars */ int nextState; u32 timeout; u32 sendTime; u32 prevTime; u32 next_timeout; u32 ip_address; u32 arp_ip_address; /* configuration information */ u32 ServerInaddr; /* Server's IP address (network byte order) */ u32 LeaseTime; /* lease time (network byte order) */ u32 RenewTime; /* T1 time (network byte order) */ u32 RebindTime; /* T2 time (network byte order) */ u32 ReqSentTime; /* time when DHCPREQUEST message is sent */ u32 SuggestLeaseTime; /* lease time suggested by the user */ DHCP_USER_INFO *p_user_info; void *p_next; /* pointer to next interface in list */ DHCP_MESSAGE DhcpMsgSend[SIZEOF_DHCP_MESSAGE]; /* DHCP message to send */ DHCP_MESSAGE DhcpMsgRecv[SIZEOF_DHCP_MESSAGE]; /* DHCP message received */ u8 *OptPtr[MAXNOPT]; /* array of ptrs to DHCP option element */ u8 *OptOffer[MAXNOPT]; /* same as above in DHCPOFFER msg */ } IF_INFO;/* global variables in if.c *//*extern IF_INFO Ifbuf;*/#if !defined(errno) extern int errno;#endif extern int DebugFlag;/* DHCP option type */enum { OT_STRING = 1, /* string */ OT_ADDR = 2 /* addresses */};/************************************************************************* ** FUNCTION PROTOTYPES ** *************************************************************************//* dhcparp.c */extern int DHCP_WaitForArp (IF_INFO *);extern int arp_wakeup(void *p_param);extern int setupSendArp(int opcode, u32 target_ip, u8 *p_target_mac, u32 source_ip, u8 *p_source_mac, netdev *ndp, long timeout, IF_INFO *, int, int);extern void DHCP_arp_check(u8 *p_source_ip);extern int arpCheck(u32 inaddr, IF_INFO *ifbuf, long timeout, int pass_state, int fail_state);extern void sendArpReply(u8 *thaddr, u32 tinaddr, IF_INFO *ifbuf);/* client.c */extern void DHCP_Timer(void);extern void DHCP_Task(u32 parameters);extern void mkDhcpDiscoverMsg(u8 *haddr, DHCP_MESSAGE *msg, IF_INFO *);extern void mkDhcpRequestMsg(int flag, u32 serverInaddr, u32 leaseTime, u32 xid, u32 ciaddr, DHCP_MESSAGE *msg, IF_INFO *);extern void mkDhcpDeclineMsg(int flag, u32 serverInaddr, u32 ciaddr, DHCP_MESSAGE *msg);extern void sendDhcpDecline(IF_INFO *, int flag, u32 serverInaddr, u32 ciaddr);extern int setDhcpInfo(IF_INFO *, u8 *optp[]);extern void setupIfInfo(IF_INFO *ifbuf, u32 yiaddr, u8 *optp[]);extern void initHost(IF_INFO *ifbuf, u32 yiaddr);extern long getNextTimeout(IF_INFO *p_info, int flag);extern long random(void);extern void print_mac(char *p_string, a48 *p_a48);extern void print_ip(char *p_string, u32 *p_u32);extern u32 os_rand(void);/* hostinfo.c */extern void setupOptInfo(u8 *dest[], const u8 *src[]);extern void freeOptInfo(u8 *optp[]);extern void saveHostInfo(const u8 *optp[]);/* if.c */extern void ifReset(IF_INFO *);extern void ifDown (IF_INFO *);extern void ifUp(IF_INFO *);extern u32 getNaturalMask(u32 inaddr);extern u32 getNaturalBcast(u32 inaddr);/* options.c */extern void getOptions(u8 *optp[], DHCP_MESSAGE *msg);extern int parseDhcpMsg(IF_INFO *, u8 *optp[], DHCP_MESSAGE *msg);/* socketif.c */extern void setSockAddrIn(u16 port, u32 inaddr, struct in_sockaddr *insaddr);extern void DhcpOpenSocket(struct in_sockaddr *addr, IF_INFO *);extern int DhcpSendTo(int fd, char *buf, int buf_len, int flags, saddr *to, int tolen, int *errp);extern void DhcpCloseSocket(IF_INFO *);extern int setup_rcvAndCheckDhcpMsg(IF_INFO *, u32, int, int);extern int rcvAndCheckDhcpMsg(IF_INFO *);extern int setup_waitChkReXmitMsg(IF_INFO *, int, int, int);extern int waitChkReXmitMsg(IF_INFO *);extern int waitChkReXmitMsg_1(IF_INFO *);extern int waitChkReXmitMsg_2(IF_INFO *);extern void setWaitMsgType(int type, u32 *ptype);#ifdef DHCP_DEBUG#ifndef os_printfimport void os_printf(char * msg,...);#endif#define DHCP_DEBUG0(s) os_printf(s)#define DHCP_DEBUG1(s,x) os_printf(s,x)#define DHCP_DEBUG2(s,x,y) os_printf(s,x,y)#define DHCP_DEBUG3(s,x,y,z) os_printf(s,x,y,z)#define DHCP_DEBUG4(s,w,x,y,z) os_printf(s,w,x,y,z)#else#define DHCP_DEBUG0(s)#define DHCP_DEBUG1(s,x)#define DHCP_DEBUG2(s,x,y)#define DHCP_DEBUG3(s,x,y,z)#define DHCP_DEBUG4(s,w,x,y,z)#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -