- /* The information we get now contains information on sizes. If
- * we're here, that means we want a 'working' connection, but
- * we're not interested in the sizes. So, read them but throw
- * the values away. We need to read the size of the device (a
- * 64bit integer) plus the reserved fields (128 bytes; should
- * all be zeroes).
- */
- read_all(sock, buf, sizeof(tmp64)+128);
+ if(!name) {
+ read_all(sock, &size, sizeof(size));
+ size=ntohll(size);
+ read_all(sock, buf, 128);
+ goto end;
+ }
+ /* flags */
+ read_all(sock, buf, sizeof(uint16_t));
+ /* reserved field */
+ write(sock, &tmp32, sizeof(tmp32));
+ /* magic */
+ tmp64 = htonll(opts_magic);
+ write(sock, &tmp64, sizeof(tmp64));
+ /* name */
+ tmp32 = htonl(NBD_OPT_EXPORT_NAME);
+ write(sock, &tmp32, sizeof(tmp32));
+ tmp32 = htonl((uint32_t)strlen(name));
+ write(sock, &tmp32, sizeof(tmp32));
+ write(sock, name, strlen(name));
+ read_all(sock, &size, sizeof(size));
+ size = ntohll(size);
+ read_all(sock, buf, sizeof(uint16_t)+124);