ReactOS 0.4.15-dev-7953-g1f49173
arp.c File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <stdio.h>
#include <stdlib.h>
#include <tchar.h>
#include <winsock2.h>
#include <iphlpapi.h>
#include <arp_msg.h>
Include dependency graph for arp.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 

Functions

DWORD DoFormatMessage (VOID)
 
DWORD PrintEntries (PMIB_IPNETROW pIpAddRow)
 
DWORD DisplayArpEntries (PTCHAR pszInetAddr, PTCHAR pszIfAddr)
 
DWORD Addhost (PTCHAR pszInetAddr, PTCHAR pszEthAddr, PTCHAR pszIfAddr)
 
DWORD Deletehost (PTCHAR pszInetAddr, PTCHAR pszIfAddr)
 
VOID Usage (VOID)
 
VOID PrintMessage (DWORD dwMessage)
 
VOID PrintMessageV (DWORD dwMessage,...)
 
INT main (int argc, char *argv[])
 

Variables

const char SEPARATOR = '-'
 
int _CRT_glob = 0
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 38 of file arp.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 31 of file arp.c.

Function Documentation

◆ Addhost()

DWORD Addhost ( PTCHAR  pszInetAddr,
PTCHAR  pszEthAddr,
PTCHAR  pszIfAddr 
)

Definition at line 349 of file arp.c.

