~ubuntu-branches/debian/stretch/arping/stretch

« back to all changes in this revision

Viewing changes to arping.c

  • Committer: Bazaar Package Importer
  • Author(s): Lenart Janos
  • Date: 2004-03-13 22:50:04 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040313225004-49izij6cwiuhas35
Tags: 2.01-3
* Setgid removed (on control-directory).           (closes: Bug#234481)
* Bashism fixed.                                   (closes: Bug#230342)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
 
2
 * NOTE: This is arping 1.x, arping 2.x is in arping-2/
 
3
 */
 
4
 
 
5
 
 
6
 
 
7
/*
2
8
 * arping
3
9
 *
4
10
 * By Thomas Habets <thomas@habets.pp.se>
12
18
 *
13
19
 * Also finds out IP of specified MAC
14
20
 *
15
 
 * $Id: arping.c,v 1.51 2002/02/12 18:17:47 marvin Exp $
16
 
 */
17
 
/*
18
 
 *  Copyright (C) 2000-2002 Thomas Habets <thomas@habets.pp.se>
19
 
 *
20
 
 *  This library is free software; you can redistribute it and/or
21
 
 *  modify it under the terms of the GNU General Public
22
 
 *  License as published by the Free Software Foundation; either
23
 
 *  version 2 of the License, or (at your option) any later version.
24
 
 *
25
 
 *  This library is distributed in the hope that it will be useful,
26
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
27
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
28
 
 *  General Public License for more details.
29
 
 *
30
 
 *  You should have received a copy of the GNU General Public
31
 
 *  License along with this library; if not, write to the Free Software
32
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
21
 * $Id: arping.c,v 1.64 2003/08/03 23:06:58 marvin Exp $
 
22
 */
 
23
/*
 
24
 *  Copyright (C) 2000-2003 Thomas Habets <thomas@habets.pp.se>
 
25
 *
 
26
 *   This program is free software; you can redistribute it and/or modify
 
27
 *   it under the terms of the GNU General Public License as published by
 
28
 *   the Free Software Foundation; either version 2 of the License, or
 
29
 *   (at your option) any later version.
 
30
 *
 
31
 *   This program is distributed in the hope that it will be useful,
 
32
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
33
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
34
 *   GNU General Public License for more details.
 
35
 *
 
36
 *   You should have received a copy of the GNU General Public License
 
37
 *   along with this program; if not, write to the Free Software
 
38
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
39
 */
 
40
/*
 
41
 * Note to self:
 
42
 *  Test checklist:  (cmac = mac in cisco format (0000.0000.0000)
 
43
 *    command                   expected response
 
44
 *    arping host               pongs
 
45
 *    arping -a host            audiable pongs
 
46
 *    arping mac                pongs
 
47
 *    arping cmac               pongs
 
48
 *    arping -a mac             audiable pongs
 
49
 *    arping -A host            nothing
 
50
 *    arping -A mac             nothing
 
51
 *    arping -t cmac -A host    pongs
 
52
 *    arping -t mac -A host     pongs
 
53
 *    arping -T ip -A mac       pongs
 
54
 *    arping -T ip -A cmac      pongs
 
55
 *    arping -T bcast mac       pongs    # bcast of current net
 
56
 *    arping -r host            mac
 
57
 *    arping -R host            ip
 
58
 *    arping -r mac             ip
 
59
 *    arping -R mac             mac
 
60
 *    arping -rR mac            mac ip
 
61
 *    arping -rR ip             mac ip
 
62
 *    ./arping-scan-net.sh mac  ip
 
63
 * 
 
64
 * Arch checklist:
 
65
 *   Linux/x86         test with debian package libnet0-dev and libnet1-dev
 
66
 *   Linux/sparc
 
67
 *   Linux/hppa
 
68
 *   Solaris/sparc
 
69
 *   NetBSD/alpha      (is libnet or arping unaligned? -- libnet I think)
 
70
 *   OpenBSD/sparc64   (libnet a bit buggy here)
 
71
 *
33
72
 */
34
73
#include <stdio.h>
35
74
#include <stdlib.h>
36
75
#include <unistd.h>
37
 
#include <net/ethernet.h>
38
76
 
39
77
#include <sys/time.h>
40
78
 
79
117
#define DEBUG(a)
80
118
#endif
81
119
 
82
 
const float version = 1.04;
 
120
const float version = 1.08;
83
121
 
84
122
struct ether_addr *mymac;
85
123
static u_char eth_xmas[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
91
129
static const u_int ip_xmas = 0xffffffff;
92
130
 
93
131
static pcap_t *pcap;
94
 
struct bpf_program bpf_prog;
95
 
struct in_addr net,mask;
 
132
//static struct bpf_program bpf_prog;
 
133
//static struct in_addr net,mask;
96
134
#if 0
97
135
// Use this if you want to hard-code a default interface
98
136
static char *ifname = "eth0";
101
139
#endif
102
140
static u_int32_t dip = 0;
103
141
static u_char *packet;
104
 
struct libnet_link_int *linkint;
 
142
static struct libnet_link_int *linkint;
105
143
 
106
144
static unsigned int beep = 0;
107
145
static unsigned int verbose = 0;
114
152
static unsigned int quiet = 0;
115
153
static unsigned int nullip = 0;
116
154
static unsigned int is_promisc = 0;
 
155
static unsigned int addr_must_be_same = 0;
 
156
 
 
157
 
 
158
const char *arping_lookupdev_default(u_int32_t srcip, u_int32_t dstip,
 
159
                                     char *ebuf)
 
160
{
 
161
        static const char *ifname;
 
162
        if (!(ifname = pcap_lookupdev(ebuf))) {
 
163
                return 0;
 
164
        }
 
165
        return ifname;
 
166
}
 
167
 
 
168
#if defined(FINDIF) && defined(linux)
 
169
const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
 
170
{
 
171
        FILE *f;
 
172
        static char buf[1024];
 
173
        char buf1[1024];
 
174
        char buf2[1024];
 
175
        char *p,*p2;
 
176
        int n;
 
177
 
 
178
        libnet_host_lookup_r(dstip,0,buf2);
 
179
        libnet_host_lookup_r(srcip,0,buf1);
 
180
 
 
181
        /*
 
182
         * Construct and run command
 
183
         */
 
184
        snprintf(buf, 1023, "/sbin/ip route get %s from %s 2>&1",
 
185
                 buf2,buf1);
 
186
        DEBUG(printf("%s\n",buf));
 
187
        if (!(f = popen(buf, "r"))) {
 
188
                goto failed;
 
189
        }
 
190
        if (0 > (n = fread(buf, 1, sizeof(buf)-1, f))) {
 
191
                pclose(f);
 
192
                goto failed;
 
193
        }
 
194
        buf[n] = 0;
 
195
        if (-1 == pclose(f)) {
 
196
                perror("arping: pclose()");
 
197
                goto failed;
 
198
        }
 
199
 
 
200
        /*
 
201
         * Parse out device
 
202
         */
 
203
        p = strstr(buf, "dev ");
 
204
        if (!p) {
 
205
                goto failed;
 
206
        }
 
207
 
 
208
        p+=4;
 
209
 
 
210
        p2 = strchr(p, ' ');
 
211
        if (!p2) {
 
212
                goto failed;
 
213
        }
 
214
        *p2 = 0;
 
215
        return p;
 
216
 failed:
 
217
        return arping_lookupdev_default(srcip,dstip,ebuf);
 
218
}
 
219
#else
 
220
const char *arping_lookupdev(u_int32_t srcip, u_int32_t dstip, char *ebuf)
 
221
{
 
222
        return arping_lookupdev_default(srcip,dstip,ebuf);
 
223
}
 
224
#endif
117
225
 
118
226
static void sigint(int i)
119
227
{
143
251
{
144
252
        printf("ARPing %1.2f, by Thomas Habets <thomas@habets.pp.se>\n",
145
253
               version);
146
 
        printf("usage: arping [ -qvrRd0bp ] [ -S <host/ip> ] [ -T <host/ip ]"
147
 
               " [ -s <MAC> ]\n"
 
254
        printf("usage: arping [ -0aAbdFpqrRv ] [ -S <host/ip> ] "
 
255
               "[ -T <host/ip ] [ -s <MAC> ]\n"
148
256
               "              [ -t <MAC> ] [ -c <count> ] [ -i <interface> ] "
149
257
               "<host/ip/MAC | -B>\n");
150
258
        exit(ret);
160
268
        if (searchmac) {
161
269
                libnet_build_icmp_echo(ICMP_ECHO,      /* type */ 
162
270
                                       0,              /* code */ 
163
 
                                       (short)random(),           /* id */ 
 
271
                                       (short)rand(),           /* id */ 
164
272
                                       htons(numsent-1), /* seq */ 
165
273
                                       NULL,           /* pointer to payload */
166
274
                                       0,              /* payload length */ 
198
306
                exit(1);
199
307
        }
200
308
        alarm(1);
 
309
        DEBUG(fprintf(stderr, "Resetting timer\n"));
201
310
#if SOLARIS
202
311
        signal(SIGALRM, alasend);
203
312
#endif
246
355
 
247
356
        if (searchmac) {
248
357
                // ping mac
249
 
                hip = (struct iphdr*)((char*)eth + sizeof(struct libnet_ethernet_hdr));
 
358
                hip = (struct iphdr*)((char*)eth
 
359
                                      + sizeof(struct libnet_ethernet_hdr));
250
360
                hicmp = (struct icmphdr*)((char*)hip + sizeof(struct iphdr));
251
361
                if ((htons(hicmp->type) == ICMP_ECHOREPLY)
252
362
                    && ((!memcmp(eth->h_source, eth_target, ETH_ALEN)
254
364
                    && !memcmp(eth->h_dest, eth_source,
255
365
                               ETH_ALEN)) {
256
366
                        u_char *cp = eth->h_source;
 
367
                        if (addr_must_be_same) {
 
368
                                u_int32_t tmp;
 
369
                                memcpy(&tmp, &hip->saddr, 4);
 
370
                                if (dip != tmp) {
 
371
                                        return;
 
372
                                }
 
373
                        }
257
374
                        numrecvd++;
258
375
                        if (!rawoutput) {
259
376
                                printf("%d bytes from ", h->len);
266
383
                                        printf("%.2x ", *cp++);
267
384
                                }
268
385
                                if (rawoutput & 1) {
269
 
                                        printf("%s",
270
 
                                               libnet_host_lookup(hip->saddr,
271
 
                                                                  0));
 
386
                                        u_int32_t tmp;
 
387
                                        memcpy(&tmp, &hip->saddr, 4);
 
388
                                        printf("%s",libnet_host_lookup(tmp,0));
272
389
                                }
273
390
                                if (!rawoutput) {
274
391
                                        /*
275
 
                                         * ugly code due to non-aligned saddr (bus error on sparc)
 
392
                                         * ugly code due to non-aligned saddr
 
393
                                         * (bus error on sparc)
276
394
                                         */
277
395
                                        u_int32_t tmp;
278
 
                                        memcpy(&tmp, &hip->saddr, sizeof(u_int32_t));
 
396
                                        memcpy(&tmp, &hip->saddr,
 
397
                                               sizeof(u_int32_t));
279
398
                                        printf("%s",libnet_host_lookup(tmp,0));
280
399
                                        printf(" (");
281
400
                                        for (c = 0; c < ETH_ALEN-1; c++) {
282
401
                                                printf("%.2x:", *cp++);
283
402
                                        }
284
 
                                        printf("%.2x): icmp_seq=%d time=%s", *cp,
 
403
                                        printf("%.2x): icmp_seq=%d time=%s",
 
404
                                               *cp,
285
405
                                               hicmp->un.echo.sequence,
286
 
                                               tvtoda(&lastpacketsent, &recvtime));
 
406
                                               tvtoda(&lastpacketsent,
 
407
                                                      &recvtime));
287
408
                                }
288
409
                                if (beep) {
289
410
                                        printf("\a");
293
414
                }
294
415
        } else {
295
416
                /* ping ip */
296
 
                harp = (struct arphdr*)((char*)eth + sizeof(struct libnet_ethernet_hdr));
 
417
                harp = (struct arphdr*)((char*)eth
 
418
                                        + sizeof(struct libnet_ethernet_hdr));
297
419
                if ((htons(harp->ar_op) == ARPOP_REPLY)
298
420
                    && (htons(harp->ar_pro) == ETH_P_IP)
299
421
                    && (htons(harp->ar_hrd) == ARPHRD_ETHER)) {
300
422
                        u_int32_t ip;
301
423
                        memcpy(&ip, (char*)harp + harp->ar_hln
302
424
                               + sizeof(struct arphdr), 4);
 
425
                        if (addr_must_be_same
 
426
                            && (memcmp((u_char*)harp+sizeof(struct arphdr),
 
427
                                       eth_target, ETH_ALEN))) {
 
428
                                return;
 
429
                        }
 
430
 
303
431
                        if (dip == ip) {
304
432
                                cp = (u_char*)harp + sizeof(struct arphdr);
305
433
                                if (!rawoutput && !finddup) {
306
434
                                        printf("%d bytes from ", h->len);
307
435
                                }
 
436
 
308
437
                                if (!quiet) {
309
438
                                        if (rawoutput & 1) {
310
439
                                                for (c = 0; c < harp->ar_hln-1;
327
456
                                        }
328
457
                                        if (!rawoutput) {
329
458
                                                printf(" (%s): index=%d time=%s",
330
 
                                                       libnet_host_lookup(ip, 0),
331
 
                                                       numrecvd, tvtoda(&lastpacketsent, &recvtime));
 
459
                                                       libnet_host_lookup(ip,0),
 
460
                                                       numrecvd,
 
461
                                                       tvtoda(&lastpacketsent,
 
462
                                                              &recvtime));
332
463
                                        }
333
464
                                        if (beep) {
334
465
                                                printf("\a");
348
479
                fprintf(stderr, "pcap_loop(): error\n");
349
480
                exit(1);
350
481
        }
 
482
        // does not return
351
483
}
352
484
 
353
485
int main(int argc, char **argv)
358
490
        struct bpf_program bp;
359
491
        char must_be_pingip = 0;
360
492
        char have_eth_source = 0;
 
493
        unsigned int n[6];
 
494
        int dont_use_arping_lookupdev=0;
361
495
        
362
496
        DEBUG(printf("main()\n"));
363
497
 
366
500
 
367
501
        memcpy(eth_target, eth_xmas, ETH_ALEN);
368
502
 
369
 
        while ((c = getopt(argc, argv, "0bdS:T:Bvhi:rRc:qs:t:pa")) != EOF) {
 
503
        while ((c = getopt(argc, argv, "aAbBc:dF0S:T:hi:rRqs:t:pv")) != EOF) {
370
504
                switch (c) {
 
505
                case 'A':
 
506
                        addr_must_be_same = 1;
 
507
                        break;
371
508
                case 'a':
372
509
                        beep = 1;
373
510
                        break;
 
511
                case 'c':
 
512
                        maxcount = atoi(optarg);
 
513
                        break;
 
514
                case 'd':
 
515
                        finddup = 1;
 
516
                        break;  
 
517
                case 'F':
 
518
#if !defined(FINDIF)
 
519
                        fprintf(stderr, "arping: find-interface support not "
 
520
                                "compiled in\n");
 
521
#endif
 
522
                        dont_use_arping_lookupdev=1;
 
523
                        break;
374
524
                case 'v':
375
525
                        verbose++;
376
526
                        break;
395
545
                case 'q':
396
546
                        quiet = rawoutput = 1;
397
547
                        break;
398
 
                case 'c':
399
 
                        maxcount = atoi(optarg);
400
 
                        break;
401
 
                case 'd':
402
 
                        finddup = 1;
403
 
                        break;  
404
548
                case 'S':
405
 
                        if ((myip = libnet_name_resolve(optarg,
406
 
                                                        LIBNET_RESOLVE))
407
 
                            == -1) {
 
549
                        if (-1==(myip = libnet_name_resolve(optarg,
 
550
                                                            LIBNET_RESOLVE))){
408
551
                                fprintf(stderr,"arping: Can't to resolve %s\n",
409
552
                                        optarg);
410
553
                                exit(1);
414
557
                        }
415
558
                        break;
416
559
                case 'T': // destination IP in mac ping (default: 0xffffffff)
417
 
                        dip = libnet_name_resolve(optarg,
418
 
                                                  LIBNET_RESOLVE);
 
560
                        if (-1 == (dip = libnet_name_resolve(optarg,
 
561
                                                             LIBNET_RESOLVE))){
 
562
                                fprintf(stderr, "arping: can't resolve: %s\n",
 
563
                                        optarg);
 
564
                                exit(1);
 
565
                        }
419
566
                        searchmac = 1;
420
567
                        break;
421
568
                case 'b':
428
575
                        nullip = 1;
429
576
                        break;
430
577
                case 's': // spoofed source MAC
431
 
                        {
432
 
                           unsigned int n[6];
433
 
                           
434
 
                           if (sscanf(optarg, "%x:%x:%x:%x:%x:%x",
435
 
                                      &n[0],
436
 
                                      &n[1],
437
 
                                      &n[2],
438
 
                                      &n[3],
439
 
                                      &n[4],
440
 
                                      &n[5]
441
 
                                   ) != 6) {
442
 
                                   fprintf(stderr, "Illegal MAC addr %s\n",
443
 
                                           optarg);
444
 
                                   exit(1);
445
 
                           }
446
 
                           for (c = 0; c < 6; c++) {
447
 
                                   eth_source[c] = n[c] & 0xff;
448
 
                           }
449
 
                           have_eth_source = 1;
450
 
                        }
 
578
                        if (sscanf(optarg, "%x:%x:%x:%x:%x:%x",
 
579
                                   &n[0],
 
580
                                   &n[1],
 
581
                                   &n[2],
 
582
                                   &n[3],
 
583
                                   &n[4],
 
584
                                   &n[5]
 
585
                                    ) == 6) {
 
586
                                ;
 
587
                        } else if(sscanf(optarg, "%2x%x.%2x%x.%2x%x",
 
588
                                          &n[0],
 
589
                                          &n[1],
 
590
                                          &n[2],
 
591
                                          &n[3],
 
592
                                          &n[4],
 
593
                                          &n[5]
 
594
                                           ) == 6) {
 
595
                                   ;
 
596
                        } else {
 
597
                                fprintf(stderr, "arping: Illegal MAC addr "
 
598
                                        "%s\n", optarg);
 
599
                                exit(1);
 
600
                        }
 
601
                        for (c = 0; c < 6; c++) {
 
602
                                eth_source[c] = n[c] & 0xff;
 
603
                        }
 
604
                        have_eth_source = 1;
451
605
                        break;
452
606
                case 't':
453
607
                        must_be_pingip = 1;
454
 
                        {
455
 
                           unsigned int n[6];
456
 
                           
457
 
                           if (sscanf(optarg, "%x:%x:%x:%x:%x:%x",
458
 
                                      &n[0],
459
 
                                      &n[1],
460
 
                                      &n[2],
461
 
                                      &n[3],
462
 
                                      &n[4],
463
 
                                      &n[5]
464
 
                                   ) != 6) {
465
 
                                   fprintf(stderr, "Illegal MAC addr %s\n",
466
 
                                           optarg);
467
 
                                   exit(1);
468
 
                           }
469
 
                           for (c = 0; c < 6; c++) {
470
 
                                   eth_target[c] = n[c] & 0xff;
471
 
                           }
 
608
                        if (sscanf(optarg, "%x:%x:%x:%x:%x:%x",
 
609
                                   &n[0],
 
610
                                   &n[1],
 
611
                                   &n[2],
 
612
                                   &n[3],
 
613
                                   &n[4],
 
614
                                   &n[5]
 
615
                                    ) == 6) {
 
616
                                ;
 
617
                        } else if(sscanf(optarg, "%2x%x.%2x%x.%2x%x",
 
618
                                         &n[0],
 
619
                                         &n[1],
 
620
                                         &n[2],
 
621
                                         &n[3],
 
622
                                         &n[4],
 
623
                                         &n[5]
 
624
                                          ) == 6) {
 
625
                                ;    
 
626
                        } else {
 
627
                                fprintf(stderr,"arping: Illegal MAC addr %s\n",
 
628
                                        optarg);
 
629
                                exit(1);
 
630
                        }
 
631
                        
 
632
                        for (c = 0; c < 6; c++) {
 
633
                                eth_target[c] = n[c] & 0xff;
472
634
                        }
473
635
                        break;
474
636
                case 'p':
480
642
        }
481
643
        if (!searchmac && !dip && (optind + 1 != argc)) {
482
644
                usage(1);
483
 
                exit(1);
 
645
        } else if (searchmac && (optind + 1 != argc)) {
 
646
                usage(1);
484
647
        }
485
648
        if (getuid() && geteuid()) {
486
649
                fprintf(stderr, "arping: must run as root\n");
492
655
                exit(1);
493
656
        }
494
657
 
495
 
        if (searchmac || (!dip && strchr(argv[optind], ':'))) {
496
 
                unsigned int n[6];
497
 
                if (!dip) {
498
 
                        dip = ip_xmas;
499
 
                }
500
 
 
501
 
                if (must_be_pingip) {
502
 
                        fprintf(stderr, "Specified switch can't be used in "
503
 
                                "MAC-ping mode\n");
504
 
                        exit(1);
505
 
                }
506
 
 
507
 
                if (sscanf(argv[optind], "%x:%x:%x:%x:%x:%x", 
508
 
                           &n[0],
509
 
                           &n[1],
510
 
                           &n[2],
511
 
                           &n[3],
512
 
                           &n[4],
513
 
                           &n[5]
514
 
                           ) != 6) {
515
 
                        fprintf(stderr, "Illegal mac addr %s\n", argv[optind]);
516
 
                        return 1;
517
 
                }
518
 
                for (c = 0; c < 6; c++) {
519
 
                        eth_target[c] = n[c] & 0xff;
520
 
                }
 
658
        if (sscanf(argv[optind], "%x:%x:%x:%x:%x:%x", 
 
659
                   &n[0],
 
660
                   &n[1],
 
661
                   &n[2],
 
662
                   &n[3],
 
663
                   &n[4],
 
664
                   &n[5]
 
665
                   ) == 6) {
 
666
                searchmac = 1;
 
667
        } else if(sscanf(argv[optind], "%2x%x.%2x%x.%2x%x",
 
668
                   &n[0],
 
669
                   &n[1],
 
670
                   &n[2],
 
671
                   &n[3],
 
672
                   &n[4],
 
673
                   &n[5]
 
674
                   ) == 6) {
521
675
                searchmac = 1;
522
676
        } else if (!dip) {
523
 
                
524
 
                if (-1 == (dip = libnet_name_resolve((u_char*)argv[optind],
525
 
                                                     LIBNET_RESOLVE))) {
 
677
                if (-1 == (dip=libnet_name_resolve((u_char*)argv[optind],
 
678
                                                   LIBNET_RESOLVE))) {
526
679
                        fprintf(stderr, "arping: Can't resolve %s\n",
527
680
                                argv[optind]);
528
681
                        exit(1);
529
682
                }
 
683
        } else if (must_be_pingip) {
 
684
                fprintf(stderr, "arping: Illegal IP %s\n", argv[optind]);
 
685
                exit(1);
 
686
        } else {
 
687
                fprintf(stderr, "arping: Illegal mac %s\n", argv[optind]);
 
688
                exit(1);
 
689
        }
 
690
        if (searchmac && !dip) {
 
691
                dip = ip_xmas;
 
692
        }
 
693
 
 
694
        if (searchmac && must_be_pingip) {
 
695
                fprintf(stderr, "arping: Specified switch can't be used in "
 
696
                        "MAC-ping mode\n");
 
697
                exit(1);
 
698
        }
 
699
 
 
700
        if (searchmac) {
 
701
                for (c = 0; c < 6; c++) {
 
702
                        eth_target[c] = n[c] & 0xff;
 
703
                }
530
704
        }
531
705
        if (finddup && maxcount == -1) {
532
706
                maxcount = 3;
535
709
         * libnet init
536
710
         */
537
711
        if (!ifname) {
538
 
                if (!(ifname = pcap_lookupdev(ebuf))) {
539
 
                        fprintf(stderr, "pcap_lookupdev(): %s\n", ebuf);
 
712
                if (dont_use_arping_lookupdev) {
 
713
                        ifname = arping_lookupdev_default(myip,dip,ebuf);
 
714
                } else {
 
715
                        ifname = arping_lookupdev(myip,dip,ebuf);
 
716
                }
 
717
                if (!ifname) {
 
718
                        fprintf(stderr,"arping_lookupdev(): %s\n", ebuf);
540
719
                        exit(1);
541
720
                }
 
721
                // FIXME: check for other probably-not interfaces
 
722
                if (!strcmp(ifname, "ipsec")
 
723
                    || !strcmp(ifname, "lo")) {
 
724
                        fprintf(stderr, "arping: Um.. %s looks like the wrong "
 
725
                                "interface to use. Is it? "
 
726
                                "(-i switch)\n", ifname);
 
727
                        fprintf(stderr, "arping: using it anyway this time\n");
 
728
                }
542
729
        }
543
730
 
544
731
        if (!(linkint = libnet_open_link_interface(ifname, ebuf))) {
663
850
                        fprintf(stderr, "libnet_build_arp(): error\n");
664
851
                        exit(1);
665
852
                }
666
 
                
667
 
        }
 
853
        }
668
854
        /*
669
855
         * pcap init
670
856
         */