Use a different magic
authorWouter Verhelst <w@uter.be>
Tue, 27 Jul 2010 11:34:04 +0000 (07:34 -0400)
committerWouter Verhelst <w@uter.be>
Tue, 27 Jul 2010 11:34:04 +0000 (07:34 -0400)
Use a different magic, to avoid old clients accidentally using the
well-known port and hanging.

nbd-client.c
nbd-server.c

index 6e5225d..63202d2 100644 (file)
@@ -139,14 +139,14 @@ void negotiate(int sock, u64 *rsize64, u32 *flags, char* name) {
        if (read(sock, &magic, sizeof(magic)) < 0)
                err("Failed/2: %m");
        magic = ntohll(magic);
-       if (magic != cliserv_magic)
-               err("Not enough cliserv_magic");
-       printf(".");
        if(name) {
                uint32_t opt;
                uint64_t namesize;
                uint64_t reserved = 0;
 
+               if (magic != opts_magic)
+                       err("Not enough opts_magic");
+               printf(".");
                if(read(sock, &tmp, sizeof(uint16_t)) < 0) {
                        err("Failed reading flags: %m");
                }
@@ -164,6 +164,10 @@ void negotiate(int sock, u64 *rsize64, u32 *flags, char* name) {
                namesize = ntohll(namesize);
                write(sock, &namesize, sizeof(namesize));
                write(sock, name, strlen(name));
+       } else {
+               if (magic != cliserv_magic)
+                       err("Not enough cliserv_magic");
+               printf(".");
        }
 
        if (read(sock, &size64, sizeof(size64)) < 0)
@@ -264,7 +268,7 @@ void usage(char* errmsg, ...) {
        } 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]\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] [-name|-N name]\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");
index f07a29f..b92170a 100644 (file)
@@ -1218,6 +1218,7 @@ CLIENT* negotiate(int net, CLIENT *client, GArray* servers) {
        uint64_t size_host;
        uint32_t flags = NBD_FLAG_HAS_FLAGS;
        uint16_t smallflags = 0;
+       uint64_t magic;
 
        memset(zeros, '\0', sizeof(zeros));
        if(!client || !client->modern) {
@@ -1226,8 +1227,8 @@ CLIENT* negotiate(int net, CLIENT *client, GArray* servers) {
                        if(client)
                                exit(EXIT_FAILURE);
                }
-               cliserv_magic = htonll(cliserv_magic);
-               if (write(net, &cliserv_magic, sizeof(cliserv_magic)) < 0) {
+               magic = htonll(opts_magic);
+               if (write(net, &magic, sizeof(magic)) < 0) {
                        err_nonfatal("Negotiation failed: %m");
                        if(client)
                                exit(EXIT_FAILURE);
@@ -1235,7 +1236,6 @@ CLIENT* negotiate(int net, CLIENT *client, GArray* servers) {
        }
        if(!client) {
                uint64_t reserved;
-               uint64_t magic;
                uint32_t opt;
                uint64_t namelen;
                char* name;