#define received (G.received )
#define brd_recv (G.brd_recv )
#define req_recv (G.req_recv )
-#define INIT_G() \
- do { \
- count = -1; \
- } while (0)
+#define INIT_G() do { \
+ count = -1; \
+} while (0)
+
+// If GNUisms are not available...
+//static void *mempcpy(void *_dst, const void *_src, int n)
+//{
+// memcpy(_dst, _src, n);
+// return (char*)_dst + n;
+//}
static int send_pack(struct in_addr *src_addr,
struct in_addr *dst_addr, struct sockaddr_ll *ME,
struct arphdr *ah = (struct arphdr *) buf;
unsigned char *p = (unsigned char *) (ah + 1);
- ah->ar_hrd = htons(ME->sll_hatype);
ah->ar_hrd = htons(ARPHRD_ETHER);
ah->ar_pro = htons(ETH_P_IP);
ah->ar_hln = ME->sll_halen;
ah->ar_pln = 4;
ah->ar_op = option_mask32 & ADVERT ? htons(ARPOP_REPLY) : htons(ARPOP_REQUEST);
- memcpy(p, &ME->sll_addr, ah->ar_hln);
- p += ME->sll_halen;
-
- memcpy(p, src_addr, 4);
- p += 4;
+ p = mempcpy(p, &ME->sll_addr, ah->ar_hln);
+ p = mempcpy(p, src_addr, 4);
if (option_mask32 & ADVERT)
- memcpy(p, &ME->sll_addr, ah->ar_hln);
+ p = mempcpy(p, &ME->sll_addr, ah->ar_hln);
else
- memcpy(p, &HE->sll_addr, ah->ar_hln);
- p += ah->ar_hln;
+ p = mempcpy(p, &HE->sll_addr, ah->ar_hln);
- memcpy(p, dst_addr, 4);
- p += 4;
+ p = mempcpy(p, dst_addr, 4);
err = sendto(sock_fd, buf, p - buf, 0, (struct sockaddr *) HE, sizeof(*HE));
if (err == p - buf) {
return err;
}
-static void finish(void) ATTRIBUTE_NORETURN;
+static void finish(void) NORETURN;
static void finish(void)
{
if (!(option_mask32 & QUIET)) {
if (ah->ar_pro != htons(ETH_P_IP)
|| (ah->ar_pln != 4)
|| (ah->ar_hln != me.sll_halen)
- || (len < sizeof(*ah) + 2 * (4 + ah->ar_hln)))
+ || (len < (int)(sizeof(*ah) + 2 * (4 + ah->ar_hln))))
return false;
memcpy(&src_ip, p + ah->ar_hln, 4);
}
int arping_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int arping_main(int argc, char **argv)
+int arping_main(int argc UNUSED_PARAM, char **argv)
{
const char *device = "eth0";
char *source = NULL;
err_str = xasprintf("interface %s %%s", device);
{
unsigned opt;
- char *str_count, *str_timeout;
+ char *str_timeout;
/* Dad also sets quit_on_reply.
* Advert also sets unsolicited.
*/
- opt_complementary = "=1:Df:AU";
+ opt_complementary = "=1:Df:AU:c+";
opt = getopt32(argv, "DUAqfbc:w:I:s:",
- &str_count, &str_timeout, &device, &source);
- if (opt & 0x40) /* -c: count */
- count = xatoi_u(str_count);
+ &count, &str_timeout, &device, &source);
if (opt & 0x80) /* -w: timeout */
timeout_us = xatou_range(str_timeout, 0, INT_MAX/2000000) * 1000000 + 500000;
//if (opt & 0x200) /* -s: source */
printf(" from %s via %s\n", inet_ntoa(src), device);
}
- {
- struct sigaction sa;
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_flags = SA_RESTART;
-
- sa.sa_handler = (void (*)(int)) finish;
- sigaction(SIGINT, &sa, NULL);
-
- sa.sa_handler = (void (*)(int)) catcher;
- sigaction(SIGALRM, &sa, NULL);
- }
+ signal_SA_RESTART_empty_mask(SIGINT, (void (*)(int))finish);
+ signal_SA_RESTART_empty_mask(SIGALRM, (void (*)(int))catcher);
catcher();