27
27
#define _GNU_SOURCE
28
28
29
29
#include <errno.h>
30
- #include <error.h>
31
30
#include <ifaddrs.h>
32
31
#include <fcntl.h>
33
32
#include <poll.h>
@@ -107,11 +106,12 @@ static struct global {
107
106
108
107
109
108
static inline void exit_errno (const char * message ) {
110
- error (1 , errno , "error: %s" , message );
109
+ fprintf (stderr , "error: %s: %s\n" , message , strerror (errno ));
110
+ exit (1 );
111
111
}
112
112
113
113
static inline void warn_errno (const char * message ) {
114
- error ( 0 , errno , "warning: %s" , message );
114
+ fprintf ( stderr , "warning: %s: %s\n " , message , strerror ( errno ) );
115
115
}
116
116
117
117
@@ -370,7 +370,8 @@ static void handle_rtnl(void) {
370
370
return ;
371
371
372
372
case NLMSG_ERROR :
373
- error (1 , 0 , "error: netlink error" );
373
+ fprintf (stderr , "error: netlink error" );
374
+ exit (1 );
374
375
375
376
default :
376
377
if (handle_rtnl_msg (nh -> nlmsg_type , NLMSG_DATA (nh ))) {
@@ -545,8 +546,10 @@ static void usage(void) {
545
546
}
546
547
547
548
static void add_prefix (const char * prefix ) {
548
- if (G .n_prefixes == MAX_PREFIXES )
549
- error (1 , 0 , "maximum number of prefixes is %i." , MAX_PREFIXES );
549
+ if (G .n_prefixes == MAX_PREFIXES ) {
550
+ fprintf (stderr , "maximum number of prefixes is %i." , MAX_PREFIXES );
551
+ exit (1 );
552
+ }
550
553
551
554
const size_t len = strlen (prefix )+ 1 ;
552
555
char prefix2 [len ];
@@ -570,16 +573,19 @@ static void add_prefix(const char *prefix) {
570
573
return ;
571
574
572
575
error :
573
- error (1 , 0 , "invalid prefix %s (only prefixes of length 64 are supported)." , prefix );
576
+ fprintf (stderr , "invalid prefix %s (only prefixes of length 64 are supported)." , prefix );
577
+ exit (1 );
574
578
}
575
579
576
580
static void parse_cmdline (int argc , char * argv []) {
577
581
int c ;
578
582
while ((c = getopt (argc , argv , "i:p:h" )) != -1 ) {
579
583
switch (c ) {
580
584
case 'i' :
581
- if (G .ifname )
582
- error (1 , 0 , "multiple interfaces are not supported." );
585
+ if (G .ifname ) {
586
+ fprintf (stderr , "multiple interfaces are not supported." );
587
+ exit (1 );
588
+ }
583
589
584
590
G .ifname = optarg ;
585
591
@@ -603,8 +609,10 @@ static void parse_cmdline(int argc, char *argv[]) {
603
609
int main (int argc , char * argv []) {
604
610
parse_cmdline (argc , argv );
605
611
606
- if (!G .ifname || !G .n_prefixes )
607
- error (1 , 0 , "interface and prefix arguments are required." );
612
+ if (!G .ifname || !G .n_prefixes ) {
613
+ fprintf (stderr , "interface and prefix arguments are required." );
614
+ exit (1 );
615
+ }
608
616
609
617
init_random ();
610
618
init_icmp ();
0 commit comments