19bbf0f31b3719931afe071dbec88110b5f6d66b
[reactos.git] / reactos / apps / utils / net / arp / arp.c
1 /*
2 * arp - display ARP cache from the IP stack parameters.
3 *
4 * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
5 *
6 * Robert Dickenson <robd@reactos.org>, August 15, 2002.
7 */
8 #include <stdio.h>
9 #include <windows.h>
10 #include <tchar.h>
11 #include <time.h>
12
13 #include <iptypes.h>
14 #include <ipexport.h>
15 #include <iphlpapi.h>
16 #include <snmp.h>
17
18 #include "trace.h"
19
20
21 VOID SNMP_FUNC_TYPE SnmpSvcInitUptime();
22 DWORD SNMP_FUNC_TYPE SnmpSvcGetUptime();
23
24 ////////////////////////////////////////////////////////////////////////////////
25
26 const char szUsage[] = { "\n" \
27 "Displays and modifies the IP Protocol to physical address translation tables\n" \
28 "used by address resolution protocol (ARP).\n" \
29 "\n" \
30 "ARP -s inet_addr eth_addr [if_addr]\n" \
31 "ARP -d inet_addr [if_addr]\n" \
32 "ARP -a [inet_addr] [-N if_addr]\n" \
33 "\n" \
34 " -a Displays the active ARP table by querying the current protocol\n" \
35 " data. If inet_addr is specified, the IP and physical addresses\n" \
36 " for the specified address are displayed. If more than one\n" \
37 " network interface is using ARP, each interfaces ARP table is\n" \
38 " displayed.\n" \
39 " -g Indentical to -a.\n" \
40 " inet_addr Specifies the IP address.\n" \
41 " -N if_addr Displays the ARP table for the specified interface only\n" \
42 " -d Deletes the host entry specified by inet_addr. inet_addr may be\n" \
43 " wildcarded with * to delete all host entries in the ARP table.\n" \
44 " -s Adds the host and associates the IP address inet_addr with the\n" \
45 " physical address eth_addr. The physical address must be specified\n" \
46 " as 6 hexadecimal characters delimited by hyphens. The new entry\n" \
47 " will become permanent in the ARP table.\n" \
48 " eth_addr Specifies the interface physical address.\n" \
49 " if_addr If present, this specifies the IP address of the interface whose\n" \
50 " address translation table should be modified. If not present, the\n" \
51 " first applicable interface will be used.\n" \
52 "Example:\n" \
53 " > arp -s 192.168.0.12 55-AA-55-01-02-03 .... Static entry creation.\n" \
54 " > arp -a .... ARP table display.\n" \
55 " > arp -d * .... Delete all ARP table entries.\n"
56 };
57
58 void usage(void)
59 {
60 // fprintf(stderr,"USAGE:\n");
61 fputs(szUsage, stderr);
62 }
63
64 int main(int argc, char *argv[])
65 {
66 TCHAR szComputerName[50];
67 DWORD dwSize = 50;
68
69 int nBytes = 500;
70 BYTE* pCache;
71
72 if (argc > 1) {
73 usage();
74 return 1;
75 }
76
77 SnmpSvcInitUptime();
78
79 GetComputerName(szComputerName, &dwSize);
80 _tprintf(_T("ReactOS ARP cache on Computer Name: %s\n"), szComputerName);
81
82 pCache = (BYTE*)SnmpUtilMemAlloc(nBytes);
83
84 Sleep(2500);
85
86 if (pCache != NULL) {
87
88 DWORD dwUptime = SnmpSvcGetUptime();
89
90 _tprintf(_T("SNMP uptime: %ld\n"), dwUptime);
91
92 SnmpUtilMemFree(pCache);
93 } else {
94 _tprintf(_T("ERROR: call to SnmpUtilMemAlloc() failed\n"));
95 return 1;
96 }
97 return 0;
98 }
99