ReactOS  0.4.15-dev-1152-g6c94e4f
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 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 347 of file arp.c.

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

Referenced by main().

◆ Deletehost()

DWORD Deletehost ( PTCHAR  pszInetAddr,
PTCHAR  pszIfAddr 
)

Definition at line 493 of file arp.c.

494 {
495  PMIB_IPNETROW pDelHost = NULL;
496  PMIB_IPNETTABLE pIpNetTable = NULL;
497  ULONG Size = 0;
498  DWORD dwIpAddr = 0;
499  BOOL bFlushTable = FALSE;
500  DWORD dwError = NO_ERROR;
501 
502  /* error checking */
503 
504  /* check IP address */
505  if (pszInetAddr == NULL)
506  {
507  Usage();
509  }
510 
511  /* if wildcard is given, set flag to delete all hosts */
512  if (strncmp(pszInetAddr, "*", 1) == 0)
513  {
514  bFlushTable = TRUE;
515  }
516  else
517  {
518  dwIpAddr = inet_addr(pszInetAddr);
519  if (dwIpAddr == INADDR_NONE)
520  {
521  PrintMessageV(10001, pszInetAddr);
523  }
524  }
525 
526  /* We need the IpNetTable to get the adapter index */
527  /* Return required buffer size */
528  GetIpNetTable(NULL, &Size, 0);
529 
530  /* allocate memory for ARP address table */
531  pIpNetTable = (PMIB_IPNETTABLE) HeapAlloc(GetProcessHeap(), 0, Size);
532  if (pIpNetTable == NULL)
533  {
534  PrintMessage(10004);
535  dwError = ERROR_NOT_ENOUGH_MEMORY;
536  goto cleanup;
537  }
538 
539  ZeroMemory(pIpNetTable, sizeof(*pIpNetTable));
540 
541  dwError = GetIpNetTable(pIpNetTable, &Size, TRUE);
542  if (dwError != NO_ERROR)
543  {
544  _tprintf(_T("GetIpNetTable failed: %lu\n"), dwError);
545  DoFormatMessage();
546  goto cleanup;
547  }
548 
549  /* reserve memory on heap and zero */
550  pDelHost = (MIB_IPNETROW *)HeapAlloc(GetProcessHeap(), 0, sizeof(MIB_IPNETROW));
551  if (pDelHost == NULL)
552  {
553  PrintMessage(10004);
554  dwError = ERROR_NOT_ENOUGH_MEMORY;
555  goto cleanup;
556  }
557 
558  ZeroMemory(pDelHost, sizeof(MIB_IPNETROW));
559 
560  /* set dwIndex field to the index of a local IP address to
561  * indicate the network on which the ARP entry applies */
562  if (pszIfAddr)
563  {
564  if (sscanf(pszIfAddr, "%lx", &pDelHost->dwIndex) == EOF)
565  {
566  goto cleanup;
567  }
568  }
569  else
570  {
571  /* needs testing. I get the correct index on my machine, but need others
572  * to test their card index. Any problems and we can use GetAdaptersInfo instead */
573  pDelHost->dwIndex = pIpNetTable->table[0].dwIndex;
574  }
575 
576  if (bFlushTable != FALSE)
577  {
578  /* delete arp cache */
579  dwError = FlushIpNetTable(pDelHost->dwIndex);
580  if (dwError != NO_ERROR)
581  {
582  DoFormatMessage();
583  goto cleanup;
584  }
585  }
586  else
587  {
588  /* copy converted IP address */
589  pDelHost->dwAddr = dwIpAddr;
590 
591  /* Delete the ARP entry */
592  dwError = DeleteIpNetEntry(pDelHost);
593  if (dwError != NO_ERROR)
594  {
595  DoFormatMessage();
596  goto cleanup;
597  }
598  }
599 
600 cleanup:
601  if (pIpNetTable != NULL)
602  HeapFree(GetProcessHeap(), 0, pIpNetTable);
603  if (pDelHost != NULL)
604  HeapFree(GetProcessHeap(), 0, pDelHost);
605 
606  return dwError;
607 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define _tprintf
Definition: tchar.h:506
#define inet_addr(cp)
Definition: inet.h:98
DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex)
#define TRUE
Definition: types.h:120
#define INADDR_NONE
Definition: tcp.c:42
DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder)
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define ZeroMemory
Definition: winbase.h:1648
#define NO_ERROR
Definition: dderror.h:5
struct _MIB_IPNETTABLE * PMIB_IPNETTABLE
DWORD dwAddr
Definition: ipmib.h:117
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define _T(x)
Definition: vfdio.h:22
#define GetProcessHeap()
Definition: compat.h:484
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD DoFormatMessage(VOID)
Definition: arp.c:61
VOID PrintMessage(DWORD dwMessage)
Definition: arp.c:93
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
MIB_IPNETROW table[1]
Definition: ipmib.h:128
struct _MIB_IPNETROW MIB_IPNETROW
VOID PrintMessageV(DWORD dwMessage,...)
Definition: arp.c:116
#define EOF
Definition: stdio.h:24
VOID Usage(VOID)
Definition: arp.c:614
unsigned int ULONG
Definition: retypes.h:1
DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry)
char * cleanup(char *str)
Definition: wpickclick.c:99
DWORD dwIndex
Definition: ipmib.h:114
#define HeapFree(x, y, z)
Definition: compat.h:483

Referenced by main().

◆ DisplayArpEntries()

DWORD DisplayArpEntries ( PTCHAR  pszInetAddr,
PTCHAR  pszIfAddr 
)

