10
10
#include <uuid/uuid.h>
11
11
12
12
#include "cli.h"
13
+ #include "log.h"
13
14
14
15
#ifndef VERSION
15
16
#define VERSION "UNKNOWN"
77
78
struct cli_options * cli_options_parse (int argc , char * argv []) {
78
79
struct cli_options * res = calloc (1 , sizeof (* res ));
79
80
if (res == NULL ) {
80
- perror ("calloc" );
81
+ ERRORN ("calloc" );
81
82
exit (EXIT_FAILURE );
82
83
}
83
84
@@ -109,7 +110,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
109
110
} else if (strcmp (optarg , "bridged" ) == 0 ) {
110
111
res -> vmnet_mode = VMNET_BRIDGED_MODE ;
111
112
} else {
112
- fprintf ( stderr , "Unknown vmnet mode \"%s\"\n " , optarg );
113
+ ERRORF ( "Unknown vmnet mode \"%s\"" , optarg );
113
114
goto error ;
114
115
}
115
116
break ;
@@ -127,7 +128,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
127
128
break ;
128
129
case CLI_OPT_VMNET_INTERFACE_ID :
129
130
if (uuid_parse (optarg , res -> vmnet_interface_id ) < 0 ) {
130
- fprintf ( stderr , "Failed to parse UUID \"%s\"\n " , optarg );
131
+ ERRORF ( "Failed to parse UUID \"%s\"" , optarg );
131
132
goto error ;
132
133
}
133
134
break ;
@@ -166,7 +167,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
166
167
* is specified) */
167
168
struct in_addr sin ;
168
169
if (!inet_aton (res -> vmnet_gateway , & sin )) {
169
- perror ("inet_aton(res->vmnet_gateway)" );
170
+ ERRORN ("inet_aton(res->vmnet_gateway)" );
170
171
goto error ;
171
172
}
172
173
uint32_t h = ntohl (sin .s_addr );
@@ -175,7 +176,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
175
176
sin .s_addr = htonl (h );
176
177
const char * end_static = inet_ntoa (sin ); /* static storage, do not free */
177
178
if (end_static == NULL ) {
178
- perror ("inet_ntoa" );
179
+ ERRORN ("inet_ntoa" );
179
180
goto error ;
180
181
}
181
182
res -> vmnet_dhcp_end = strdup (end_static );
@@ -189,36 +190,31 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
189
190
190
191
/* validate */
191
192
if (res -> vmnet_mode == VMNET_BRIDGED_MODE && res -> vmnet_interface == NULL ) {
192
- fprintf (
193
- stderr ,
194
- "vmnet mode \"bridged\" require --vmnet-interface to be specified\n" );
193
+ ERROR ("vmnet mode \"bridged\" require --vmnet-interface to be specified" );
195
194
goto error ;
196
195
}
197
196
if (res -> vmnet_gateway == NULL ) {
198
197
if (res -> vmnet_mode != VMNET_BRIDGED_MODE ) {
199
- fprintf (stderr ,
200
- "WARNING: --vmnet-gateway=IP should be explicitly specified to "
201
- "avoid conflicting with other applications\n" );
198
+ WARN ("--vmnet-gateway=IP should be explicitly specified to "
199
+ "avoid conflicting with other applications" );
202
200
}
203
201
if (res -> vmnet_dhcp_end != NULL ) {
204
- fprintf ( stderr , "--vmnet-dhcp-end=IP requires --vmnet-gateway=IP\n " );
202
+ ERROR ( "--vmnet-dhcp-end=IP requires --vmnet-gateway=IP" );
205
203
goto error ;
206
204
}
207
205
if (res -> vmnet_mask != NULL ) {
208
- fprintf ( stderr , "--vmnet-mask=MASK requires --vmnet-gateway=IP\n " );
206
+ ERROR ( "--vmnet-mask=MASK requires --vmnet-gateway=IP" );
209
207
goto error ;
210
208
}
211
209
} else {
212
210
if (res -> vmnet_mode == VMNET_BRIDGED_MODE ) {
213
- fprintf (stderr ,
214
- "vmnet mode \"bridged\" conflicts with --vmnet-gateway\n" );
211
+ ERROR ("vmnet mode \"bridged\" conflicts with --vmnet-gateway" );
215
212
goto error ;
216
213
}
217
214
struct in_addr dummy ;
218
215
if (!inet_aton (res -> vmnet_gateway , & dummy )) {
219
- fprintf (stderr ,
220
- "invalid address \"%s\" was specified for --vmnet-gateway\n" ,
221
- res -> vmnet_gateway );
216
+ ERRORF ("invalid address \"%s\" was specified for --vmnet-gateway" ,
217
+ res -> vmnet_gateway );
222
218
goto error ;
223
219
}
224
220
}
0 commit comments