} else {
fprintf(stderr, "nbd-client version %s\n", PACKAGE_VERSION);
}
- fprintf(stderr, "Usage: nbd-client host port nbd_device [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S] [-persist|-p] [-nofork|-n] [-name|-N name]\n");
+ fprintf(stderr, "Usage: nbd-client host port nbd_device [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S] [-persist|-p] [-nofork|-n]\n");
+ fprintf(stderr, "Or : nbd-client -name|-N name host [port] nbd_device [-block-size|-b block size] [-timeout|-t timeout] [-swap|-s] [-sdp|-S] [-persist|-p] [-nofork|-n]\n");
fprintf(stderr, "Or : nbd-client -d nbd_device\n");
fprintf(stderr, "Or : nbd-client -c nbd_device\n");
fprintf(stderr, "Or : nbd-client -h|--help\n");
fprintf(stderr, "Allowed values for blocksize are 512,1024,2048,4096\n"); /* will be checked in kernel :) */
fprintf(stderr, "Note, that kernel 2.4.2 and older ones do not work correctly with\n");
fprintf(stderr, "blocksizes other than 1024 without patches\n");
+ fprintf(stderr, "Default value for port with -N is 10809. Note that port must always be numeric\n");
}
void disconnect(char* device) {
nonspecial++;
} else {
port = optarg;
- if(name) {
- usage("port and name specified at the same time. This is not supported.");
- exit(EXIT_FAILURE);
- }
}
break;
case 2:
break;
case 'N':
name=optarg;
- if(port) {
- usage("port and name specified at the same time. This is not supported.");
- exit(EXIT_FAILURE);
+ if(!port) {
+ port = NBD_DEFAULT_PORT;
}
- port = NBD_DEFAULT_PORT;
break;
case 'p':
cont=1;
oldstyle is set to false (and then the
command-line client isn't used, gna gna) */
char* modern_listen; /**< listenaddr value for modernsock */
+char* modernport=NBD_DEFAULT_PORT; /**< Port number on which to listen for
+ new-style nbd-client connections */
/**
* Types of virtuatlization
"\t-p|--pid-file\t\tspecify a filename to write our PID to\n"
"\t-o|--output-config\toutput a config file section for what you\n\t\t\t\tspecified on the command line, with the\n\t\t\t\tspecified section name\n"
"\t-M|--max-connections\tspecify the maximum number of opened connections\n\n"
- "\tif port is set to 0, stdin is used (for running from inetd)\n"
+ "\tif port is set to 0, stdin is used (for running from inetd).\n"
"\tif file_to_export contains '%%s', it is substituted with the IP\n"
"\t\taddress of the machine trying to connect\n"
"\tif ip is set, it contains the local IP address on which we're listening.\n\tif not, the server will listen on all local IP addresses\n");
{ "group", FALSE, PARAM_STRING, &rungroup, 0 },
{ "oldstyle", FALSE, PARAM_BOOL, &do_oldstyle, 1 },
{ "listenaddr", FALSE, PARAM_STRING, &modern_listen, 0 },
+ { "port", FALSE, PARAM_STRING, &modernport, 0 },
};
PARAM* p=gp;
int p_size=sizeof(gp)/sizeof(PARAM);
}
break;
}
- if(!strcmp(p[j].paramname, "port") && !strcmp(p[j].target, NBD_DEFAULT_PORT)) {
- g_set_error(e, errdomain, CFILE_INCORRECT_PORT, "Config file specifies default port for oldstyle export");
+ if(!strcmp(p[j].paramname, "port") && !strcmp(p[j].target, modernport)) {
+ g_set_error(e, errdomain, CFILE_INCORRECT_PORT, "Config file specifies new-style port for oldstyle export");
g_key_file_free(cfile);
return NULL;
}
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_UNSPEC;
hints.ai_protocol = IPPROTO_TCP;
- e = getaddrinfo(modern_listen, NBD_DEFAULT_PORT, &hints, &ai);
+ e = getaddrinfo(modern_listen, modernport, &hints, &ai);
if(e != 0) {
fprintf(stderr, "getaddrinfo failed: %s\n", gai_strerror(e));
exit(EXIT_FAILURE);
if(argc<3) {
g_message("%d: Not enough arguments", (int)getpid());
g_message("%d: Usage: %s <hostname> <port>", (int)getpid(), argv[0]);
- g_message("%d: Or: %s <hostname> -N <exportname>", (int)getpid(), argv[0]);
+ g_message("%d: Or: %s <hostname> -N <exportname> [<port>]", (int)getpid(), argv[0]);
exit(EXIT_FAILURE);
}
logging();
nonopt++;
break;
case 1:
- if(want_port)
p=(strtol(argv[2], NULL, 0));
if(p==LONG_MIN||p==LONG_MAX) {
g_critical("Could not parse port number: %s", strerror(errno));
break;
case 'N':
name=g_strdup(optarg);
- p = 10809;
+ if(!p) {
+ p = 10809;
+ }
want_port = false;
break;
case 't':