Merged r16363:16600 from trunk except lib\aclui, subsys\csrss and subsys\smss. Modified: branches/cache_manager_rewrite/reactos/Makefile Modified: branches/cache_manager_rewrite/reactos/ReactOS.xml Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.c Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.rc Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.xml Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/finger/net.c Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/fake.c Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/ftp.c Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ipconfig/ipconfig. c Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/route/route.c Modified: branches/cache_manager_rewrite/reactos/apps/utils/ps/ps.c Modified: branches/cache_manager_rewrite/reactos/apps/utils/rosperf/fill.c Modified: branches/cache_manager_rewrite/reactos/apps/utils/rosperf/lines.c Modified: branches/cache_manager_rewrite/reactos/apps/utils/rosperf/rosperf.h Modified: branches/cache_manager_rewrite/reactos/baseaddress.xml Deleted: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile.i3 86 Deleted: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/Makefile.po werpc Added: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/bootsect.ma k Added: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/fat.h Added: branches/cache_manager_rewrite/reactos/boot/freeldr/bootsect/fat32.h Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/arch/i386/ha rdware.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/arch/i386/hw pci.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/arch/i386/mb .S Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/arch/i386/pc disk.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/arch/i386/xb oxdisk.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/cache/cache. c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/freeldr_base .xml Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/ext2.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/fat.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/fs.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/iso.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/ntfs.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/fs/ntfs.h Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/include/arch .h Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/include/free ldr.h Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/include/mult iboot.h Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/include/reac tos.h Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/include/rtl. h Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/inffile/inff ile.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/linuxboot.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/mm/meminit.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/mm/mm.c Deleted: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/multiboot.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/reactos/binh ive.c Added: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/reactos/load er.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/reactos/reac tos.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/reactos/regi stry.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/reactos/regi stry.h Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/reactos/setu pldr.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/print.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/rtl/stdlib.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr/ui/tui.c Modified: branches/cache_manager_rewrite/reactos/boot/freeldr/freeldr.xml Added: branches/cache_manager_rewrite/reactos/boot/freeldr/install/installfreel dr.xml Deleted: branches/cache_manager_rewrite/reactos/boot/freeldr/tools/bin2c.c Modified: branches/cache_manager_rewrite/reactos/bootdata/hivesys.inf Modified: branches/cache_manager_rewrite/reactos/bootdata/packages/reactos.dff Modified: branches/cache_manager_rewrite/reactos/bootdata/txtsetup.sif Modified: branches/cache_manager_rewrite/reactos/doc/README.WINE Modified: branches/cache_manager_rewrite/reactos/drivers/bus/acpi/ospm/fdo.c Modified: branches/cache_manager_rewrite/reactos/drivers/bus/serenum/detect.c Modified: branches/cache_manager_rewrite/reactos/drivers/bus/serenum/fdo.c Modified: branches/cache_manager_rewrite/reactos/drivers/bus/serenum/misc.c Modified: branches/cache_manager_rewrite/reactos/drivers/bus/serenum/pdo.c Modified: branches/cache_manager_rewrite/reactos/drivers/bus/serenum/serenum.c Modified: branches/cache_manager_rewrite/reactos/drivers/bus/serenum/serenum.h Modified: branches/cache_manager_rewrite/reactos/drivers/dd/blue/blue.c Modified: branches/cache_manager_rewrite/reactos/drivers/dd/bootvid/bootvid.c Modified: branches/cache_manager_rewrite/reactos/drivers/dd/null/null.c Modified: branches/cache_manager_rewrite/reactos/drivers/dd/parallel/parallel.c Modified: branches/cache_manager_rewrite/reactos/drivers/dd/ramdrv/ramdrv.c Modified: branches/cache_manager_rewrite/reactos/drivers/fs/cdfs/dirctl.c Modified: branches/cache_manager_rewrite/reactos/drivers/fs/cdfs/fcb.c Modified: branches/cache_manager_rewrite/reactos/drivers/fs/np/rw.c Modified: branches/cache_manager_rewrite/reactos/drivers/fs/ntfs/attrib.c Modified: branches/cache_manager_rewrite/reactos/drivers/fs/ntfs/mft.c Modified: branches/cache_manager_rewrite/reactos/drivers/fs/vfat/rw.c Modified: branches/cache_manager_rewrite/reactos/drivers/lib/ip/network/receive.c Modified: branches/cache_manager_rewrite/reactos/drivers/lib/ip/transport/udp/udp. c Modified: branches/cache_manager_rewrite/reactos/drivers/net/afd/afd/select.c Modified: branches/cache_manager_rewrite/reactos/drivers/net/dd/pcnet/pcnet.c Modified: branches/cache_manager_rewrite/reactos/drivers/net/dd/pcnet/pcnet.h Modified: branches/cache_manager_rewrite/reactos/drivers/net/ndis/ndis/buffer.c Modified: branches/cache_manager_rewrite/reactos/drivers/net/ndis/ndis/io.c Modified: branches/cache_manager_rewrite/reactos/drivers/net/ndis/ndis/miniport.c Modified: branches/cache_manager_rewrite/reactos/drivers/net/npf/read.c Modified: branches/cache_manager_rewrite/reactos/drivers/net/npf/win_bpf_filter.c Modified: branches/cache_manager_rewrite/reactos/drivers/storage/atapi/atapi.c Modified: branches/cache_manager_rewrite/reactos/drivers/storage/cdrom/cdrom.c Modified: branches/cache_manager_rewrite/reactos/drivers/storage/disk/disk.c Modified: branches/cache_manager_rewrite/reactos/drivers/storage/scsiport/scsiport .c Modified: branches/cache_manager_rewrite/reactos/drivers/usb/cromwell/linux/usb.h Modified: branches/cache_manager_rewrite/reactos/drivers/video/displays/vga/object s/bitblt.c Modified: branches/cache_manager_rewrite/reactos/drivers/video/displays/vga/object s/lineto.c Modified: branches/cache_manager_rewrite/reactos/drivers/video/displays/vga/object s/paint.c Modified: branches/cache_manager_rewrite/reactos/drivers/video/displays/vga/object s/pointer.c Modified: branches/cache_manager_rewrite/reactos/drivers/video/displays/vga/vgavid eo/vgavideo.c Modified: branches/cache_manager_rewrite/reactos/drivers/video/miniport/vga/initvg a.c Modified: branches/cache_manager_rewrite/reactos/drivers/video/miniport/xboxvmp/xb oxvmp.c Modified: branches/cache_manager_rewrite/reactos/drivers/video/miniport/xboxvmp/xb oxvmp.h [truncated at 100 lines; 555 more skipped] _____
Modified: branches/cache_manager_rewrite/reactos/Makefile --- branches/cache_manager_rewrite/reactos/Makefile 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/Makefile 2005-08-14 16:42:46 UTC (rev 17385) @@ -169,6 +169,7 @@
ECHO_MKHIVE =@echo $(QUOTE)[MKHIVE] $@$(QUOTE) ECHO_REGTESTS=@echo $(QUOTE)[REGTESTS] $@$(QUOTE) ECHO_TEST =@echo $(QUOTE)[TEST] $@$(QUOTE) + ECHO_GENDIB =@echo $(QUOTE)[GENDIB] $@$(QUOTE) else ECHO_CP = ECHO_MKDIR = @@ -196,6 +197,7 @@ ECHO_MKHIVE = ECHO_REGTESTS= ECHO_TEST = + ECHO_GENDIB = endif
@@ -288,16 +290,19 @@
include lib/lib.mak include tools/tools.mak +include boot/freeldr/bootsect/bootsect.mak -include makefile.auto
PREAUTO := \ + $(BIN2C_TARGET) \ $(BIN2RES_TARGET) \ $(BUILDNO_H) \ $(BUGCODES_H) \ $(BUGCODES_RC) \ $(ERRCODES_H) \ $(ERRCODES_RC) \ - $(NCI_SERVICE_FILES) + $(NCI_SERVICE_FILES) \ + $(GENDIB_DIB_FILES)
makefile.auto: $(RBUILD_TARGET) $(PREAUTO) $(XMLBUILDFILES) $(ECHO_RBUILD) _____
Modified: branches/cache_manager_rewrite/reactos/ReactOS.xml --- branches/cache_manager_rewrite/reactos/ReactOS.xml 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/ReactOS.xml 2005-08-14 16:42:46 UTC (rev 17385) @@ -28,11 +28,12 @@
<define name="KDBG" value="1" /> <property name="DBG_OR_KDBG" value="true" /> </if> + <compilerflag>-Wpointer-arith</compilerflag>
<include>include</include> - <include>include/reactos</include> + <include>include/reactos</include> <include>w32api/include</include> - <include>w32api/include/ddk</include> + <include>w32api/include/ddk</include>
<directory name="apps"> <xi:include href="apps/directory.xml" /> _____
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.c --- branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.c 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.c 2005-08-14 16:42:46 UTC (rev 17385) @@ -1,97 +1,465 @@
-/* - * arp - display ARP cache from the IP stack parameters. +/* + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS arp utility + * FILE: apps/utils/net/arp/arp.c + * PURPOSE: view and manipulate the ARP cache + * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com) + * REVISIONS: + * GM 27/06/05 Created * - * This source code is in the PUBLIC DOMAIN and has NO WARRANTY. - * - * Robert Dickenson robd@reactos.org, August 15, 2002. */ + + +#include <windows.h> #include <stdio.h> -#include <windows.h> +#include <stdlib.h> #include <tchar.h> -#include <time.h> - -#include <iptypes.h> -#include <ipexport.h> +#include <string.h> +#include <ctype.h> +#include <winsock2.h> #include <iphlpapi.h> -#include <snmp.h> + +#define WIN32_LEAN_AND_MEAN +#define UNICODE +#define _UNICODE + +/* + * Globals + */ +const char SEPERATOR = '-'; + + + +/* + * function declerations + */ +INT DisplayArpEntries(PTCHAR pszInetAddr, PTCHAR pszIfAddr); +INT PrintEntries(PMIB_IPNETROW pIpAddRow); +INT Addhost(PTCHAR pszInetAddr, PTCHAR pszEthAddr, PTCHAR pszIfAddr); +INT Deletehost(PTCHAR pszInetAddr, PTCHAR pszIfAddr); +VOID Usage(VOID); + + + +/* + * + * Takes optional parameters of an internet address and interface address. + * Retrieve all entries in the ARP cache. If an internet address is + * specified, display the ARP entry relating to that address. If an + * interface address is specified, display all entries relating to + * that interface. + * + */ +/* FIXME: allow user to specify an interface address, via pszIfAddr */ +INT DisplayArpEntries(PTCHAR pszInetAddr, PTCHAR pszIfAddr) +{ + INT iRet; + UINT i, k; + PMIB_IPNETTABLE pIpNetTable; + PMIB_IPADDRTABLE pIpAddrTable; + ULONG ulSize = 0; + struct in_addr inaddr, inaddr2; + DWORD dwSize = 0; + PTCHAR pszIpAddr; + TCHAR szIntIpAddr[20]; + + /* Return required buffer size */ + GetIpNetTable(NULL, &ulSize, 0); + + /* allocate memory for ARP address table */ + pIpNetTable = (PMIB_IPNETTABLE) malloc(ulSize * sizeof(BYTE)); + ZeroMemory(pIpNetTable, sizeof(*pIpNetTable)); + + /* get Arp address table */ + if (pIpNetTable != NULL) { + GetIpNetTable(pIpNetTable, &ulSize, TRUE); + } else { + _tprintf(_T("failed to allocate memory for GetIpNetTable\n")); + free(pIpNetTable); + return -1; + } + + /* check there are entries in the table */ + if (pIpNetTable->dwNumEntries == 0) { + _tprintf(_T("No ARP entires found\n")); + free(pIpNetTable); + return -1; + } + + + + /* try doing this in the way it's done above, it's clearer */ + /* Retrieve the interface-to-ip address mapping + * table to get the IP address for adapter */ + pIpAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize); + GetIpAddrTable(pIpAddrTable, &dwSize, 0); // NULL ? +
-#include "trace.h" - -VOID WINAPI SnmpSvcInitUptime(); - -/////////////////////////////////////////////////////////////////////// ///////// - -const char szUsage[] = { "\n" \ - "Displays and modifies the IP Protocol to physical address translation tables\n" \ - "used by address resolution protocol (ARP).\n" \ - "\n" \ - "ARP -s inet_addr eth_addr [if_addr]\n" \ - "ARP -d inet_addr [if_addr]\n" \ - "ARP -a [inet_addr] [-N if_addr]\n" \ - "\n" \ - " -a Displays the active ARP table by querying the current protocol\n" \ - " data. If inet_addr is specified, the IP and physical addresses\n" \ - " for the specified address are displayed. If more than one\n" \ - " network interface is using ARP, each interfaces ARP table is\n" \ - " displayed.\n" \ - " -g Indentical to -a.\n" \ - " inet_addr Specifies the IP address.\n" \ - " -N if_addr Displays the ARP table for the specified interface only\n" \ - " -d Deletes the host entry specified by inet_addr. inet_addr may be\n" \ - " wildcarded with * to delete all host entries in the ARP table.\n" \ - " -s Adds the host and associates the IP address inet_addr with the\n" \ - " physical address eth_addr. The physical address must be specified\n" \ - " as 6 hexadecimal characters delimited by hyphens. The new entry\n" \ - " will become permanent in the ARP table.\n" \ - " eth_addr Specifies the interface physical address.\n" \ - " if_addr If present, this specifies the IP address of the interface whose\n" \ - " address translation table should be modified. If not present, the\n" \ - " first applicable interface will be used.\n" \ - "Example:\n" \ - " > arp -s 192.168.0.12 55-AA-55-01-02-03 .... Static entry creation.\n" \ - " > arp -a .... ARP table display.\n" \ - " > arp -d * .... Delete all ARP table entries.\n" -}; - -void usage(void) + pIpAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize); + //ZeroMemory(pIpAddrTable, sizeof(*pIpAddrTable)); + + if ((iRet = GetIpAddrTable(pIpAddrTable, &dwSize, TRUE)) != NO_ERROR) { // NO_ERROR = 0 + _tprintf(_T("GetIpAddrTable failed: %d\n"), iRet); + _tprintf(_T("error: %d\n"), WSAGetLastError()); + } + + + for (k=0; k < pIpAddrTable->dwNumEntries; k++) { + if (pIpNetTable->table[0].dwIndex == pIpAddrTable->table[k].dwIndex) { + //printf("printing pIpAddrTable->table[?].dwIndex = %lx\n", pIpNetTable->table[k].dwIndex); + inaddr2.s_addr = pIpAddrTable->table[k].dwAddr; + pszIpAddr = inet_ntoa(inaddr2); + strcpy(szIntIpAddr, pszIpAddr); + } + } + + + /* print header, including interface IP address and index number */ + _tprintf(_T("\nInterface: %s --- 0x%lx \n"), szIntIpAddr, pIpNetTable->table[0].dwIndex); + _tprintf(_T(" Internet Address Physical Address Type\n")); + + /* go through all ARP entries */ + for (i=0; i < pIpNetTable->dwNumEntries; i++) { + + /* if the user has supplied their own internet addesss * + * only print the arp entry which matches that */ + if (pszInetAddr) { + inaddr.S_un.S_addr = pIpNetTable->table[i].dwAddr; + pszIpAddr = inet_ntoa(inaddr); + + /* check if it matches, print it */ + if (strcmp(pszIpAddr, pszInetAddr) == 0) { + PrintEntries(&pIpNetTable->table[i]); + } + } else { + /* if an address is not supplied, print all entries */ + PrintEntries(&pIpNetTable->table[i]); + } + + } + + free(pIpNetTable); + free(pIpAddrTable); + + return 0; +} + + + +/* + * + * Takes an ARP entry and prints the IP address, + * the MAC address and the entry type to screen + * + */ +INT PrintEntries(PMIB_IPNETROW pIpAddRow) { -// fprintf(stderr,"USAGE:\n"); - fputs(szUsage, stderr); + IN_ADDR inaddr; + TCHAR cMacAddr[20]; + + /* print IP addresses */ + inaddr.S_un.S_addr = pIpAddRow->dwAddr; + _tprintf(_T(" %-22s"), inet_ntoa(inaddr)); //error checking + + /* print MAC address */ + _stprintf(cMacAddr, _T("%02x-%02x-%02x-%02x-%02x-%02x"), + pIpAddRow->bPhysAddr[0], + pIpAddRow->bPhysAddr[1], + pIpAddRow->bPhysAddr[2], + pIpAddRow->bPhysAddr[3], + pIpAddRow->bPhysAddr[4], + pIpAddRow->bPhysAddr[5]); + _tprintf(_T("%-22s"), cMacAddr); + + /* print cache type */ + switch (pIpAddRow->dwType) { + case MIB_IPNET_TYPE_DYNAMIC : _tprintf(_T("dynamic\n")); + break; + case MIB_IPNET_TYPE_STATIC : _tprintf(_T("static\n")); + break; + case MIB_IPNET_TYPE_INVALID : _tprintf(_T("invalid\n")); + break; + case MIB_IPNET_TYPE_OTHER : _tprintf(_T("other\n")); + break; + } + return 0; } - -int main(int argc, char *argv[]) + + + +/* + * + * Takes an internet address, a MAC address and an optional interface + * address as arguments and checks their validity. + * Fill out an MIB_IPNETROW structure and insert the data into the + * ARP cache as a static entry. + * + */ +INT Addhost(PTCHAR pszInetAddr, PTCHAR pszEthAddr, PTCHAR pszIfAddr) { - TCHAR szComputerName[50]; - DWORD dwSize = 50; + PMIB_IPNETROW pAddHost; + PMIB_IPADDRTABLE pIpAddrTable; + DWORD dwIpAddr; + DWORD dwSize = 0; + INT iRet, i, val; + TCHAR c; + + /* error checking */ + + /* check IP address */ + if (pszInetAddr != NULL) { + if ((dwIpAddr = inet_addr(pszInetAddr)) == INADDR_NONE) { + _tprintf(_T("ARP: bad IP address: %s\n"), pszInetAddr); + return -1; + } + } else { + Usage(); + return -1; + } + + /* check MAC address */ + if (strlen(pszEthAddr) != 17) { + _tprintf(_T("ARP: bad argument: %s\n"), pszEthAddr); + return -1; + } + for (i=0; i<17; i++) { + if (pszEthAddr[i] == SEPERATOR) { + continue; + } + if (!isxdigit(pszEthAddr[i])) { + _tprintf(_T("ARP: bad argument: %s\n"), pszEthAddr); + return -1; + } + } + + /* reserve memory on heap and zero */ + pAddHost = (MIB_IPNETROW *) malloc(sizeof(MIB_IPNETROW)); + ZeroMemory(pAddHost, sizeof(MIB_IPNETROW)); + + + + + /* set dwIndex field to the index of a local IP address to + * indicate the network on which the ARP entry applies */ + if (pszIfAddr) { + sscanf(pszIfAddr, "%lx", &pAddHost->dwIndex); + } else { + /* map the IP to the index */ + pIpAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize); + GetIpAddrTable(pIpAddrTable, &dwSize, 0); + + pIpAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize); + + if ((iRet = GetIpAddrTable(pIpAddrTable, &dwSize, TRUE)) != NO_ERROR) { // NO_ERROR = 0 + _tprintf(_T("GetIpAddrTable failed: %d\n"), iRet); + _tprintf(_T("error: %d\n"), WSAGetLastError()); + } + printf("printing pIpAddrTable->table[0].dwIndex = %lx\n", pIpAddrTable->table[0].dwIndex); + pAddHost->dwIndex = 4;
- int nBytes = 500; - BYTE* pCache; - - if (argc > 1) { - usage(); - return 1; + free(pIpAddrTable); } - - SnmpSvcInitUptime(); - - GetComputerName(szComputerName, &dwSize); - _tprintf(_T("ReactOS ARP cache on Computer Name: %s\n"), szComputerName); - - pCache = (BYTE*)SnmpUtilMemAlloc(nBytes); - - Sleep(2500); - - if (pCache != NULL) { - - DWORD dwUptime = SnmpSvcGetUptime(); - - _tprintf(_T("SNMP uptime: %ld\n"), dwUptime); - - SnmpUtilMemFree(pCache); + + /* Set MAC address to 6 bytes (typical) */ + pAddHost->dwPhysAddrLen = 6; + + + /* Encode bPhysAddr into correct byte array */ + for (i=0; i<6; i++) { + val =0; + c = toupper(pszEthAddr[i*3]); + c = c - (isdigit(c) ? '0' : ('A' - 10)); + val += c; + val = (val << 4); + c = toupper(pszEthAddr[i*3 + 1]); + c = c - (isdigit(c) ? '0' : ('A' - 10)); + val += c; + pAddHost->bPhysAddr[i] = val; + + } + + + /* copy converted IP address */ + pAddHost->dwAddr = dwIpAddr; + + + /* set type to static */ + pAddHost->dwType = MIB_IPNET_TYPE_STATIC; + + + /* Add the ARP entry */ + if ((iRet = SetIpNetEntry(pAddHost)) != NO_ERROR) { + _tprintf(_T("The ARP entry addition failed: %d\n"), iRet); + return -1; + } + + free(pAddHost); + + return 0; +} + + + +/* + * + * Takes an internet address and an optional interface address as + * arguments and checks their validity. + * Add the interface number and IP to an MIB_IPNETROW structure + * and remove the entrty from the ARP cache. + * + */ +INT Deletehost(PTCHAR pszInetAddr, PTCHAR pszIfAddr) +{ + PMIB_IPNETROW pDelHost; + PMIB_IPADDRTABLE pIpAddrTable; + DWORD dwIpAddr; + DWORD dwSize = 0; + INT iret; + + /* error checking */ + + /* check IP address */ + if (pszInetAddr != NULL) { + if ((dwIpAddr = inet_addr(pszInetAddr)) == INADDR_NONE) { + _tprintf(_T("ARP: bad IP address: %s\n"), pszInetAddr); + return -1; + } } else { - _tprintf(_T("ERROR: call to SnmpUtilMemAlloc() failed\n")); - return 1; + Usage(); + return -1; } - return 0; + + + pIpAddrTable = (MIB_IPADDRTABLE*) malloc(sizeof(MIB_IPADDRTABLE)); + pDelHost = (MIB_IPNETROW *) malloc(sizeof(MIB_IPNETROW)); + ZeroMemory(pIpAddrTable, sizeof(MIB_IPADDRTABLE)); + ZeroMemory(pDelHost, sizeof(MIB_IPNETROW)); + /* set dwIndex field to the index of a local IP address to + * indicate the network on which the ARP entry applies */ + if (pszIfAddr) { + sscanf(pszIfAddr, "%lx", &pDelHost->dwIndex); + } else { + /* map the IP to the index */ + if (GetIpAddrTable(pIpAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) { + pIpAddrTable = (MIB_IPADDRTABLE *) malloc(dwSize); + } + if ((iret = GetIpAddrTable(pIpAddrTable, &dwSize, TRUE)) != NO_ERROR) { + _tprintf(_T("GetIpAddrTable failed: %d\n"), iret); + _tprintf(_T("error: %d\n"), WSAGetLastError()); + } + pDelHost->dwIndex = 4; //pIpAddrTable->table[0].dwIndex; + } + + /* copy converted IP address */ + pDelHost->dwAddr = dwIpAddr; + + /* Add the ARP entry */ + if ((iret = DeleteIpNetEntry(pDelHost)) != NO_ERROR) { + _tprintf(_T("The ARP entry deletion failed: %d\n"), iret); + return -1; + } + + free(pIpAddrTable); + free(pDelHost); + + return 0; } - + + + +/* + * + * print program usage to screen + * + */ +VOID Usage(VOID) +{ + _tprintf(_T("\nDisplays and modifies the IP-to-Physical address translation tables used by\n" + "address resolution protocol (ARP).\n" + "\n" + "ARP -s inet_addr eth_addr [if_addr]\n" + "ARP -d inet_addr [if_addr]\n" + "ARP -a [inet_addr] [-N if_addr]\n" + "\n" + " -a Displays current ARP entries by interrogating the current\n" + " protocol data. If inet_addr is specified, the IP and Physical\n" + " addresses for only the specified computer are displayed. If\n" + " more than one network interface uses ARP, entries for each ARP\n" + " table are displayed.\n" + " -g Same as -a.\n" + " inet_addr Specifies an internet address.\n" + " -N if_addr Displays the ARP entries for the network interface specified\n" + " by if_addr.\n" + " -d Deletes the host specified by inet_addr. inet_addr may be\n" + " wildcarded with * to delete all hosts.\n" + " -s Adds the host and associates the Internet address inet_addr\n" + " with the Physical address eth_addr. The Physical address is\n" + " given as 6 hexadecimal bytes separated by hyphens. The entry\n" + " is permanent.\n" + " eth_addr Specifies a physical address.\n" + " if_addr If present, this specifies the Internet address of the\n" + " interface whose address translation table should be modified.\n" + " If not present, the first applicable interface will be used.\n" + "Example:\n" + " > arp -s 157.55.85.212 00-aa-00-62-c6-09 .... Adds a static entry.\n" + " > arp -a .... Displays the arp table.\n\n")); +} + + + +/* + * + * Program entry. + * Parse command line and call the required function + * + */ +INT main(int argc, char* argv[]) +{ + const char N[] = "-N"; + + if ((argc < 2) || (argc > 5)) + { + Usage(); + return FALSE; + } + + + if (argv[1][0] == '-') { + switch (argv[1][1]) { + /* FIX ME */ + /* need better control for -a, as -N might not be arg 4 */ + case 'a': if (argc == 2) + DisplayArpEntries(NULL, NULL); + else if (argc == 3) + DisplayArpEntries(argv[2], NULL); + else if ((argc == 5) && ((strcmp(argv[3], N)) == 0)) + DisplayArpEntries(argv[2], argv[4]); + else + Usage(); + break; + case 'g': break; + case 'd': if (argc == 3) + Deletehost(argv[2], NULL); + else if (argc == 4) + Deletehost(argv[2], argv[3]); + else + Usage(); + break; + case 's': if (argc == 4) + Addhost(argv[2], argv[3], NULL); + else if (argc == 5) + Addhost(argv[2], argv[3], argv[4]); + else + Usage(); + break; + default: + Usage(); + return -1; + } + } else { + Usage(); + return -1; + } + + return 0; +} _____
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.rc --- branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.rc 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.rc 2005-08-14 16:42:46 UTC (rev 17385) @@ -1,6 +1,5 @@
-/* $Id$ */ - #define REACTOS_STR_FILE_DESCRIPTION "ReactOS TCP/IPv4 Win32 arp\0" #define REACTOS_STR_INTERNAL_NAME "arp\0" #define REACTOS_STR_ORIGINAL_FILENAME "arp.exe\0" +#define REACTOS_STR_ORIGINAL_COPYRIGHT "Ged Murphy (gedmurphy@gmail.com)\0" #include <reactos/version.rc> _____
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.xml --- branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.xml 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/apps/utils/net/arp/arp.xml 2005-08-14 16:42:46 UTC (rev 17385) @@ -2,8 +2,10 @@
<include base="arp">.</include> <define name="__USE_W32API" /> <library>kernel32</library> - <library>user32</library> - <library>snmpapi</library> + <library>iphlpapi</library> + <library>ws2_32</library> + <library>shlwapi</library> <file>arp.c</file> <file>arp.rc</file> </module> + _____
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/finger/net.c --- branches/cache_manager_rewrite/reactos/apps/utils/net/finger/net.c 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/apps/utils/net/finger/net.c 2005-08-14 16:42:46 UTC (rev 17385) @@ -59,7 +59,7 @@
return;
*host++ = '\0'; - if (isdigit(*host) && (defaddr.s_addr = inet_addr(host)) != -1) { + if (isdigit(*host) && (defaddr.s_addr = inet_addr(host)) != (unsigned long)-1) { def.h_name = host; def.h_addr_list = alist; def.h_addr = (char *)&defaddr; _____
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/fake.c --- branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/fake.c 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/fake.c 2005-08-14 16:42:46 UTC (rev 17385) @@ -100,7 +100,7 @@
index = 0; total = recv(s, buffer, sizeof(buffer), 0);
- if (total == INVALID_SOCKET) + if (total == SOCKET_ERROR) { total = 0; return ERROR; _____
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/ftp.c --- branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/ftp.c 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/apps/utils/net/ftp/ftp.c 2005-08-14 16:42:46 UTC (rev 17385) @@ -119,7 +119,7 @@
bzero((char *)&hisctladdr, sizeof (hisctladdr)); hisctladdr.sin_addr.s_addr = inet_addr(host); - if (hisctladdr.sin_addr.s_addr != -1) { + if (hisctladdr.sin_addr.s_addr != (unsigned long)-1) { hisctladdr.sin_family = AF_INET; (void) strncpy(hostnamebuf, host, sizeof(hostnamebuf)); } else { _____
Modified: branches/cache_manager_rewrite/reactos/apps/utils/net/ipconfig/ipconfig. c --- branches/cache_manager_rewrite/reactos/apps/utils/net/ipconfig/ipconfig. c 2005-08-14 13:45:00 UTC (rev 17384) +++ branches/cache_manager_rewrite/reactos/apps/utils/net/ipconfig/ipconfig. c 2005-08-14 16:42:46 UTC (rev 17385) @@ -1,10 +1,30 @@
+/* $Id: ipconfig.c + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS Ipconfig utility + * FILE: apps/utils/net/ipconfig/ipconfig.c + * PURPOSE: Show and set network interface IP parameters + */ /* - * ipconfig - display IP stack parameters. + * History: * - * This source code is in the PUBLIC DOMAIN and has NO WARRANTY. + * 15/8/2002 (Robert Dickenson robd@reactos.org) + * Original version (PUBLIC DOMAIN and NO WARRANTY) * - * Robert Dickenson robd@reactos.org, August 15, 2002. - */ + * 26/6/2005 (Tim Jobling tjob800@yahoo.co.uk) + * Relicense to GPL. + * Display NodeType with meaningfull Human readable names. + * Exclusively use TCHAR strings. + * Display Physical Address, DHCP enabled state, IP Addresses/Netmasks, + * Default Gateway, DHCP server and DHCP Lease times. + * Parse command line options. + * Default to only showing the IP/SM/DG is no options specified + * Handel option: /All and /? + * Display message about all unimplemented options. + * Changed C++ style commenting to C style + * +*/ + #include <stdio.h> #include <windows.h> #include <tchar.h> @@ -18,8 +38,6 @@ #include "trace.h" #endif
-/////////////////////////////////////////////////////////////////////// ///////// - /* imported from iphlpapi.dll
GetAdapterOrderMap @@ -30,18 +48,43 @@
*/
-static TCHAR* GetNodeTypeName(int nNodeType) +static TCHAR* GetNodeTypeName(UINT nNodeType) { switch (nNodeType) { - case 0: return _T("zero"); - case 1: return _T("one"); - case 2: return _T("two"); - case 3: return _T("three"); - case 4: return _T("mixed"); + case 1: return _T("Broadcast"); + case 2: return _T("Peer To Peer"); + case 4: return _T("Mixed"); + case 8: return _T("Hybrid"); default: return _T("unknown"); } }
+static TCHAR* GetInterfaceTypeName(UINT nInterfaceType) +{ + switch (nInterfaceType) { + case MIB_IF_TYPE_OTHER: return _T("Other"); + case MIB_IF_TYPE_ETHERNET: return _T("Ethernet"); + case MIB_IF_TYPE_TOKENRING: return _T("Token Ring"); + case MIB_IF_TYPE_FDDI: return _T("FDDI"); + case MIB_IF_TYPE_PPP: return _T("PPP"); + case MIB_IF_TYPE_LOOPBACK: return _T("Loopback"); + case MIB_IF_TYPE_SLIP: return _T("SLIP"); + default: return _T("unknown"); + } +} + +void PrintPhysicalAddr(PBYTE Addr, UINT len) +{ + UINT i=0; + for (i=0; i<len; i++) + { + _tprintf(_T("%02X"), Addr[i]); + if ((i+1)<len) + _tprintf(_T("-")); + } + _tprintf(_T("\n")); +} + static void ShowNetworkFixedInfo() { FIXED_INFO* pFixedInfo = NULL; @@ -64,27 +107,28 @@ if (result == ERROR_SUCCESS) { IP_ADDR_STRING* pIPAddr;
- printf("\tHostName. . . . . . . . . . . : %s\n", pFixedInfo->HostName); - printf("\tDomainName. . . . . . . . . . : %s\n", pFixedInfo->DomainName); -// - printf("\tDNS Servers . . . . . . . . . : %s\n", pFixedInfo->DnsServerList.IpAddress.String); + _tprintf(_T("\tHostName. . . . . . . . . . . : %s\n"), pFixedInfo->HostName); + _tprintf(_T("\tDomainName. . . . . . . . . . : %s\n"), pFixedInfo->DomainName); + + _tprintf(_T("\tDNS Servers . . . . . . . . . : %s\n"), pFixedInfo->DnsServerList.IpAddress.String); pIPAddr = pFixedInfo->DnsServerList.Next; while (pIPAddr) { - printf("\t\t\t\t : %s\n", pIPAddr->IpAddress.String); + _tprintf(_T("\t\t\t\t : %s\n"), pIPAddr->IpAddress.String); pIPAddr = pIPAddr->Next; } -// + _tprintf(_T("\tNodeType. . . . . . . . . . . : %d (%s)\n"), pFixedInfo->NodeType, GetNodeTypeName(pFixedInfo->NodeType)); - printf("\tScopeId . . . . . . . . . . . : %s\n", pFixedInfo->ScopeId); + _tprintf(_T("\tScopeId . . . . . . . . . . . : %s\n"), pFixedInfo->ScopeId); _tprintf(_T("\tEnableRouting . . . . . . . . : %s\n"), pFixedInfo->EnableRouting ? _T("yes") : _T("no")); _tprintf(_T("\tEnableProxy . . . . . . . . . : %s\n"), pFixedInfo->EnableProxy ? _T("yes") : _T("no")); _tprintf(_T("\tEnableDns . . . . . . . . . . : %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no")); _tprintf(_T("\n")); - //_tprintf(_T("\n"),); - //_tprintf(_T("GetNetworkParams() returned with %d\n"), pIfTable->NumAdapters); +/* + _tprintf(_T("\n"),); + _tprintf(_T("GetNetworkParams() returned with %d\n"), pIfTable->NumAdapters);
-// _tprintf(_T("\tConnection specific DNS suffix: %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no")); - + _tprintf(_T("\tConnection specific DNS suffix: %s\n"), pFixedInfo->EnableDns ? _T("yes") : _T("no")); +*/ } else { switch (result) { case ERROR_BUFFER_OVERFLOW: @@ -121,10 +165,11 @@ }
result = GetInterfaceInfo(pIfTable, &dwOutBufLen); -// dwOutBufLen = sizeof(IP_INTERFACE_INFO) + dwNumIf * sizeof(IP_ADAPTER_INDEX_MAP); -// _tprintf(_T("GetNumberOfInterfaces() returned %d, dwOutBufLen %d\n"), dwNumIf, dwOutBufLen); -// _tprintf(_T("sizeof(IP_INTERFACE_INFO) %d, sizeof(IP_ADAPTER_INDEX_MAP) %d\n"), sizeof(IP_INTERFACE_INFO), sizeof(IP_ADAPTER_INDEX_MAP)); - +/* + dwOutBufLen = sizeof(IP_INTERFACE_INFO) + dwNumIf * sizeof(IP_ADAPTER_INDEX_MAP); + _tprintf(_T("GetNumberOfInterfaces() returned %d, dwOutBufLen %d\n"), dwNumIf, dwOutBufLen); + _tprintf(_T("sizeof(IP_INTERFACE_INFO) %d, sizeof(IP_ADAPTER_INDEX_MAP) %d\n"), sizeof(IP_INTERFACE_INFO), sizeof(IP_ADAPTER_INDEX_MAP)); +*/ pIfTable = (IP_INTERFACE_INFO*)malloc(dwOutBufLen); if (!pIfTable) { _tprintf(_T("ERROR: failed to allocate 0x%08lX bytes of memory\n"), dwOutBufLen); @@ -143,17 +188,13 @@ */ result = GetInterfaceInfo(pIfTable, &dwOutBufLen); if (result == NO_ERROR) { - int i; + UINT i; _tprintf(_T("GetInterfaceInfo() returned with %ld adaptor entries\n"), pIfTable->NumAdapters); for (i = 0; i < pIfTable->NumAdapters; i++) { wprintf(L"[%d] %s\n", i + 1, pIfTable->Adapter[i].Name); - //wprintf(L"[%d] %s\n", pIfTable->Adapter[i].Index, pIfTable->Adapter[i].Name); + /*wprintf(L"[%d] %s\n", pIfTable->Adapter[i].Index, pIfTable->Adapter[i].Name);*/
-// \DEVICE\TCPIP_{DB0E61C1-3498-4C5F-B599-59CDE8A1E357} -// \DEVICE\TCPIP_{BD445697-0945-4591-AE7F-2AB0F383CA87} -// \DEVICE\TCPIP_{6D87DC08-6BC5-4E78-AB5F-18CAB785CFFE} - -//HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters \Interfaces\Tcpip_{DB0E61C1-3498-4C5F-B599-59CDE8A1E357} +/*HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters \Interfaces\Tcpip_{DB0E61C1-3498-4C5F-B599-59CDE8A1E357}*/ } } else { switch (result) { @@ -213,13 +254,20 @@ a Lease Obtained. . . . . . . . . . : Monday, 30 December 2002 5:56:53 PM b Lease Expires . . . . . . . . . . : Monday, 30 December 2002 6:26:53 PM */ -static void ShowAdapterInfo() +static void ShowAdapterInfo(BOOL ShowAll) { IP_ADAPTER_INFO* pAdaptorInfo; ULONG ulOutBufLen; DWORD dwRetVal; + PIP_ADDR_STRING pIpAddrString; + struct tm *LeaseTime;
- _tprintf(_T("\nAdaptor Information\t\n")); + + if (ShowAll) + { + _tprintf(_T("\nAdaptor Information\t\n")); + } + pAdaptorInfo = (IP_ADAPTER_INFO*)GlobalAlloc(GPTR, sizeof(IP_ADAPTER_INFO)); ulOutBufLen = sizeof(IP_ADAPTER_INFO);
@@ -231,14 +279,57 @@ _tprintf(_T("Call to GetAdaptersInfo failed. Return Value: 0x%08lx\n"), dwRetVal); } else { while (pAdaptorInfo) { - printf(" AdapterName: %s\n", pAdaptorInfo->AdapterName); - printf(" Description: %s\n", pAdaptorInfo->Description); + + /* print the type of interface before the Name of it */ + _tprintf(_T("\n%s Adapter %s:\n\n"), GetInterfaceTypeName(pAdaptorInfo->Type), pAdaptorInfo->AdapterName); + + if (ShowAll) + { + _tprintf(_T("\tDescription. . . . . . : %s\n"), pAdaptorInfo->Description); + + /* print the Physical address to the screen*/ + _tprintf(_T("\tPhysical Address . . . : ")); + PrintPhysicalAddr(pAdaptorInfo->Address, pAdaptorInfo->AddressLength); + + /* Now the DHCP state */ + _tprintf(_T("\tDHCP Enabled . . . . . : %s\n"), pAdaptorInfo->DhcpEnabled ? _T("Yes") : _T("No")); + } + + /* IP Addresses/Netmasks, there may be more than one */ + pIpAddrString = &pAdaptorInfo->IpAddressList; + + do{ + _tprintf(_T("\tIP Address . . . . . . : %s\n"), pIpAddrString->IpAddress.String); + _tprintf(_T("\tSubnet Mask. . . . . . : %s\n"), pIpAddrString->IpMask.String); + pIpAddrString = pIpAddrString->Next; + }while (pIpAddrString!=NULL); + + /* Default Gateway */ + pIpAddrString = &pAdaptorInfo->GatewayList; + _tprintf(_T("\tDefault Gateway. . . . : %s\n"), pIpAddrString->IpAddress.String); + + /* Print some stuff that is only relevant it dhcp is enabled */ + if((pAdaptorInfo->DhcpEnabled)&&(ShowAll)) + { + /* Display the DHCP server address */ + pIpAddrString = &pAdaptorInfo->DhcpServer; + _tprintf(_T("\tDHCP Server. . . . . . : %s\n"), pIpAddrString->IpAddress.String); + + /* Display the Lease times*/ + LeaseTime = localtime(&pAdaptorInfo->LeaseObtained); + _tprintf(_T("\tLease Obtained . . . . : %s"), asctime(LeaseTime)); + + LeaseTime = localtime(&pAdaptorInfo->LeaseExpires); + _tprintf(_T("\tLease Expieres . . . . : %s"), asctime(LeaseTime)); + + } + pAdaptorInfo = pAdaptorInfo->Next; } } }
-const char szUsage[] = { "USAGE:\n" \ +const TCHAR szUsage[] = { _T("USAGE:\n" \ " ipconfig [/? | /all | /release [adapter] | /renew [adapter]\n" \ " | /flushdns | /registerdns\n" \ " | /showclassid adapter\n" \ @@ -259,7 +350,7 @@ " /setclassid Modifies the dhcp class id.\n" \ "\n" \ "The default is to display only the IP address, subnet mask and\n" \ - "default gateway for each adapter bound to TCP/IP.\n" + "default gateway for each adapter bound to TCP/IP.\n") }; /* "\n" \ @@ -279,21 +370,114 @@
static void usage(void) { - fputs(szUsage, stderr); + _fputts(szUsage, stderr); }
-int main(int argc, char *argv[]) +int _tmain(int argc, TCHAR *argv[]) { - // 10.0.0.100 // As of build 0.0.20 this is hardcoded in the ip stack + BOOL DoUsage=FALSE; + BOOL DoAll=FALSE; + BOOL DoRelease=FALSE; + BOOL DoRenew=FALSE; + BOOL DoFlushdns=FALSE; + BOOL DoRegisterdns=FALSE; + BOOL DoDisplaydns=FALSE; + BOOL DoShowclassid=FALSE; + BOOL DoSetclassid=FALSE;
- if (argc > 1) { - usage(); - return 1; + _tprintf(_T("\nReactOS IP Configuration\n\n")); + + /* + Parse command line for options we have been given. + */ + if ( ((argc > 1))&&((argv[1][0]=='/')||(argv[1][0]=='-')) ) + { + if( !_tcsicmp( &argv[1][1], _T("?") )) + { + DoUsage = TRUE; + } + else if( !_tcsnicmp( &argv[1][1], _T("ALL"), _tcslen(&argv[1][1]) )) + { + DoAll = TRUE; + } + else if( !_tcsnicmp( &argv[1][1], _T("RELEASE"), _tcslen(&argv[1][1]) )) + { + DoRelease = TRUE; + } + else if( ! _tcsnicmp( &argv[1][1], _T("RENEW"), _tcslen(&argv[1][1]) )) + { + DoRenew = TRUE; + } + else if( ! _tcsnicmp( &argv[1][1], _T("FLUSHDNS"), _tcslen(&argv[1][1]) )) + { [truncated at 1000 lines; 71690 more skipped]