mac address를 출력하는 프로그램을 짰는데 자꾸 에러가 나요..

아래와 같이 프로그램을 짰는데, 자꾸 no entry in arp_cache for 에러 메세지가 납니다.
어디가 잘못된건지 좀 가르쳐 주세요..
#include
#include
#include
#include
#include
#include
int main()
{
struct sockaddr_in sin = {0};
struct arpreq myarp ={0};
int sockfd;
unsigned char *ptr;
sin.sin_family = AF_INET;
sin.sin_addr.s_addr=inet_addr("202.211.176.244");
sin.sin_port = htons(2000);
printf("sin= %d, arp=%d\n",sizeof(sin),sizeof(myarp) );
memcpy(&myarp.arp_pa, &sin, sizeof(sin) );
strcpy(myarp.arp_dev, "eth0");
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
printf("cannot open socket\n");
exit(0);
}
if (ioctl(sockfd, SIOCGARP, &myarp) == -1) {
printf("no entry in arp_cache for \n");
exit(0);
}
ptr = &myarp.arp_ha.sa_data[0];
printf("MAC address is ");
printf("%x%x%x%x%x%x\n",*ptr, *(ptr+1),*(ptr+2), *(ptr+3),*(ptr+4),*(ptr+5));
}
댓글 달기