不错的一篇玩转arp的文章(3)
strcpy(sa.sa_data,DEFAULT_DEVICE);
for (j=0;j {
if (sendto(sock,&pkt,sizeof(pkt),0,&sa,sizeof(sa)) < 0)
{
perror("sendto");
exit(1);
}
}
exit(0);
}
void die (char *str)
{
fprintf(stderr,"%s ",str);
exit(1);
}
void get_ip_addr (struct in_addr *in_addr, char *str)
{
struct hostent *hostp;
in_addr->s_addr = inet_addr(str);
if(in_addr->s_addr == -1)
{
if ((hostp = gethostbyname(str)))
bcopy(hostp->h_addr, in_addr, hostp->h_length);
else {
fprintf(stderr, "send_arp: unknown host %s ", str);
exit(1);
}
}
}
void get_hw_addr (char *buf, char *str)
{
int i;
char c, val;
for(i = 0; i < ETH_HW_ADDR_LEN; i++)
{
if (!(c = tolower(*str++)))
die("Invalid hardware address");
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c-'a'+10;
else
die("Invalid hardware address");
*buf = val << 4;
if (!(c = tolower(*str++)))
die("Invalid hardware address");
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c-'a'+10;
else
die("Invalid hardware address");
*buf++ |= val;
if (*str == ':')
str++;
}
}
内容版权声明:除非注明,否则皆为本站原创文章。