int ip_conflict_check(char *device, char *ip)
{
FILE *fp;
char cmd[64], buf[128];
memset(cmd, 0x00, sizeof(cmd));
sprintf(cmd, "arping -q -D -I %s -c 1 %s; echo $?", device, ip);
if((fp=popen(cmd, "r")) == NULL)
{
perror("popen() Fail");
return -1;
}
memset(buf, 0x00, sizeof(buf));
while(1)
{
if(fgets(buf, sizeof(buf), fp) == NULL) break;
}
pclose(fp);
return buf[0]-0x30;
}
int main(void)
{
char *device="eth0"; //"wlan0" //Network (Ethernet or WiFi) Interface Device
char *ip="192.168.0.254"; //체크하고자 하는 IP
ip_conflict_check(device, ip);
}
'c' 카테고리의 다른 글
fopen() open() Example (0) | 2023.03.07 |
---|---|
log파일 만들기 source (0) | 2023.02.07 |
리눅스 정규식을 이용한 IP / Email 주소 체크 (0) | 2022.09.06 |
구조체 배열 인자로 넘겨서 채우기 (0) | 2022.08.11 |
리눅스 usb mount 예제 (0) | 2021.07.20 |