350{
351 PMIB_IPNETROW pAddHost = NULL;
352 PMIB_IPNETTABLE pIpNetTable = NULL;
353 DWORD dwIpAddr = 0;
354 ULONG Size = 0;
355 INT i, val, c;
356 DWORD dwError = NO_ERROR;
357
358 /* error checking */
359
360 /* check IP address */
361 if (pszInetAddr == NULL)
362 {
363 Usage();
365 }
366
367 dwIpAddr = inet_addr(pszInetAddr);
368 if (dwIpAddr == INADDR_NONE)
369 {
370 PrintMessageV(MSG_ARP_BAD_IP_ADDRESS, pszInetAddr);
372 }
373
374 /* check MAC address */
375 if (strlen(pszEthAddr) != 17)
376 {
377 PrintMessageV(MSG_ARP_BAD_ARGUMENT, pszEthAddr);
379 }
380
381 for (i = 0; i < 17; i++)
382 {
383 if (pszEthAddr[i] == SEPARATOR)
384 continue;
385
386 if (!isxdigit(pszEthAddr[i]))
387 {
388 PrintMessageV(MSG_ARP_BAD_ARGUMENT, pszEthAddr);
390 }
391 }
392
393 /* We need the IpNetTable to get the adapter index */
394 /* Return required buffer size */
395 GetIpNetTable(pIpNetTable, &Size, 0);
396
397 /* allocate memory for ARP address table */
398 pIpNetTable = (PMIB_IPNETTABLE)HeapAlloc(GetProcessHeap(), 0, Size);
399 if (pIpNetTable == NULL)
400 {
401 PrintMessage(MSG_ARP_NO_MEMORY);
402 dwError = ERROR_NOT_ENOUGH_MEMORY;
403 goto cleanup;
404 }
405
406 ZeroMemory(pIpNetTable, sizeof(*pIpNetTable));
407
408 dwError = GetIpNetTable(pIpNetTable, &Size, TRUE);
409 if (dwError != NO_ERROR)
410 {
411 _tprintf(_T("GetIpNetTable failed: %lu\n"), dwError);
413 goto cleanup;
414 }
415
416 /* reserve memory on heap and zero */
417 pAddHost = (PMIB_IPNETROW)HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IPNETROW));
418 if (pAddHost == NULL)
419 {
420 PrintMessage(MSG_ARP_NO_MEMORY);
421 dwError = ERROR_NOT_ENOUGH_MEMORY;
422 goto cleanup;
423 }
424
425 ZeroMemory(pAddHost, sizeof(MIB_IPNETROW));
426
427 /* set dwIndex field to the index of a local IP address to
428 * indicate the network on which the ARP entry applies */
429 if (pszIfAddr)
430 {
431 if (sscanf(pszIfAddr, "%lx", &pAddHost->dwIndex) == EOF)
432 {
433 goto cleanup;
434 }
435 }
436 else
437 {
438 //printf("debug print: pIpNetTable->table[0].dwIndex = %lx\n", pIpNetTable->table[0].dwIndex);
439 /* needs testing. I get the correct index on my machine, but need others
440 * to test their card index. Any problems and we can use GetAdaptersInfo instead */
441 pAddHost->dwIndex = pIpNetTable->table[0].dwIndex;
442 }
443
444 /* Set MAC address to 6 bytes (typical) */
445 pAddHost->dwPhysAddrLen = 6;
446
447
448 /* Encode bPhysAddr into correct byte array */
449 for (i = 0; i < 6; i++)
450 {
451 val = 0;
452 c = toupper(pszEthAddr[i * 3]);
453 c = c - (isdigit(c) ? '0' : ('A' - 10));
454 val += c;
455 val = (val << 4);
456 c = toupper(pszEthAddr[i * 3 + 1]);
457 c = c - (isdigit(c) ? '0' : ('A' - 10));
458 val += c;
459 pAddHost->bPhysAddr[i] = (BYTE)val;
460 }
461
462 /* copy converted IP address */
463 pAddHost->dwAddr = dwIpAddr;
464
465
466 /* set type to static */
467 pAddHost->dwType = MIB_IPNET_TYPE_STATIC;
468
469
470 /* Add the ARP entry */
471 dwError = SetIpNetEntry(pAddHost);
472 if (dwError != NO_ERROR)
473 {
475 goto cleanup;
476 }
477
478cleanup:
479 if (pIpNetTable != NULL)
480 HeapFree(GetProcessHeap(), 0, pIpNetTable);
481 if (pAddHost != NULL)
482 HeapFree(GetProcessHeap(), 0, pAddHost);
483
484 return dwError;
485}
#define isdigit(c)
Definition: acclib.h:68
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define isxdigit(c)
Definition: acclib.h:70
int toupper(int c)
Definition: utclib.c:881
#define INADDR_NONE
Definition: tcp.c:42
const char SEPARATOR
Definition: arp.c:47
VOID PrintMessage(DWORD dwMessage)
Definition: arp.c:95
VOID PrintMessageV(DWORD dwMessage,...)
Definition: arp.c:118
DWORD DoFormatMessage(VOID)
Definition: arp.c:63
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
static void cleanup(void)
Definition: main.c:1335
unsigned long DWORD
Definition: ntddk_ex.h:95
const GLubyte * c
Definition: glext.h:8905
GLuint GLfloat * val
Definition: glext.h:7180
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Must_inspect_result_ _In_ USAGE _In_ USHORT _In_ USAGE Usage
Definition: hidpi.h:384
#define EOF
Definition: stdio.h:24
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define _tprintf
Definition: tchar.h:506
DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry)
struct _MIB_IPNETTABLE * PMIB_IPNETTABLE
struct _MIB_IPNETROW MIB_IPNETROW
@ MIB_IPNET_TYPE_STATIC
Definition: ipmib.h:109
struct _MIB_IPNETROW * PMIB_IPNETROW
#define inet_addr(cp)
Definition: inet.h:98
#define c
Definition: ke_i.h:80
DWORD dwPhysAddrLen
Definition: ipmib.h:115
BYTE bPhysAddr[MAXLEN_PHYSADDR]
Definition: ipmib.h:116
DWORD dwAddr
Definition: ipmib.h:117
DWORD dwType
Definition: ipmib.h:120
DWORD dwIndex
Definition: ipmib.h:114
MIB_IPNETROW table[1]
Definition: ipmib.h:128
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG
Definition: typedefs.h:59
#define _T(x)
Definition: vfdio.h:22
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define ZeroMemory
Definition: winbase.h:1712
unsigned char BYTE
Definition: xxhash.c:193

Referenced by main().

◆ Deletehost()

DWORD Deletehost ( PTCHAR  pszInetAddr,
PTCHAR  pszIfAddr 
)

Definition at line 495 of file arp.c.

