Oops
[nbd.git] / nbd-client.c
index 63202d2..b0631ca 100644 (file)
 #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;
@@ -141,8 +141,8 @@ void negotiate(int sock, u64 *rsize64, u32 *flags, char* name) {
        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");
@@ -156,12 +156,12 @@ void negotiate(int sock, u64 *rsize64, u32 *flags, char* name) {
                write(sock, &reserved, sizeof(reserved));
 
                /* Write the export name that we're after */
-               magic = ntohll(cliserv_magic);
+               magic = ntohll(opts_magic);
                write(sock, &magic, sizeof(magic));
                opt = ntohl(NBD_OPT_EXPORT_NAME);
                write(sock, &opt, sizeof(opt));
-               namesize = (u64)strlen(name);
-               namesize = ntohll(namesize);
+               namesize = (u32)strlen(name);
+               namesize = ntohl(namesize);
                write(sock, &namesize, sizeof(namesize));
                write(sock, name, strlen(name));
        } else {
@@ -358,12 +358,12 @@ int main(int argc, char *argv[]) {
                                        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);
@@ -384,8 +384,7 @@ int main(int argc, char *argv[]) {
                        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);