#include <getopt.h>
#include <stdarg.h>
-#ifndef __GNUC__
-#error I need GCC to work
-#endif
-
#include <linux/ioctl.h>
#define MY_NAME "nbd_client"
#include "cliserv.h"
+#ifdef WITH_SDP
+#include <sdp_inet.h>
+#endif
+
int check_conn(char* devname, int do_print) {
char buf[256];
char* p;
magic = ntohll(magic);
if(name) {
uint32_t opt;
- uint64_t namesize;
- uint64_t reserved = 0;
+ uint32_t namesize;
+ uint32_t reserved = 0;
if (magic != opts_magic)
err("Not enough opts_magic");
*flags = ((u32)ntohs(tmp)) << 16;
/* reserved for future use*/
- write(sock, &reserved, sizeof(reserved));
+ if (write(sock, &reserved, sizeof(reserved)) < 0)
+ err("Failed/2.1: %m");
/* Write the export name that we're after */
- magic = ntohll(cliserv_magic);
- write(sock, &magic, sizeof(magic));
+ magic = ntohll(opts_magic);
+ if (write(sock, &magic, sizeof(magic)) < 0)
+ err("Failed/2.2: %m");
opt = ntohl(NBD_OPT_EXPORT_NAME);
- write(sock, &opt, sizeof(opt));
- namesize = (u64)strlen(name);
- namesize = ntohll(namesize);
- write(sock, &namesize, sizeof(namesize));
- write(sock, name, strlen(name));
+ if (write(sock, &opt, sizeof(opt)) < 0)
+ err("Failed/2.3: %m");
+ namesize = (u32)strlen(name);
+ namesize = ntohl(namesize);
+ if (write(sock, &namesize, sizeof(namesize)) < 0)
+ err("Failed/2.4: %m");
+ if (write(sock, name, strlen(name)) < 0)
+ err("Failed/2.4: %m");
} else {
if (magic != cliserv_magic)
err("Not enough cliserv_magic");
break;
case 1:
// port
- port = optarg;
if(!strtol(optarg, NULL, 0)) {
// not parseable as a number, assume it's the device and we have a name
nbddev = optarg;
nonspecial++;
} else {
+ port = optarg;
if(name) {
usage("port and name specified at the same time. This is not supported.");
exit(EXIT_FAILURE);
blocksize=(int)strtol(optarg, NULL, 0);
break;
case 'c':
- check_conn(optarg, 1);
- exit(EXIT_SUCCESS);
+ return check_conn(optarg, 1);
case 'd':
disconnect(optarg);
exit(EXIT_SUCCESS);
/* Go daemon */
#ifndef NOFORK
- if(!nofork) daemon(0,0);
+ if(!nofork) {
+ if (daemon(0,0) < 0)
+ err("Cannot detach from terminal");
+ }
#endif
do {
#ifndef NOFORK