===================================================================== DHCP Client Demon and Library on Win32 WinPcapDhcpCD http://www.kobore.net/soft/winpcapdhcpcd/dhcpcd.txt ver 0.2 2002/04/12 ver 0.1 2002/02/14 Tomoichi Ebata E-mail:See http://www.kobore.net/mailAddress.gif http://www.kobore.net/ This product includes software developed by the Politecnico di Torino, and its contributors. http://netgroup-serv.polito.it/winpcap/ ==================================================================== This software "WinPcapDhcpCD" uses "WinPcap: the Free Packet Capture Architecture for Windows" http://netgroup-serv.polito.it/winpcap/ developed by developed by the Politecnico di Torino, and its contributors. I really appriciate the efforts of WinPcap developers and supporters. 0. History ~~~~~~~~~~ ver 0.2 2002/04/12 When a DHCP sends reply messages quickly, WinPcapDhcpCD drops them, so another packet receiver thread is added. ver 0.1 2002/02/14 - The first release 1. Copyright ~~~~~~~~~~~~ Copyright (c) 2002,2003,2004,2005 Tomoichi Ebata. All rights reserved. "WinPcapDhcpCD" is free software; You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. "WinPcapDhcpCD" is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 2. What is "WinPcapDhcpCD" ? ~~~~~~~~~~~~~~~~~~~~~~~~~~ WinPcapDhcpCD is a DHCP client demon library that works on Windows OS(NT and 2000). WinPcapDhcpCD is based on "WinPcap" that is developed by the Politecnico di Torino, and its contributors. The purpose of this library is to get more than one IP addresses in your application program. This library makes a thread to keep the IP addresses by the end of the application program (scope). I refered "Dynamic Host Configuration Protocol (RFC2131)", but the implementation of this library was not perfect in order to make it simple and light. 3. Environment to use "WinPcapDhcpCD" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You need the version 2.2 (or more) WinPcap library. Please download from http://netgroup-serv.polito.it/winpcap/install/default.htm 4. Supported operation system ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WinPcapDhcpCD is available on Windows NT SP5, SP6 and Windows 2000 On Windows 9X,it is not available now, (However it is not difficult to modify it) 5. Method of CDhcpcd class ~~~~~~~~~~~~~~~~~~~~~~~ (1) CDhcpcd::CDhcpcd( char *myNicName, char *dhcpID ) is a constructor. myNicName is a name that can access DHCP server. (e.g "\\Device\\Packet_E100B1") Please check the accurate name by pipconfig.exe http://www.kobore.net/soft/pipmasq/pipconfig.exe dhcpID is a string within 255 characters. If you want to get more than one IP address from DHCP server in your program, you should use different IDs (e.g. "dhcpid001","dhcpid002") (2) CDhcpcd::~CDhcpcd(void) is a destructor. (3) bool CDhcpcd::isValid(void) returns true if the instanciation of CDhcpcd class is successed. (4) CDhcpcd::start( struct dhcpGetInfo *_dhcpGetInfo ) gets IP address and other information by the following structure from DHCP server. struct dhcpGetInfo { __u32 xid; __u32 yourClientIPAddress; __u32 nextServerIPAddress; unsigned char subnetMask[4]; unsigned char defaultGateway[4]; unsigned char dns[4]; unsigned char domainName[255]; unsigned char leaseTime[4]; unsigned char dhcpMessageType[1]; unsigned char dhcpServerIdentifier[4]; __u32 dhcpLeaseTime; __u32 dhcpT1value; __u32 dhcpT2value; bool dhcpDemonStatus; }; The format of all the above information of the structure is network byte order style, so you should change the proper data type in your program.(See the following sample program) There is no way to get another information (for example, NIS server IP address or NTP server IP address). (5) bool CDhcpcd::status( struct dhcpGetInfo *_dhcpGetInfo ) gets IP address and other information by the following structure from DHCP client demon that this library provides. (6) bool CDhcpcd::end(void) terminates the instance of CDhcpcd class. This method is called when the program counter goes out the scope, so you don't have to write this method in your program. 6. Others ~~~~~~~~~ If you fail to make the constructor, all methods don't work later. Please use CDhcpcd::isValid() if you succeed in making the instance. 7. Sample code ~~~~~~~~~~~~~~ #include "dhcpcd.h" bool rev_inet_addr(__u32 netByteIPAddr32, char *dotIP) { memset(dotIP, 0, 16); struct in_addr addr; addr.s_addr = netByteIPAddr32; memcpy(dotIP, inet_ntoa(addr), 16); return true; } bool printInfo(struct dhcpGetInfo *_dhcpGetInfo) { printf("DefaultGateway\t%u.%u.%u.%u\n", (unsigned char *)_dhcpGetInfo->defaultGateway[0], (unsigned char *)_dhcpGetInfo->defaultGateway[1], (unsigned char *)_dhcpGetInfo->defaultGateway[2], (unsigned char *)_dhcpGetInfo->defaultGateway[3] ); printf("dhcpLeaseTime\t%d\n",_dhcpGetInfo->dhcpLeaseTime); printf("DomainNameServer\t%u.%u.%u.%u\n", (unsigned char *)_dhcpGetInfo->dns[0], (unsigned char *)_dhcpGetInfo->dns[1], (unsigned char *)_dhcpGetInfo->dns[2], (unsigned char *)_dhcpGetInfo->dns[3] ); printf("domainName\t%s\n",_dhcpGetInfo->domainName); printf("xid\t%d\n", _dhcpGetInfo->xid); char ip[16]; rev_inet_addr(_dhcpGetInfo->yourClientIPAddress, ip); printf("yourClientIPAddress\t%s\n", ip); rev_inet_addr(_dhcpGetInfo->nextServerIPAddress, ip); printf("nextServerIPAddress\t%s\n", ip); return true; } void main(void) { CDhcpcd _dhcpcd("\\Device\\Packet_FA311ND43", "ebata"); struct dhcpGetInfo _dhcpGetInfo; memset(&_dhcpGetInfo, 0, sizeof(struct dhcpGetInfo)); _dhcpcd.start(&_dhcpGetInfo); printInfo(&_dhcpGetInfo); Sleep(2000); _dhcpcd.status(&_dhcpGetInfo); printInfo(&_dhcpGetInfo); Sleep(2000); _dhcpcd.end(); }