summaryrefslogtreecommitdiff
path: root/src/arping_test.c
blob: daaa579ec3b7e734ec4dc15319ff5c4d421e24a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/* arping/src/arping_test.c
 *
 *  Copyright (C) 2015-2019 Thomas Habets <thomas@habets.se>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with this program; if not, write to the Free Software Foundation, Inc.,
 *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
#include"config.h"
#define _GNU_SOURCE
#include<assert.h>
#include<errno.h>
#include<fcntl.h>
#include<inttypes.h>
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>

#include<check.h>
#include<libnet.h>
#include<pcap.h>

#include"arping.h"

#ifndef ETH_ALEN
#define ETH_ALEN 6
#endif

extern libnet_t* libnet;
extern int mock_libnet_lo_ok;
extern int mock_libnet_null_ok;

int get_mac_addr(const char *in, char *out);
void strip_newline(char* s);


/**
 *
 */
static void
xclose(int* fd)
{
        if (0 > close(*fd)) {
                fprintf(stderr, "close(%d): %s", *fd, strerror(errno));
                *fd = -1;
        }
}

struct captured_output {
        int saved_fd;  // Old fd, will be dup2()ed back in place when done.
        int fno;       // Overridden fd (e.g. stdout or stderr).
        int reader_fd; // Reader end of the pipe.
        char* buffer;  // Output buffer.
        size_t bufsize; // Buffer size.
        pthread_t thread;  // Reader thread.
};

/**
 * Helper function for stdout/stderr catching.
 *
 * This is the main() for the thread that reads from the fake stdout pipe
 * and writes into the buffer.
 *
 */
static void*
read_main(void* p)
{
        struct captured_output* out = p;
        char *cur = out->buffer;

        for (;;) {
                ssize_t n;
                n = out->bufsize - (cur - out->buffer);
                assert(n > 0);
                n = read(out->reader_fd, cur, n);
                if (n > 0) {
                        cur += n;
                }
                if (n == 0) {
                        return NULL;
                }
        }
}

/**
 * Helper function to capture stdout/stderr output.
 *
 * Args:
 *   fd:  The fd to capture.
 * Returns:
 *   A structure to be used as a handle. Only thing caller should do with
 *   this structure is call stop_capture(), read its .buffer member, and
 *   uncapture().
 */
static struct captured_output*
capture(int fd)
{
        struct captured_output* out;

        out = calloc(1, sizeof(struct captured_output));
        fail_if(out == NULL);

        out->fno = fd;
        out->saved_fd = dup(fd);
        out->bufsize = 1024*100;
        out->buffer = calloc(1, out->bufsize);

        fail_if(0 > out->saved_fd);
        fail_if(out->buffer == NULL);

        // set up pipe
        int fds[2];
        fail_if(0 > pipe(fds));
        fail_if(0 > dup2(fds[1], fd));
        out->reader_fd = fds[0];
        xclose(&fds[1]);

        fail_if(pthread_create(&out->thread, NULL, read_main, (void*)out));
        return out;
}

/**
 * Helper function to capture stdout/stderr output.
 *
 * Stop capture, so that .buffer becomes readable.
 */
static void
stop_capture(struct captured_output* out)
{
        fail_if(0 > dup2(out->saved_fd, out->fno));
        xclose(&out->saved_fd);
        fail_if(pthread_join(out->thread, NULL));
        xclose(&out->reader_fd);
}

/**
 * Helper function to capture stdout/stderr output.
 *
 * Deallocate buffer. stop_capture() must be called before uncapture().
 */
static void
uncapture(struct captured_output* out)
{
        free(out->buffer);
        out->buffer = NULL;
        free(out);
}