Definition at line 200 of file arp.c.

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

Referenced by main().

◆ DoFormatMessage()

DWORD DoFormatMessage ( VOID  )

Definition at line 61 of file arp.c.

62 {
63  LPTSTR lpMsgBuf;
64  DWORD RetVal;
65 
67 
68  if (ErrorCode != ERROR_SUCCESS)
69  {
73  NULL,
74  ErrorCode,
75  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
76  (LPTSTR) &lpMsgBuf,
77  0,
78  NULL );
79 
80  if (RetVal != 0)
81  {
82  _tprintf(_T("%s"), lpMsgBuf);
83  LocalFree(lpMsgBuf);
84  /* return number of TCHAR's stored in output buffer
85  * excluding '\0' - as FormatMessage does*/
86  return RetVal;
87  }
88  }
89  return 0;
90 }
#define _tprintf
Definition: tchar.h:506
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
#define ERROR_SUCCESS
Definition: deptool.c:10
#define LANG_NEUTRAL
Definition: nls.h:22
#define SUBLANG_DEFAULT
Definition: nls.h:168
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:404
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FormatMessage
Definition: winbase.h:3635
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define MAKELANGID(p, s)
Definition: nls.h:15

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

◆ main()

INT main ( int argc  ,
char argv[] 
)

Definition at line 625 of file arp.c.

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

◆ PrintEntries()

DWORD PrintEntries ( PMIB_IPNETROW  pIpAddRow)

Definition at line 148 of file arp.c.

149 {
150  IN_ADDR inaddr;
151  TCHAR cMacAddr[20];
152 
153  /* print IP addresses */
154  inaddr.S_un.S_addr = pIpAddRow->dwAddr;
155  _tprintf(_T(" %-22s"), inet_ntoa(inaddr));
156 
157  /* print MAC address */
158  _stprintf(cMacAddr, _T("%02x-%02x-%02x-%02x-%02x-%02x"),
159  pIpAddRow->bPhysAddr[0],
160  pIpAddRow->bPhysAddr[1],
161  pIpAddRow->bPhysAddr[2],
162  pIpAddRow->bPhysAddr[3],
163  pIpAddRow->bPhysAddr[4],
164  pIpAddRow->bPhysAddr[5]);
165  _tprintf(_T("%-22s"), cMacAddr);
166 
167  /* print cache type */
168  switch (pIpAddRow->dwType)
169  {
171  PrintMessage(10007);
172  break;
173 
175  PrintMessage(10008);
176  break;
177 
179  PrintMessage(10006);
180  break;
181 
183  PrintMessage(10005);
184  break;
185  }
186  _putts(_T(""));
187  return NO_ERROR;
188 }
#define _tprintf
Definition: tchar.h:506
union in_addr::@1020 S_un
#define NO_ERROR
Definition: dderror.h:5
DWORD dwAddr
Definition: ipmib.h:117
BYTE bPhysAddr[MAXLEN_PHYSADDR]
Definition: ipmib.h:116
#define inet_ntoa(addr)
Definition: inet.h:100
#define _putts
Definition: tchar.h:587
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
Definition: tcpip.h:125
VOID PrintMessage(DWORD dwMessage)
Definition: arp.c:93
u_long S_addr
Definition: tcpip.h:131
#define _stprintf
Definition: utility.h:124
DWORD dwType
Definition: ipmib.h:120

Referenced by DisplayArpEntries().

◆ PrintMessage()

VOID PrintMessage ( DWORD  dwMessage)

Definition at line 93 of file arp.c.

95 {
96  LPTSTR lpMsgBuf;
97  DWORD RetVal;
98 
103  dwMessage,
105  (LPTSTR)&lpMsgBuf,
106  0,
107  NULL);
108  if (RetVal != 0)
109  {
110  _tprintf(_T("%s"), lpMsgBuf);
111  LocalFree(lpMsgBuf);
112  }
113 }
#define _tprintf
Definition: tchar.h:506
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FormatMessage
Definition: winbase.h:3635
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:401
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

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

◆ PrintMessageV()

VOID PrintMessageV ( DWORD  dwMessage,
  ... 
)

Definition at line 116 of file arp.c.

119 {
120  LPTSTR lpMsgBuf;
121  va_list args = NULL;
122  DWORD RetVal;
123 
124  va_start(args, dwMessage);
125 
128  dwMessage,
130  (LPTSTR)&lpMsgBuf,
131  0,
132  &args);
133  va_end(args);
134 
135  if (RetVal != 0)
136  {
137  _tprintf(_T("%s"), lpMsgBuf);
138  LocalFree(lpMsgBuf);
139  }
140 }
#define _tprintf
Definition: tchar.h:506
Definition: match.c:390
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define va_end(ap)
Definition: acmsvcex.h:90
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:400
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:403
#define _T(x)
Definition: vfdio.h:22
unsigned long DWORD
Definition: ntddk_ex.h:95
#define FormatMessage
Definition: winbase.h:3635
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
#define va_start(ap, A)
Definition: acmsvcex.h:91
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50

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

◆ Usage()

VOID Usage ( VOID  )

Definition at line 614 of file arp.c.

615 {
616  PrintMessage(10000);
617 }
VOID PrintMessage(DWORD dwMessage)
Definition: arp.c:93

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

Variable Documentation

◆ _CRT_glob

int _CRT_glob = 0

Definition at line 46 of file arp.c.

◆ SEPARATOR

const char SEPARATOR = '-'

Definition at line 45 of file arp.c.

Referenced by Addhost().