496{
497 PMIB_IPNETROW pDelHost = NULL;
498 PMIB_IPNETTABLE pIpNetTable = NULL;
499 ULONG Size = 0;
500 DWORD dwIpAddr = 0;
501 BOOL bFlushTable = FALSE;
502 DWORD dwError = NO_ERROR;
503
504 /* error checking */
505
506 /* check IP address */
507 if (pszInetAddr == NULL)
508 {
509 Usage();
511 }
512
513 /* if wildcard is given, set flag to delete all hosts */
514 if (strncmp(pszInetAddr, "*", 1) == 0)
515 {
516 bFlushTable = TRUE;
517 }
518 else
519 {
520 dwIpAddr = inet_addr(pszInetAddr);
521 if (dwIpAddr == INADDR_NONE)
522 {
523 PrintMessageV(MSG_ARP_BAD_IP_ADDRESS, pszInetAddr);
525 }
526 }
527
528 /* We need the IpNetTable to get the adapter index */
529 /* Return required buffer size */
530 GetIpNetTable(NULL, &Size, 0);
531
532 /* allocate memory for ARP address table */
533 pIpNetTable = (PMIB_IPNETTABLE) HeapAlloc(GetProcessHeap(), 0, Size);
534 if (pIpNetTable == NULL)
535 {
536 PrintMessage(MSG_ARP_NO_MEMORY);
537 dwError = ERROR_NOT_ENOUGH_MEMORY;
538 goto cleanup;
539 }
540
541 ZeroMemory(pIpNetTable, sizeof(*pIpNetTable));
542
543 dwError = GetIpNetTable(pIpNetTable, &Size, TRUE);
544 if (dwError != NO_ERROR)
545 {
546 _tprintf(_T("GetIpNetTable failed: %lu\n"), dwError);
548 goto cleanup;
549 }
550
551 /* reserve memory on heap and zero */
552 pDelHost = (MIB_IPNETROW *)HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IPNETROW));
553 if (pDelHost == NULL)
554 {
555 PrintMessage(MSG_ARP_NO_MEMORY);
556 dwError = ERROR_NOT_ENOUGH_MEMORY;
557 goto cleanup;
558 }
559
560 ZeroMemory(pDelHost, sizeof(MIB_IPNETROW));
561
562 /* set dwIndex field to the index of a local IP address to
563 * indicate the network on which the ARP entry applies */
564 if (pszIfAddr)
565 {
566 if (sscanf(pszIfAddr, "%lx", &pDelHost->dwIndex) == EOF)
567 {
568 goto cleanup;
569 }
570 }
571 else
572 {
573 /* needs testing. I get the correct index on my machine, but need others
574 * to test their card index. Any problems and we can use GetAdaptersInfo instead */
575 pDelHost->dwIndex = pIpNetTable->table[0].dwIndex;
576 }
577
578 if (bFlushTable != FALSE)
579 {
580 /* delete arp cache */
581 dwError = FlushIpNetTable(pDelHost->dwIndex);
582 if (dwError != NO_ERROR)
583 {
585 goto cleanup;
586 }
587 }
588 else
589 {
590 /* copy converted IP address */
591 pDelHost->dwAddr = dwIpAddr;
592
593 /* Delete the ARP entry */
594 dwError = DeleteIpNetEntry(pDelHost);
595 if (dwError != NO_ERROR)
596 {
598 goto cleanup;
599 }
600 }
601
602cleanup:
603 if (pIpNetTable != NULL)
604 HeapFree(GetProcessHeap(), 0, pIpNetTable);
605 if (pDelHost != NULL)
606 HeapFree(GetProcessHeap(), 0, pDelHost);
607
608 return dwError;
609}
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)

Referenced by main().

◆ DisplayArpEntries()

DWORD DisplayArpEntries ( PTCHAR  pszInetAddr,
PTCHAR  pszIfAddr 
)

Definition at line 202 of file arp.c.

