- s = socket(PF_INET, SOCK_DGRAM, 0);
- if (s < 0)
- {
- perror("socket");
- exit(-1);
- }
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
- if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0)
- {
- perror("get eth0 hwaddr");
- exit(-1);
- }
- memcpy(mac, &ifr.ifr_hwaddr.sa_data, 6*sizeof(char));
- if (ioctl(s, SIOCGIFINDEX, &ifr) < 0)
- {
- perror("get eth0 ifindex");
- exit(-1);
- }
- close(s);
- sendarp(ifr.ifr_ifindex, mac, ip);
+ s = socket(PF_INET, SOCK_DGRAM, 0);
+ if (s < 0)
+ {
+ log(0, 0, 0, 0, "Error creating socket for GARP: %s\n", strerror(errno));
+ return;
+ }
+ memset(&ifr, 0, sizeof(ifr));
+ strncpy(ifr.ifr_name, "eth0", sizeof(ifr.ifr_name) - 1);
+ if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0)
+ {
+ log(0, 0, 0, 0, "Error getting eth0 hardware address for GARP: %s\n", strerror(errno));
+ close(s);
+ return;
+ }
+ memcpy(mac, &ifr.ifr_hwaddr.sa_data, 6*sizeof(char));
+ if (ioctl(s, SIOCGIFINDEX, &ifr) < 0)
+ {
+ log(0, 0, 0, 0, "Error getting eth0 interface index for GARP: %s\n", strerror(errno));
+ close(s);
+ return;
+ }
+ close(s);
+ sendarp(ifr.ifr_ifindex, mac, ip);