* Version 1.0 - 64bit issues should be fixed, now
* Version 1.1 - added bs (blocksize) option (Alexey Guzeev, aga@permonline.ru)
* Version 1.2 - I added new option '-d' to send the disconnect request
+ * Version 2.0 - Version synchronised with server
+ * Version 2.1 - Check for disconnection before INIT_PASSWD is received
+ * to make errormsg a bit more helpful in case the server can't
+ * open the exported file.
*/
#include <asm/page.h>
#include <linux/ioctl.h>
#include "cliserv.h"
+/**
+ * Open a connection to a given host on a given port.
+ * @param name The host to connect to
+ * @param port The port to connect to
+ * @return A connected socket to the given host on the given port
+ **/
int opennet(char *name, int port)
{
int sock;
return sock;
}
+/**
+ * Do everything
+ * @todo cut this thing into little tiny manageable pieces, preferably with a
+ * chainsaw.
+ **/
int main(int argc, char *argv[])
{
int port, sock, nbd, one = 1;
if (argc < 3) {
errmsg:
+ fprintf(stderr, "nbd-client version %s\n", PACKAGE_VERSION);
fprintf(stderr, "Usage: nbd-client [bs=blocksize] host port nbd_device [-swap]\n");
fprintf(stderr, "Or : nbd-client -d nbd_device\n");
fprintf(stderr, "Default value for blocksize is 1024 (recommended for ethernet)\n");
printf("Negotiation: ");
if (read(sock, buf, 8) < 0)
err("Failed/1: %m");
+ if (strlen(buf)==0)
+ err("Server closed connection");
if (strcmp(buf, INIT_PASSWD))
err("INIT_PASSWD bad");
printf(".");