203{
204 DWORD i, k, dwCount;
205 PMIB_IPNETTABLE pIpNetTable = NULL;
206 PMIB_IPADDRTABLE pIpAddrTable = NULL;
207 ULONG Size = 0;
208 struct in_addr inaddr, inaddr2;
209 PTCHAR pszIpAddr;
210 TCHAR szIntIpAddr[20];
211 DWORD dwError = NO_ERROR;
212
213 /* retrieve the IP-to-physical address mapping table */
214
215 /* get table size */
216 GetIpNetTable(pIpNetTable, &Size, 0);
217
218 /* allocate memory for ARP address table */
219 pIpNetTable = (PMIB_IPNETTABLE)HeapAlloc(GetProcessHeap(), 0, Size);
220 if (pIpNetTable == NULL)
221 {
222 PrintMessage(MSG_ARP_NO_MEMORY);
223 dwError = ERROR_NOT_ENOUGH_MEMORY;
224 goto cleanup;
225 }
226
227 ZeroMemory(pIpNetTable, sizeof(*pIpNetTable));
228
229 dwError = GetIpNetTable(pIpNetTable, &Size, TRUE);
230 if (dwError != NO_ERROR)
231 {
232 _tprintf(_T("GetIpNetTable failed: %lu\n"), dwError);
234 goto cleanup;
235 }
236
237 /* check there are entries in the table */
238 if (pIpNetTable->dwNumEntries == 0)
239 {
240 PrintMessage(MSG_ARP_NO_ENTRIES);
241 goto cleanup;
242 }
243
244 /* Retrieve the interface-to-ip address mapping
245 * table to get the IP address for adapter */
246
247 /* get table size */
248 Size = 0;
249 GetIpAddrTable(pIpAddrTable, &Size, 0);
250
251 pIpAddrTable = (PMIB_IPADDRTABLE)HeapAlloc(GetProcessHeap(), 0, Size);
252 if (pIpAddrTable == NULL)
253 {
254 PrintMessage(MSG_ARP_NO_MEMORY);
255 dwError = ERROR_NOT_ENOUGH_MEMORY;
256 goto cleanup;
257 }
258
259 ZeroMemory(pIpAddrTable, sizeof(*pIpAddrTable));
260
261 dwError = GetIpAddrTable(pIpAddrTable, &Size, TRUE);
262 if (dwError != NO_ERROR)
263 {
264 _tprintf(_T("GetIpAddrTable failed: %lu\n"), dwError);
266 goto cleanup;
267 }
268
269 for (k = 0; k < pIpAddrTable->dwNumEntries; k++)
270 {
271 if (pIpNetTable->table[0].dwIndex == pIpAddrTable->table[k].dwIndex)
272 {
273 //printf("debug print: pIpAddrTable->table[?].dwIndex = %lx\n", pIpNetTable->table[k].dwIndex);
274 inaddr2.s_addr = pIpAddrTable->table[k].dwAddr;
275 pszIpAddr = inet_ntoa(inaddr2);
276 strcpy(szIntIpAddr, pszIpAddr);
277 }
278 }
279
280 /* Count relevant ARP entries */
281 dwCount = 0;
282 for (i = 0; i < pIpNetTable->dwNumEntries; i++)
283 {
284 /* if the user has supplied their own internet address *
285 * only count the arp entry which matches that */
286 if (pszInetAddr)
287 {
288 inaddr.S_un.S_addr = pIpNetTable->table[i].dwAddr;
289 pszIpAddr = inet_ntoa(inaddr);
290
291 /* check if it matches, count it */
292 if (strcmp(pszIpAddr, pszInetAddr) == 0)
293 dwCount++;
294 }
295 else
296 {
297 /* if an address is not supplied, count all entries */
298 dwCount++;
299 }
300 }
301
302 /* Print message and leave if there are no relevant ARP entries */
303 if (dwCount == 0)
304 {
305 PrintMessage(MSG_ARP_NO_ENTRIES);
306 goto cleanup;
307 }
308
309 /* print header, including interface IP address and index number */
310 PrintMessageV(MSG_ARP_INTERFACE, szIntIpAddr, pIpNetTable->table[0].dwIndex);
311
312 /* go through all ARP entries */
313 for (i = 0; i < pIpNetTable->dwNumEntries; i++)
314 {
315
316 /* if the user has supplied their own internet address *
317 * only print the arp entry which matches that */
318 if (pszInetAddr)
319 {
320 inaddr.S_un.S_addr = pIpNetTable->table[i].dwAddr;
321 pszIpAddr = inet_ntoa(inaddr);
322
323 /* check if it matches, print it */
324 if (strcmp(pszIpAddr, pszInetAddr) == 0)
325 PrintEntries(&pIpNetTable->table[i]);
326 }
327 else
328 /* if an address is not supplied, print all entries */
329 PrintEntries(&pIpNetTable->table[i]);
330 }
331
332cleanup:
333 if (pIpNetTable != NULL)
334 HeapFree(GetProcessHeap(), 0, pIpNetTable);
335 if (pIpAddrTable != NULL)
336 HeapFree(GetProcessHeap(), 0, pIpAddrTable);
337
338 return dwError;
339}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
DWORD PrintEntries(PMIB_IPNETROW pIpAddRow)
Definition: arp.c:150
DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder)
struct _MIB_IPADDRTABLE * PMIB_IPADDRTABLE
#define inet_ntoa(addr)
Definition: inet.h:100
int k
Definition: mpi.c:3369
char * PTCHAR
Definition: ntbasedef.h:476
DWORD dwAddr
Definition: ipmib.h:36
IF_INDEX dwIndex
Definition: ipmib.h:37
MIB_IPADDRROW table[1]
Definition: ipmib.h:48
DWORD dwNumEntries
Definition: ipmib.h:47
DWORD dwNumEntries
Definition: ipmib.h:127
Definition: tcpip.h:126
char TCHAR
Definition: xmlstorage.h:189

