===================================================================== ARP Client Library on Win32 WinPcapArp http://www.kobore.net/soft/winpcaparp/carp.txt ver 0.3 2000/11/20 ver 0.2 2000/08/23 ver 0.1 2000/08/02 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 "WinPcapArp" 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.3 2000/11/20 - Bug fixed(Getting wrong local MAC Address) ver 0.2 2000/08/23 - Changed the name "CArp" into "WinPcapArp" - Modified to be able to get MAC address of localhost - Added new method to use 32bit type IP address ver 0.1 2000/08/02 - The first release 1. Copyright ~~~~~~~~~~~~ Copyright (c) 2000,2001,2002,2003,2004,2005 Tomoichi Ebata. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1 Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer as the first lines of this file unmodified. 2 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY Tomoichi Ebata ``AS IS'' AND ANY EXPRESS ORIMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Tomoichi Ebata BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2. What is "WinPcapArp" ? ~~~~~~~~~~~~~~~~~~~~~~~~~ WinPcapArp is ARP client library that works on Windows OS(NT and 2000). WinPcapArp is based on "WinPcap" that is developed by the Politecnico di Torino, and its contributors. The main purpose of this library is to get a MAC address of the target ethernet NIC with the IP address. 3. Environment to use "WinPcapArp" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ WinPcapArp 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 CArp class ~~~~~~~~~~~~~~~~~~~~~~~ (1) CArp::CArp( const char* srcIPAddr, const char* subnetIPAddr, const char* defaultGWAddr, unsigned long waitTime = ARP_WAIT_TIME // 500 ); srcIPAddr Localhost IP address (e.g. "192.168.0.120") subnetIPAddr Subnet mask (e.g. "255.255.255.0") defaultGWAddr Default gateway IP address (e.g. "192.168.0.1") waitTime Wait time for ARP reply. Default time is 500ms (2) bool CArp::arpSendRecv( const char* ipAddr, char* macAddr ); ipAddr IP address for the target ethernet NIC(input) (e.g. "192.168.0.15") macAddr MAC address of the target ethernet NIC(output) (e.g. "00:50:56:ED:88:34") If there is no target NIC in the subnet network, this method returns the IP address of the default gateway. In case of passing the wait time for ARP reply, CArp::arpSendRecv() returns "false". (3) bool CArp::arpSendRecv( __u32 hostTypeIPAddr32, char* mac_ethAlen ); hostTypeIPAddr32 IP address for the target ethernet NIC (32 bits host byte order)(input) (e.g. "3295805967") macAddr MAC address of the target ethernet NIC(output) (e.g. mac_ethAlen[0] = &00 mac_ethAlen[1] = &50 . . mac_ethAlen[5] = &34 ) If there is no target NIC in the subnet network, this method returns the IP address of the default gateway. In case of passing the wait time for ARP reply, CArp::arpSendRecv() returns "false". (4) char* CArp::getLastMessage() shows the last method result. (5) bool CArp::isArpVaild() checks if CArp instance exists. 6. Others ~~~~~~~~~ If you fail to make the constructor, all methods don't work later. Please use CArp::isArpVaild() if you succeed in making the instance. 7. Sample code ~~~~~~~~~~~~~~ // ArpTest.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include "../Arp.h" void main(void) { WSADATA Data; int status = WSAStartup(MAKEWORD(1,1), &Data); // CArp arp("15.2.117.196","255.255.248.0","15.2.112.1"); // CArp arp("15.2.117.197","255.255.248.0","15.2.112.1"); CArp arp("zen2","255.255.248.0","15.2.112.1"); // CArp arp("192.168.0.2","255.255.255.0","192.168.0.2"); printf("%s\n\n",arp.getLastMessage()); if (arp.isArpVaild() == false) return; char macAddr[18]; arp.arpSendRecv("zen1",macAddr); printf("%s %s\n","zen1",macAddr); printf("%s\n\n",arp.getLastMessage()); arp.arpSendRecv("zen2",macAddr); printf("%s %s\n","zen2",macAddr); printf("%s\n\n",arp.getLastMessage()); arp.arpSendRecv("zen2",macAddr); printf("%s %s\n","zen2",macAddr); printf("%s\n\n",arp.getLastMessage()); arp.arpSendRecv("zen3",macAddr); printf("%s %s\n","zen3",macAddr); printf("%s\n\n",arp.getLastMessage()); arp.arpSendRecv("zen5",macAddr); printf("%s %s\n","zen5(3295805967)",macAddr); printf("%s\n\n",arp.getLastMessage()); arp.arpSendRecv(ntohl(inet_addr("15.2.114.196")),macAddr); printf("%s %s\n","zen5(3295805967)",macAddr); printf("%s\n\n",arp.getLastMessage()); arp.arpSendRecv("zen6",macAddr); printf("%s %s\n","zen6",macAddr); printf("%s\n\n",arp.getLastMessage()); arp.arpSendRecv("zen7",macAddr); printf("%s %s\n","zen7",macAddr); printf("%s\n\n",arp.getLastMessage()); }