forked from fengzixu/Tracert-And-Ping-Programe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendArp.cpp
121 lines (121 loc) · 3.15 KB
/
SendArp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
///* sendarp.c
// * Link with wsock32.lib and iphlpapi.lib
// */
//#pragma comment(lib,"iphlpapi.lib")
//#pragma comment(lib,"wsock32.lib")
//#include <winsock2.h>
//#include <iphlpapi.h>
//#include <stdio.h>
//
//void usage(char *pname)
//{
// printf("Usage: %s [options] ip-address\n", pname);
// printf("\t -h \t\thelp\n");
// printf("\t -s src-ip \tsource IP address\n");
// exit(1);
//}
//
//int __cdecl main(int argc, char **argv)
//{
// DWORD dwRetVal = 0;
// IPAddr DestIp = 0;
// IPAddr SrcIp = 0; /* default for src ip */
// ULONG MacAddr[2] = {0}; /* for 6-byte hardware addresses */
// ULONG PhysAddrLen = 6; /* default to length of six bytes */
//
// char *DestIpString = NULL;
// char *SrcIpString = NULL;
//
// BYTE *bPhysAddr;
// int i;
//
// if (argc > 1)
// {
// for (i = 1; i < argc; i++)
// {
// if ((argv[i][0] == '-') || (argv[i][0] == '/'))
// {
// switch (tolower(argv[i][1]))
// {
// case 's':
// SrcIpString = argv[++i];
// SrcIp = inet_addr(SrcIpString);
// break;
// case 'h':
// default:
// usage(argv[0]);
// break;
// }/* end switch */
// }
// else
// {
// DestIpString = argv[i];
// }
// }/* end for */
// }
// else
// {
// usage(argv[0]);
// }
// if (DestIpString == NULL || DestIpString[0] == '\0')
// {
// usage(argv[0]);
// }
// DestIp = inet_addr(DestIpString);
// printf("Sending ARP request for IP address: %s\n", DestIpString);
// PhysAddrLen = sizeof(MacAddr);
// memset(&MacAddr, 0xff, sizeof (MacAddr));
// dwRetVal = SendARP(DestIp, SrcIp, &MacAddr, &PhysAddrLen);
// if (dwRetVal == NO_ERROR)
// {
// bPhysAddr = (BYTE *) &MacAddr;
// if (PhysAddrLen)
// {
// for (i = 0; i < (int) PhysAddrLen; i++)
// {
// if (i == (PhysAddrLen - 1))
// {
// printf("%.2X\n", (int) bPhysAddr[i]);
// }
// else
// {
// printf("%.2X-", (int) bPhysAddr[i]);
// }
// }
// }
// else
// {
// printf("Warning: SendArp completed successfully, but returned length=0\n");
// }
// }
// else
// {
// printf("Error: SendArp failed with error: %d", dwRetVal);
// switch (dwRetVal)
// {
// case ERROR_GEN_FAILURE:
// printf(" (ERROR_GEN_FAILURE)\n");
// break;
// case ERROR_INVALID_PARAMETER:
// printf(" (ERROR_INVALID_PARAMETER)\n");
// break;
// case ERROR_INVALID_USER_BUFFER:
// printf(" (ERROR_INVALID_USER_BUFFER)\n");
// break;
// case ERROR_BAD_NET_NAME:
// printf(" (ERROR_GEN_FAILURE)\n");
// break;
// case ERROR_BUFFER_OVERFLOW:
// printf(" (ERROR_BUFFER_OVERFLOW)\n");
// break;
// case ERROR_NOT_FOUND:
// printf(" (ERROR_NOT_FOUND)\n");
// break;
// default:
// printf("\n");
// break;
// }
// }
// return 0;
//}
//