add --args (#11)

* add --args

allows gathering of arguments to be sent to the nro and avoid attempted parsing by nxlink. This allows arguments starting with - and -- to be passed to the nro without getopt complaining.
This commit is contained in:
Dave Murphy 2018-06-23 20:12:18 +01:00 committed by yellows8
parent 0e2d4806b1
commit 1aceda46f4

View File

@ -132,7 +132,7 @@ static struct in_addr findSwitch(int retries) {
printf("pinging switch\n");
struct sockaddr_in s, remote, rs;
struct sockaddr_in s, remote, rs;
char recvbuf[256];
char mess[] = "nxboot";
@ -433,11 +433,58 @@ void showHelp() {
puts("--address, -a Hostname or IPv4 address of Switch");
puts("--retries, -r number of times to ping before giving up");
puts("--path , -p set upload path for file");
puts("--args args to send to nro");
puts("--server , -s start server after completed upload");
puts("\n");
}
//---------------------------------------------------------------------------------
int add_extra_args(int len, char *buf, char *extra_args) {
//---------------------------------------------------------------------------------
if (NULL==extra_args) return len;
int extra_len = strlen(extra_args);
char *dst = &buf[len];
char *src = extra_args;
do {
int c;
do {
c = *src++;
extra_len--;
} while(c ==' ' && extra_len >= 0);
if (c == '\"' || c == '\'') {
int quote = c;
do {
c = *src++;
if (c != quote) *dst++ = c;
extra_len--;
} while(c != quote && extra_len >= 0);
*dst++ = '\0';
continue;
}
do {
*dst++ = c;
extra_len--;
c = *src++;
} while(c != ' ' && extra_len >= 0);
*dst++ = '\0';
} while(extra_len >= 0);
return dst - buf;
}
#define NRO_ARGS 1000
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------
@ -445,6 +492,7 @@ int main(int argc, char **argv) {
char *basepath = NULL;
char *finalpath = NULL;
char *endarg = NULL;
char *extra_args = NULL;
int retries = 10;
static int server = 0;
@ -458,6 +506,7 @@ int main(int argc, char **argv) {
{"address", required_argument, 0, 'a'},
{"retries", required_argument, 0, 'r'},
{"path", required_argument, 0, 'p'},
{"args", required_argument, 0, NRO_ARGS},
{"help", no_argument, 0, 'h'},
{"server", no_argument, &server, 1 },
{0, 0, 0, 0}
@ -495,6 +544,9 @@ int main(int argc, char **argv) {
case 'h':
showHelp();
break;
case NRO_ARGS:
extra_args=optarg;
break;
}
}
@ -552,6 +604,8 @@ int main(int argc, char **argv) {
cmdlen+= len + 1;
}
cmdlen = add_extra_args(cmdlen, &cmdbuf[4], extra_args);
cmdbuf[0] = cmdlen & 0xff;
cmdbuf[1] = (cmdlen>>8) & 0xff;
cmdbuf[2] = (cmdlen>>16) & 0xff;