static uint8_t*
mkpacket(struct pcap_pkthdr* pkthdr)
{
        uint8_t* packet = calloc(1, 1500);
        fail_if(packet == NULL);

        struct libnet_802_3_hdr* heth;
        struct libnet_arp_hdr* harp;

        // Set up ethernet header
        heth = (void*)packet;
        memcpy(heth->_802_3_dhost, "\x11\x22\x33\x44\x55\x66", 6);
        memcpy(heth->_802_3_shost, "\x77\x88\x99\xaa\xbb\xcc", 6);
        heth->_802_3_len = 0;  // FIXME: is this correct?

        // Set up ARP header.
        harp = (void*)((char*)heth + LIBNET_ETH_H);
        harp->ar_hln = 6;
        harp->ar_pln = 4;
        harp->ar_hrd = htons(ARPHRD_ETHER);
        harp->ar_op = htons(ARPOP_REPLY);
        harp->ar_pro = htons(ETHERTYPE_IP);

        memcpy((char*)harp + LIBNET_ARP_H, heth->_802_3_shost, 6);
        memcpy((char*)harp + LIBNET_ARP_H + harp->ar_hln, &dstip, 4);

        memcpy((char*)harp + LIBNET_ARP_H
               + harp->ar_hln
               + harp->ar_pln, heth->_802_3_dhost, 6);
        memcpy((char*)harp + LIBNET_ARP_H
               + harp->ar_hln
               + harp->ar_pln
               + harp->ar_hln, &srcip, 4);

        pkthdr->ts.tv_sec = time(NULL);
        pkthdr->ts.tv_usec = 0;
        pkthdr->len = 60;
        pkthdr->caplen = 60;

        return packet;
}

static void
dump_packet(uint8_t* packet, uint32_t len)
{
        uint32_t c;
        for (c = 0; c < len; c++) {
                fprintf(stderr, "0x%.2x, ", (int)packet[c]);
                if (!((c+1) % 10)) {
                        fprintf(stderr, "\n");
                }
        }
        fprintf(stderr, "\n");
}

START_TEST(test_mkpacket)
{
        uint8_t correct_packet[] = {
                0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa,
                0xbb, 0xcc, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x06, 0x04,
                0x00, 0x02, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0x12, 0x34,
                0x56, 0x78, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x87, 0x65,
                0x43, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        };
        struct pcap_pkthdr pkthdr;
        dstip = htonl(0x12345678);
        srcip = htonl(0x87654321);

        uint8_t* packet = mkpacket(&pkthdr);
        fail_if(packet == NULL);
        fail_unless(pkthdr.caplen == 60);
        if (memcmp(packet, correct_packet, pkthdr.caplen)) {
                dump_packet(packet, pkthdr.caplen);
        }
        fail_unless(!memcmp(packet, correct_packet, pkthdr.caplen));
} END_TEST


