6、)>=0&&*(mac+j)<=9)
mac_addr[i]=(unsigned char)(*(mac+j)-0);
if(*(mac+j)>=a&&*(mac+j)<=z)
mac_addr[i]=(unsigned char)(*(mac+j)-a+10);
if(*(mac+j)>=A&&*(mac+j)<=Z)
mac_addr[i]=(unsigned char)(*(mac+j)-A+10);
j++;
mac_addr[i]*=16;
if(*(mac+j)>=0&&*(mac+j)<=9)
m
7、ac_addr[i]+=(unsigned char)(*(mac+j)-0);
if(*(mac+j)>=a&&*(mac+j)<=z)
mac_addr[i]+=(unsigned char)(*(mac+j)-a+10);
if(*(mac+j)>=A&&*(mac+j)<=Z)
mac_addr[i]+=(unsigned char)(*(mac+j)-A+10);
j++;
}
return 1;
}
int CheckIP(char *argv,unsigned char *ip_addr)
{
char ip[16];
int
8、 i=0,j=0,k=0;
strcpy(ip,argv);
int m=strlen(argv);
for(i=0;i.&&ip[i]<0)||ip[i]>9)
{
cout<<"IP address error!"<
9、(j>3)
{
cout<<"IP address error!"<3)
{
cout<<"IP address error!"<
10、ned char)atoi(ip+j);
}
return 1;
}
void main(int argc,char *argv[])
{
if(argc!=5)
{
cout<<"please input command: SendArp source_ip source_mac dest_ip dest_mac"<
11、ame.DstMAC))
return;
if(!CheckMAC(argv[2],arpPacket.phyFrame.SrcMAC))
return;
arpPacket.phyFrame.FrameType=htons((unsigned short)0x0608);
arpPacket.arpFrame.HardwareType=(unsigned short)0x0100;
arpPacket.arpFrame.ProtocolType=(unsigned short)0x0008;
arpPacket.arpFrame.MACLen=(uns
12、igned char)6;
arpPacket.arpFrame.IPLen=(unsigned char)4;
if(!CheckMAC(argv[2],arpPacket.arpFrame.SrcMAC))
return;
if(!CheckIP(argv[1],arpPacket.arpFrame.SrcIP))
return;
if(!CheckMAC(argv[4],arpPacket.arpFrame.DstMAC))
return;
if(!CheckIP(argv[3],arpPacket.arpFrame.DstIP))
retur
13、n;
for(i=0;i<18;i++)
arpPacket.arpFrame.Padding[i]=0;
pcap_if_t *alldevs;
pcap_if_t *d,*head=NULL;
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
if(pcap_findalldevs(&alldevs,errbuf)==-1)
{
cout<<"Unable to create adapter list!"<
14、lldevs;d;d=d->next)
{
cout<<++i<<": "<name;
if(d->description)
cout<<" "<description<>k;
if(k<1||k>i)
{
cout
15、<<"Out of range!"<next,i++);
head=d;
if((fp=pcap_open_live(head->name,1000,1,1000,errbuf))==NULL)
{
cout<<"Unable to open the adapter!"<
16、igned char*)&arpPacket,sizeof((unsigned char*)&arpPacket))==-1)
{
cout<<"ARP packet send error!"<