Skip to content

nxlink: add option to override netloader target port #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/nxlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static unsigned char in[ZLIB_CHUNK];
static unsigned char out[ZLIB_CHUNK];

//---------------------------------------------------------------------------------
static int sendNROFile(in_addr_t nxaddr, char *name, size_t filesize, FILE *fh) {
static int sendNROFile(in_addr_t nxaddr, char *name, size_t filesize, FILE *fh, int port) {
//---------------------------------------------------------------------------------

int retval = 0;
Expand All @@ -295,7 +295,7 @@ static int sendNROFile(in_addr_t nxaddr, char *name, size_t filesize, FILE *fh)
struct sockaddr_in s;
memset(&s, '\0', sizeof(struct sockaddr_in));
s.sin_family = AF_INET;
s.sin_port = htons(NETLOADER_SERVER_PORT);
s.sin_port = htons(port);
s.sin_addr.s_addr = nxaddr;

if (connect(sock,(struct sockaddr *)&s,sizeof(s)) < 0) {
Expand Down Expand Up @@ -422,6 +422,7 @@ static void showHelp() {
puts("Usage: nxlink [options] nrofile\n");
puts("--help, -h Display this information");
puts("--address, -a Hostname or IPv4 address of Switch");
puts("--port, -z Port of Switch netloader server");
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");
Expand Down Expand Up @@ -488,6 +489,7 @@ int main(int argc, char **argv) {
char *address = NULL;
char *basepath = NULL;
char *finalpath = NULL;
char *port = NULL;
char *endarg = NULL;
char *extra_args = NULL;
int retries = 10;
Expand All @@ -503,6 +505,7 @@ int main(int argc, char **argv) {
{"address", required_argument, 0, 'a'},
{"retries", required_argument, 0, 'r'},
{"path", required_argument, 0, 'p'},
{"port", required_argument, 0, 'z'},
{"args", required_argument, 0, NRO_ARGS},
{"help", no_argument, 0, 'h'},
{"server", no_argument, &server, 1 },
Expand All @@ -512,17 +515,19 @@ int main(int argc, char **argv) {
/* getopt_long stores the option index here. */
int option_index = 0, c;

c = getopt_long (argc, argv, "a:r:hp:s", long_options, &option_index);
c = getopt_long (argc, argv, "a:z:r:hp:s", long_options, &option_index);

/* Detect the end of the options. */
if (c == -1)
break;

switch(c) {

case 'a':
address = optarg;
break;
case 'z':
port = optarg;
break;
case 'r':
errno = 0;
retries = strtoul(optarg, &endarg, 0);
Expand Down Expand Up @@ -641,7 +646,12 @@ int main(int argc, char **argv) {
return EXIT_FAILURE;
}

int res = sendNROFile(nxaddr.s_addr,finalpath,filesize,fh);
int srvPort = NETLOADER_SERVER_PORT;
if (port != NULL) {
srvPort = atoi(port);
}

int res = sendNROFile(nxaddr.s_addr,finalpath,filesize,fh,srvPort);

fclose(fh);

Expand Down