advert = 4,
quiet = 8,
quit_on_reply = 16,
- unicasting = 32,
- broadcast_only = 64
+ broadcast_only = 32,
+ unicasting = 64
};
static int cfg;
{
int err;
struct timeval now;
- unsigned char buf[256];
+ RESERVE_CONFIG_UBUFFER(buf, 256);
struct arphdr *ah = (struct arphdr *) buf;
unsigned char *p = (unsigned char *) (ah + 1);
if (!(cfg&unicasting))
brd_sent++;
}
+ RELEASE_CONFIG_BUFFER(buf);
return err;
}
static void finish(void)
{
if (!(cfg&quiet)) {
- printf("Sent %d probes (%d broadcast(s))\n", sent, brd_sent);
- printf("Received %d repl%s", received, (received > 1) ? "ies" : "y");
+ printf("Sent %d probes (%d broadcast(s))\n"
+ "Received %d repl%s",
+ sent, brd_sent,
+ received, (received > 1) ? "ies" : "y");
if (brd_recv || req_recv) {
printf(" (");
if (req_recv)
gettimeofday(&tv, NULL);
- printf("%s ",
- FROM->sll_pkttype == PACKET_HOST ? "Unicast" : "Broadcast");
- printf("%s from ",
- ah->ar_op == htons(ARPOP_REPLY) ? "reply" : "request");
- printf("%s ", inet_ntoa(src_ip));
- printf("[%s]", ether_ntoa((struct ether_addr *) p));
+ printf("%s %s from %s [%s]",
+ FROM->sll_pkttype == PACKET_HOST ? "Unicast" : "Broadcast",
+ ah->ar_op == htons(ARPOP_REPLY) ? "reply" : "request",
+ inet_ntoa(src_ip),
+ ether_ntoa((struct ether_addr *) p));
if (dst_ip.s_addr != src.s_addr) {
printf("for %s ", inet_ntoa(dst_ip));
s_printed = 1;
{
unsigned long opt;
char *_count, *_timeout, *_device;
+
+ /* Dad also sets quit_on_reply.
+ * Advert also sets unsolicited.
+ */
+ bb_opt_complementally = "Df:AU";
opt = bb_getopt_ulflags(argc, argv, "DUAqfbc:w:i:s:",
&_count, &_timeout, &_device);
- if (opt & 1) { /* Dad */
- cfg |= dad;
- cfg |= quit_on_reply;
- }
- if (opt & 2) /* Unsolicited */
- cfg |= unsolicited;
- if (opt & 4) { /* Advert */
- cfg |= advert;
- cfg |= unsolicited;
- }
- if (opt & 8) /* quiet */
- cfg |= quiet;
- if (opt & 16) /* quit on reply */
- cfg |= quit_on_reply;
- if (opt & 32) /* broadcast only */
- cfg |= broadcast_only;
+ cfg |= opt & 63; /* set respective flags */
if (opt & 64) /* count */
count = atoi(_count);
if (opt & 128) /* timeout */
memset(he.sll_addr, -1, he.sll_halen);
if (!(cfg&quiet)) {
- printf("ARPING to %s", inet_ntoa(dst));
- printf(" from %s via %s\n", inet_ntoa(src),
- device ? device : "unknown");
+ printf("ARPING to %s from %s via %s\n",
+ inet_ntoa(dst), inet_ntoa(src),
+ device ? device : "unknown");
}
if (!src.s_addr && !(cfg&dad)) {
while (1) {
sigset_t sset, osset;
- unsigned char packet[4096];
+ RESERVE_CONFIG_UBUFFER(packet, 4096);
struct sockaddr_ll from;
socklen_t alen = sizeof(from);
int cc;
- if ((cc = recvfrom(s, packet, sizeof(packet), 0,
+ if ((cc = recvfrom(s, packet, 4096, 0,
(struct sockaddr *) &from, &alen)) < 0) {
perror("recvfrom");
continue;
sigprocmask(SIG_BLOCK, &sset, &osset);
recv_pack(packet, cc, &from);
sigprocmask(SIG_SETMASK, &osset, NULL);
+ RELEASE_CONFIG_BUFFER(packet);
}
}