Stricter command line args validation to dhcp_release6.

This commit is contained in:
Sergey Nechaev
2016-05-14 21:36:15 +01:00
committed by Simon Kelley
parent 88b09aaddc
commit 45cb8dd9be

View File

@@ -350,11 +350,12 @@ int send_release_packet(const char* iface, struct dhcp6_packet* packet){
int main(int argc, char * const argv[]) { int main(int argc, char * const argv[]) {
const char* iface = ""; const char* UNINITIALIZED = "";
const char* ip = ""; const char* iface = UNINITIALIZED;
const char* client_id = ""; const char* ip = UNINITIALIZED;
const char* server_id = ""; const char* client_id = UNINITIALIZED;
const char* iaid = ""; const char* server_id = UNINITIALIZED;
const char* iaid = UNINITIALIZED;
int dry_run = 0; int dry_run = 0;
while (1) { while (1) {
int option_index = 0; int option_index = 0;
@@ -392,7 +393,7 @@ int main(int argc, char * const argv[]) {
break; break;
case 'h': case 'h':
usage(argv[0], stdout); usage(argv[0], stdout);
break; return 0;
case '?': case '?':
usage(argv[0], stderr); usage(argv[0], stderr);
return -1; return -1;
@@ -402,6 +403,34 @@ int main(int argc, char * const argv[]) {
} }
} }
if (iaid == UNINITIALIZED){
fprintf(stderr, "Missing required iaid parameter\n");
usage(argv[0], stderr);
return -1;
}
if (server_id == UNINITIALIZED){
fprintf(stderr, "Missing required server-id parameter\n");
usage(argv[0], stderr);
return -1;
}
if (client_id == UNINITIALIZED){
fprintf(stderr, "Missing required client-id parameter\n");
usage(argv[0], stderr);
return -1;
}
if (ip == UNINITIALIZED){
fprintf(stderr, "Missing required ip parameter\n");
usage(argv[0], stderr);
return -1;
}
if (iface == UNINITIALIZED){
fprintf(stderr, "Missing required iface parameter\n");
usage(argv[0], stderr);
return -1;
}
struct dhcp6_packet packet = create_release_packet(iaid, ip, client_id, server_id); struct dhcp6_packet packet = create_release_packet(iaid, ip, client_id, server_id);
if (dry_run){ if (dry_run){
uint16_t i; uint16_t i;