// Received uninteresting packet, should not record anything.
START_TEST(pingip_uninteresting_packet)
{
        struct pcap_pkthdr pkthdr;
        uint8_t* packet;
        struct libnet_arp_hdr* harp;

        unsigned int prev_numrecvd = numrecvd;
        struct captured_output* sout;

        // Completely broken packet.
        packet = calloc(1, 1500);
        sout = capture(STDOUT_FILENO);
        pingip_recv(NULL, &pkthdr, (char*)packet);
        stop_capture(sout);
        fail_unless(strlen(sout->buffer) == 0);
        fail_unless(prev_numrecvd == numrecvd);
        uncapture(sout);
        free(packet);

        // Not ETHERTYPE_IP.
        packet = mkpacket(&pkthdr);
        harp = (void*)((char*)packet + LIBNET_ETH_H);
        harp->ar_pro = 0;
        sout = capture(STDOUT_FILENO);
        pingip_recv(NULL, &pkthdr, (char*)packet);
        stop_capture(sout);
        fail_unless(prev_numrecvd == numrecvd);
        fail_unless(strlen(sout->buffer) == 0);
        uncapture(sout);
        free(packet);

        // Not ARPHRD_ETHER
        packet = mkpacket(&pkthdr);
        harp = (void*)((char*)packet + LIBNET_ETH_H);
        harp->ar_hrd = 0;
        sout = capture(STDOUT_FILENO);
        pingip_recv(NULL, &pkthdr, (char*)packet);
        stop_capture(sout);
        fail_unless(prev_numrecvd == numrecvd);
        fail_unless(strlen(sout->buffer) == 0);
        uncapture(sout);
        free(packet);

        // Wrong dstip
        if (0) {
                uint32_t wrongip = 123;
                packet = mkpacket(&pkthdr);
                harp = (void*)((char*)packet + LIBNET_ETH_H);
                memcpy((char*)harp + harp->ar_hln + LIBNET_ARP_H, &wrongip, 4);
                sout = capture(STDOUT_FILENO);
                pingip_recv(NULL, &pkthdr, (char*)packet);
                stop_capture(sout);
                fail_unless(prev_numrecvd == numrecvd);
                fail_unless(strlen(sout->buffer) == 0);
                uncapture(sout);
                free(packet);
        }

        // Short packet.
        packet = mkpacket(&pkthdr);
        pkthdr.caplen = pkthdr.len = 41;
        sout = capture(STDOUT_FILENO);
        pingip_recv(NULL, &pkthdr, (char*)packet);
        stop_capture(sout);
        fail_unless(prev_numrecvd == numrecvd);
        fail_unless(strlen(sout->buffer) == 0);
        uncapture(sout);
        free(packet);

        // Short captured packet.
        packet = mkpacket(&pkthdr);
        pkthdr.caplen = 41;
        sout = capture(STDOUT_FILENO);
        pingip_recv(NULL, &pkthdr, (char*)packet);
        stop_capture(sout);
        fail_unless(prev_numrecvd == numrecvd);
        fail_unless(strlen(sout->buffer) == 0);
        uncapture(sout);
        free(packet);

        // Wrong length of hardware address.
        {
                uint8_t packet[] = {
                        0x11, 0x22, 0x33, 0x44, 0x55, 0x66, // dst
                        0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, // src
                        0x00, 0x00, // type
                        0x00, 0x01, // hardware
                        0x08, 0x00, // protocol
                        0x04, 0x04, // lengths (for this test length is wrong)
                        0x00, 0x02, // operator

                        0x77, 0x88, 0x99, 0xaa, // sender (wrong length for test)
                        0x12, 0x34, 0x56, 0x78, // sender protocol address

                        0x11, 0x22, 0x33, 0x44, // receiver (wrong length for test)
                        0x87, 0x65, 0x43, 0x21, // receiver protocol address

                        0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00,
                        0x6f, 0xa8, 0x58, 0x63,
        };
                pkthdr.len = 60;
                pkthdr.caplen = 60;
                sout = capture(STDOUT_FILENO);
                pingip_recv(NULL, &pkthdr, (char*)packet);
                stop_capture(sout);
                fail_unless(strlen(sout->buffer) == 0, sout->buffer);
                fail_unless(prev_numrecvd == numrecvd);
                uncapture(sout);
        }

        // Wrong length of protocol address.
        packet = mkpacket(&pkthdr);
        ((struct libnet_arp_hdr*)((char*)packet + LIBNET_ETH_H))->ar_pln = 6;
        sout = capture(STDOUT_FILENO);
        pingip_recv(NULL, &pkthdr, (char*)packet);
        stop_capture(sout);
        fail_unless(prev_numrecvd == numrecvd);
        fail_unless(strlen(sout->buffer) == 0);
        uncapture(sout);
        free(packet);
} END_TEST

