1010#include <uuid/uuid.h>
1111
1212#include "cli.h"
13+ #include "log.h"
1314
1415#ifndef VERSION
1516#define VERSION "UNKNOWN"
7778struct cli_options * cli_options_parse (int argc , char * argv []) {
7879 struct cli_options * res = calloc (1 , sizeof (* res ));
7980 if (res == NULL ) {
80- perror ("calloc" );
81+ ERRORN ("calloc" );
8182 exit (EXIT_FAILURE );
8283 }
8384
@@ -109,7 +110,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
109110 } else if (strcmp (optarg , "bridged" ) == 0 ) {
110111 res -> vmnet_mode = VMNET_BRIDGED_MODE ;
111112 } else {
112- fprintf ( stderr , "Unknown vmnet mode \"%s\"\n " , optarg );
113+ ERRORF ( "Unknown vmnet mode \"%s\"" , optarg );
113114 goto error ;
114115 }
115116 break ;
@@ -127,7 +128,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
127128 break ;
128129 case CLI_OPT_VMNET_INTERFACE_ID :
129130 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 );
131132 goto error ;
132133 }
133134 break ;
@@ -166,7 +167,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
166167 * is specified) */
167168 struct in_addr sin ;
168169 if (!inet_aton (res -> vmnet_gateway , & sin )) {
169- perror ("inet_aton(res->vmnet_gateway)" );
170+ ERRORN ("inet_aton(res->vmnet_gateway)" );
170171 goto error ;
171172 }
172173 uint32_t h = ntohl (sin .s_addr );
@@ -175,7 +176,7 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
175176 sin .s_addr = htonl (h );
176177 const char * end_static = inet_ntoa (sin ); /* static storage, do not free */
177178 if (end_static == NULL ) {
178- perror ("inet_ntoa" );
179+ ERRORN ("inet_ntoa" );
179180 goto error ;
180181 }
181182 res -> vmnet_dhcp_end = strdup (end_static );
@@ -189,36 +190,31 @@ struct cli_options *cli_options_parse(int argc, char *argv[]) {
189190
190191 /* validate */
191192 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" );
195194 goto error ;
196195 }
197196 if (res -> vmnet_gateway == NULL ) {
198197 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" );
202200 }
203201 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" );
205203 goto error ;
206204 }
207205 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" );
209207 goto error ;
210208 }
211209 } else {
212210 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" );
215212 goto error ;
216213 }
217214 struct in_addr dummy ;
218215 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 );
222218 goto error ;
223219 }
224220 }
0 commit comments