Referenced by main().

◆ DoFormatMessage()

DWORD DoFormatMessage ( VOID  )

Definition at line 63 of file arp.c.

64{
65 LPTSTR lpMsgBuf;
66 DWORD RetVal;
67
69
71 {
75 NULL,
77 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
78 (LPTSTR) &lpMsgBuf,
79 0,
80 NULL );
81
82 if (RetVal != 0)
83 {
84 _tprintf(_T("%s"), lpMsgBuf);
85 LocalFree(lpMsgBuf);
86 /* return number of TCHAR's stored in output buffer
87 * excluding '\0' - as FormatMessage does*/
88 return RetVal;
89 }
90 }
91 return 0;
92}
#define ERROR_SUCCESS
Definition: deptool.c:10
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define LANG_NEUTRAL
Definition: nls.h:22
#define MAKELANGID(p, s)
Definition: nls.h:15
#define SUBLANG_DEFAULT
Definition: nls.h:168
#define FormatMessage
Definition: winbase.h:3795
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:420
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:423
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:419
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by Addhost(), Deletehost(), and DisplayArpEntries().

◆ main()

INT main ( int argc  ,
char argv[] 
)

Definition at line 627 of file arp.c.

628{
629 DWORD dwError = NO_ERROR;
630
631 if ((argc < 2) || (argc > 5))
632 {
633 Usage();
634 return EXIT_FAILURE;
635 }
636
637 if (argv[1][0] != '-')
638 {
639 Usage();
640 return EXIT_SUCCESS;
641 }
642
643 switch (argv[1][1])
644 {
645 case 'a': /* fall through */
646 case 'g':
647 if (argc == 2)
648 dwError = DisplayArpEntries(NULL, NULL);
649 else if (argc == 3)
650 dwError = DisplayArpEntries(argv[2], NULL);
651 else if ((argc == 4) && ((strcmp(argv[2], "-N")) == 0))
652 dwError = DisplayArpEntries(NULL, argv[3]);
653 else if ((argc == 5) && ((strcmp(argv[3], "-N")) == 0))
654 dwError = DisplayArpEntries(argv[2], argv[4]);
655 else
656 {
657 Usage();
658 dwError = ERROR_INVALID_PARAMETER;
659 }
660 break;
661
662 case 'd':
663 if (argc == 3)
664 dwError = Deletehost(argv[2], NULL);
665 else if (argc == 4)
666 dwError = Deletehost(argv[2], argv[3]);
667 else
668 {
669 Usage();
670 dwError = ERROR_INVALID_PARAMETER;
671 }
672 break;
673
674 case 's':
675 if (argc == 4)
676 dwError = Addhost(argv[2], argv[3], NULL);
677 else if (argc == 5)
678 dwError = Addhost(argv[2], argv[3], argv[4]);
679 else
680 {
681 Usage();
682 dwError = ERROR_INVALID_PARAMETER;
683 }
684 break;
685
686 default:
687 Usage();
688 dwError = ERROR_INVALID_PARAMETER;
689 break;
690 }
691
692 return (dwError == NO_ERROR) ? EXIT_SUCCESS : EXIT_FAILURE;
693}
static int argc
Definition: ServiceArgs.c:12
DWORD DisplayArpEntries(PTCHAR pszInetAddr, PTCHAR pszIfAddr)
Definition: arp.c:202
DWORD Addhost(PTCHAR pszInetAddr, PTCHAR pszEthAddr, PTCHAR pszIfAddr)
Definition: arp.c:349
DWORD Deletehost(PTCHAR pszInetAddr, PTCHAR pszIfAddr)
Definition: arp.c:495
#define EXIT_FAILURE
Definition: jerror.c:33
#define argv
Definition: mplay32.c:18
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55