// Received reply that actually matches. Things should happen.
START_TEST(pingip_interesting_packet)
{
        struct pcap_pkthdr pkthdr;
        extern uint8_t srcmac[ETH_ALEN];
        memcpy(srcmac, "\x11\x22\x33\x44\x55\x66", ETH_ALEN);
        uint8_t packet[] = {
                0x11, 0x22, 0x33, 0x44, 0x55, 0x66, // dst
                0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, // src
                0x00, 0x00, // type
                0x00, 0x01, // hardware
                0x08, 0x00, // protocol
                0x06, 0x04, // lengths
                0x00, 0x02, // operator

                0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, // sender
                0x12, 0x34, 0x56, 0x78, // sender protocol address

                0x11, 0x22, 0x33, 0x44, 0x55, 0x66, // receiver
                0x87, 0x65, 0x43, 0x21, // receiver protocol address

                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x6f, 0xa8, 0x58, 0x63,
        };
        numrecvd = 0;
        unsigned int prev_numrecvd = numrecvd;

        dstip = htonl(0x12345678);

        pkthdr.ts.tv_sec = time(NULL);
        pkthdr.ts.tv_usec = 0;
        pkthdr.len = 60;
        pkthdr.caplen = 60;

        struct captured_output *sout;

        // First ping.
        const char* correct0 =
                        "60 bytes from 77:88:99:aa:bb:cc (18.52.86.120): "
                        "index=0 time=";
        sout = capture(STDOUT_FILENO);
        pingip_recv(NULL, &pkthdr, (char*)packet);
        stop_capture(sout);

        char* emsg = NULL;
        fail_unless(0 < asprintf(&emsg, "Captured: <%s> (%zd), want   <%s> %zd\n",
                         sout->buffer, strlen(sout->buffer),
                                 correct0, strlen(correct0)));
        fail_unless(!strncmp(sout->buffer, correct0, strlen(correct0)), emsg);
        uncapture(sout);
        free(emsg);

        // Check numrecvd incremented.
        ck_assert_int_eq(numrecvd, prev_numrecvd + 1);

        pingip_recv(NULL, &pkthdr, (char*)packet);
        // Check that numrecvd is incremented second time.
        ck_assert_int_eq(numrecvd,prev_numrecvd + 2);
} END_TEST

START_TEST(strip_newline_test)
{
        const char *tests[][2] = {
                {"", ""},
                {"\n", ""},
                {"\n\n\n", ""},
                {"foo", "foo"},
                {"foo\n", "foo"},
                {"foo\n\n\n", "foo"},
                {NULL, NULL},
        };
        int c;
        for (c = 0; tests[c][0]; c++){
                char buf[128];
                strcpy(buf, tests[c][0]);
                strip_newline(buf);
                fail_unless(!strcmp(buf, tests[c][1]));
        }
} END_TEST

START_TEST(get_mac_addr_success)
{
        const char *tests[][2] = {
                // Null.
                {"0000.0000.0000", "\x00\x00\x00\x00\x00\x00"},
                {"00:00:00:00:00:00", "\x00\x00\x00\x00\x00\x00"},
                {"00-00-00-00-00-00", "\x00\x00\x00\x00\x00\x00"},

                // Broadcast.
                {"FFFF.FFFF.FFFF", "\xFF\xFF\xFF\xFF\xFF\xFF"},
                {"FF:FF:FF:FF:FF:FF", "\xFF\xFF\xFF\xFF\xFF\xFF"},
                {"FF-FF-FF-FF-FF-FF", "\xFF\xFF\xFF\xFF\xFF\xFF"},

                // Normal looking.
                {"1122.3344.5566", "\x11\x22\x33\x44\x55\x66"},
                {"11:22:33:44:55:66", "\x11\x22\x33\x44\x55\x66"},
                {"11-22-33-44-55-66", "\x11\x22\x33\x44\x55\x66"},

                // Has some zeroes.
                {"1100.0000.5566", "\x11\x00\x00\x00\x55\x66"},
                {"11:00:00:00:55:66", "\x11\x00\x00\x00\x55\x66"},
                {"11-00-00-00-55-66", "\x11\x00\x00\x00\x55\x66"},
                {NULL, NULL},
        };
        int c;
        for (c = 0; tests[c][0]; c++){
                char buf[6];
                fail_unless(get_mac_addr(tests[c][0], buf));
                fail_unless(!memcmp(buf, tests[c][1], 6));
        }
} END_TEST

START_TEST(get_mac_addr_fail)
{
        const char *tests[] = {
                "",
                "blaha",
                "11:22:33:44:55",
                "11:22:33:44:55:zz",
                NULL,
        };
        int c;
        for (c = 0; tests[c]; c++){
                char buf[6];
                fail_if(get_mac_addr(tests[c], buf));
        }
} END_TEST

START_TEST(badarg_maxcount_neg)
{
        char* args[] = {
                "arping",
                "-c", "-1",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(badarg_maxcount_nan)
{
        char* args[] = {
                "arping",
                "-c", "number",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(badarg_maxcount_range)
{
        char* args[] = {
                "arping",
                "-c", "100000000000000000000000000000",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(arg_maxcount_good)
{
        char* args[] = {
                "arping",
                "-c", "1",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(arg_maxcount_hex)
{
        char* args[] = {
                "arping",
                "-c", "0xa",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(badarg_packetwait_neg)
{
        char* args[] = {
                "arping",
                "-W", "-1",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(badarg_packetwait_nan)
{
        char* args[] = {
                "arping",
                "-W", "huteosu",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(badarg_packetwait_range)
{
        char* args[] = {
                "arping",
                "-W", "10000000000000000000000000000000000000000",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(arg_packetwait_good)
{
        char* args[] = {
                "arping",
                "-W", "1.2",
                "-h", // To exit cleanly.
                "dummy",
                NULL
        };
        arping_main(sizeof(args)/sizeof(char*)-1, args);
}

START_TEST(libnet_init_bad_nolo)
{
        // It'll only try lo if named interface fails.
        // So by accepting lo, we make sure it doesn't try lo.
        mock_libnet_lo_ok = 1;
        do_libnet_init("bad", 0);
} END_TEST

START_TEST(libnet_init_null_nolo_nonull)
{
        mock_libnet_lo_ok = 0;
        mock_libnet_null_ok = 0;
        do_libnet_init(NULL, 0);
} END_TEST

START_TEST(libnet_init_good)
{
        mock_libnet_lo_ok = 0; // Don't even try falling back to lo.
        do_libnet_init("good", 0);
        fail_if(libnet == NULL);
} END_TEST

START_TEST(libnet_init_null_nolo)
{
        mock_libnet_lo_ok = 0;
        mock_libnet_null_ok = 1;
        do_libnet_init(NULL, 0);
        fail_if(libnet == NULL);
}
END_TEST

static Suite*
arping_suite(void)
{
        Suite* s = suite_create("Arping");


        TCase *tc_core;

        // libcheck broke test registries, so have to resort to code duplication. :-(
        // https://github.com/libcheck/check/pull/158/files
#define SIGH_LIBCHECK(tn) \
        tc_core = tcase_create(#tn);   \
        tcase_add_test(tc_core, tn); \
        suite_add_tcase(s, tc_core);

        SIGH_LIBCHECK(libnet_init_null_nolo);
        SIGH_LIBCHECK(test_mkpacket);
        SIGH_LIBCHECK(pingip_uninteresting_packet);
        SIGH_LIBCHECK(pingip_interesting_packet);
        SIGH_LIBCHECK(strip_newline_test);
        SIGH_LIBCHECK(get_mac_addr_success);
        SIGH_LIBCHECK(get_mac_addr_fail);
        SIGH_LIBCHECK(libnet_init_good);
        SIGH_LIBCHECK(arg_maxcount_good);
        SIGH_LIBCHECK(arg_maxcount_hex);
        SIGH_LIBCHECK(arg_packetwait_good);

#define SIGH_LIBCHECK_EXIT(tn)          \
        tc_core = tcase_create(#tn);   \
        tcase_add_exit_test(tc_core, tn, 1);      \
        suite_add_tcase(s, tc_core);

        SIGH_LIBCHECK_EXIT(badarg_maxcount_neg);
        SIGH_LIBCHECK_EXIT(badarg_maxcount_nan);
        SIGH_LIBCHECK_EXIT(badarg_maxcount_range);
        SIGH_LIBCHECK_EXIT(badarg_packetwait_neg);
        SIGH_LIBCHECK_EXIT(badarg_packetwait_nan);
        SIGH_LIBCHECK_EXIT(badarg_packetwait_range);
        SIGH_LIBCHECK_EXIT(libnet_init_bad_nolo);
        SIGH_LIBCHECK_EXIT(libnet_init_null_nolo_nonull);

        return s;
}

int
main()
{
        int number_failed;
        Suite *s = arping_suite();
        SRunner *sr = srunner_create (s);
        srunner_run_all (sr, CK_NORMAL);
        number_failed = srunner_ntests_failed (sr);
        srunner_free (sr);
        return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
        return 0;
}
/* ---- Emacs Variables ----
 * Local Variables:
 * c-basic-offset: 8
 * indent-tabs-mode: nil
 * End:
 */