◆ PrintEntries()

DWORD PrintEntries ( PMIB_IPNETROW  pIpAddRow)

Definition at line 150 of file arp.c.

151{
152 IN_ADDR inaddr;
153 TCHAR cMacAddr[20];
154
155 /* print IP addresses */
156 inaddr.S_un.S_addr = pIpAddRow->dwAddr;
157 _tprintf(_T(" %-22s"), inet_ntoa(inaddr));
158
159 /* print MAC address */
160 _stprintf(cMacAddr, _T("%02x-%02x-%02x-%02x-%02x-%02x"),
161 pIpAddRow->bPhysAddr[0],
162 pIpAddRow->bPhysAddr[1],
163 pIpAddRow->bPhysAddr[2],
164 pIpAddRow->bPhysAddr[3],
165 pIpAddRow->bPhysAddr[4],
166 pIpAddRow->bPhysAddr[5]);
167 _tprintf(_T("%-22s"), cMacAddr);
168
169 /* print cache type */
170 switch (pIpAddRow->dwType)
171 {
173 PrintMessage(MSG_ARP_DYNAMIC);
174 break;
175
177 PrintMessage(MSG_ARP_STATIC);
178 break;
179
181 PrintMessage(MSG_ARP_INVALID);
182 break;
183
185 PrintMessage(MSG_ARP_OTHER);
186 break;
187 }
188 _putts(_T(""));
189 return NO_ERROR;
190}
#define _putts
Definition: tchar.h:587
@ MIB_IPNET_TYPE_DYNAMIC
Definition: ipmib.h:108
@ MIB_IPNET_TYPE_INVALID
Definition: ipmib.h:107
@ MIB_IPNET_TYPE_OTHER
Definition: ipmib.h:106
#define _stprintf
Definition: utility.h:124
u_long S_addr
Definition: tcpip.h:131
union in_addr::@1020 S_un

Referenced by DisplayArpEntries().

◆ PrintMessage()

VOID PrintMessage ( DWORD  dwMessage)

Definition at line 95 of file arp.c.

97{
98 LPTSTR lpMsgBuf;
99 DWORD RetVal;
100
105 dwMessage,
107 (LPTSTR)&lpMsgBuf,
108 0,
109 NULL);
110 if (RetVal != 0)
111 {
112 _tprintf(_T("%s"), lpMsgBuf);
113 LocalFree(lpMsgBuf);
114 }
115}
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:422

Referenced by Addhost(), Deletehost(), DisplayArpEntries(), PrintEntries(), and Usage().

◆ PrintMessageV()

VOID PrintMessageV ( DWORD  dwMessage,
  ... 
)

Definition at line 118 of file arp.c.

121{
122 LPTSTR lpMsgBuf;
123 va_list args = NULL;
124 DWORD RetVal;
125
126 va_start(args, dwMessage);
127
130 dwMessage,
132 (LPTSTR)&lpMsgBuf,
133 0,
134 &args);
135 va_end(args);
136
137 if (RetVal != 0)
138 {
139 _tprintf(_T("%s"), lpMsgBuf);
140 LocalFree(lpMsgBuf);
141 }
142}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
Definition: match.c:390

Referenced by Addhost(), Deletehost(), and DisplayArpEntries().

◆ Usage()

VOID Usage ( VOID  )

Definition at line 616 of file arp.c.

617{
618 PrintMessage(MSG_ARP_SYNTAX);
619}

Variable Documentation

◆ _CRT_glob

int _CRT_glob = 0

Definition at line 48 of file arp.c.

◆ SEPARATOR

const char SEPARATOR = '-'

Definition at line 47 of file arp.c.

Referenced by Addhost().