Back to index

nbd  3.2
Defines | Functions | Variables
cliserv.h File Reference
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <stdlib.h>
#include "nbd.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define __be32   u32
#define __be64   u64
#define fdatasync(arg)   fsync(arg)
#define INIT_PASSWD   "NBDMAGIC"
#define INFO(a)   do { } while(0)
#define G_GNUC_NORETURN
#define G_GNUC_UNUSED
#define htonll   ntohll
#define NBD_DEFAULT_PORT
#define NBD_OPT_EXPORT_NAME   (1) /** Client wants to select a named export (is followed by name of export) */
#define NBD_OPT_ABORT   (2) /** Client wishes to abort negotiation */
#define NBD_OPT_LIST   (3) /** Client request list of supported exports (not followed by data) */
#define NBD_REP_ACK   (1) /** ACK a request. Data: option number to be acked */
#define NBD_REP_SERVER   (2) /** Reply to NBD_OPT_LIST (one of these per server; must be followed by NBD_REP_ACK to signal the end of the list */
#define NBD_REP_FLAG_ERROR   (1 << 31) /** If the high bit is set, the reply is an error */
#define NBD_REP_ERR_UNSUP   (1 | NBD_REP_FLAG_ERROR) /** Client requested an option not understood by this version of the server */
#define NBD_REP_ERR_POLICY   (2 | NBD_REP_FLAG_ERROR) /** Client requested an option not allowed by server configuration. (e.g., the option was disabled) */
#define NBD_REP_ERR_INVALID   (3 | NBD_REP_FLAG_ERROR) /** Client issued an invalid request */
#define NBD_REP_ERR_PLATFORM   (4 | NBD_REP_FLAG_ERROR) /** Option not supported on this platform */
#define NBD_FLAG_FIXED_NEWSTYLE   (1 << 0) /* new-style export that actually supports extending */
#define NBD_FLAG_C_FIXED_NEWSTYLE   NBD_FLAG_FIXED_NEWSTYLE

Functions

void setmysockopt (int sock)
void err_nonfatal (const char *s)
void err (const char *s) G_GNUC_NORETURN
void logging (void)
u64 ntohll (u64 a)

Variables

u64 cliserv_magic = 0x00420281861253LL
u64 opts_magic = 0x49484156454F5054LL
u64 rep_magic = 0x3e889045565a9LL

Define Documentation

#define __be32   u32

Definition at line 39 of file cliserv.h.

#define __be64   u64

Definition at line 40 of file cliserv.h.

#define fdatasync (   arg)    fsync(arg)

Definition at line 44 of file cliserv.h.

#define G_GNUC_NORETURN

Definition at line 87 of file cliserv.h.

#define G_GNUC_UNUSED

Definition at line 88 of file cliserv.h.

#define htonll   ntohll

Definition at line 146 of file cliserv.h.

#define INFO (   a)    do { } while(0)

Definition at line 62 of file cliserv.h.

#define INIT_PASSWD   "NBDMAGIC"

Definition at line 60 of file cliserv.h.

Value:
"10809"       /* Port on which named exports are
                                    * served */

Definition at line 148 of file cliserv.h.

Definition at line 167 of file cliserv.h.

#define NBD_FLAG_FIXED_NEWSTYLE   (1 << 0) /* new-style export that actually supports extending */

Definition at line 165 of file cliserv.h.

#define NBD_OPT_ABORT   (2) /** Client wishes to abort negotiation */

Definition at line 152 of file cliserv.h.

#define NBD_OPT_EXPORT_NAME   (1) /** Client wants to select a named export (is followed by name of export) */

Definition at line 151 of file cliserv.h.

#define NBD_OPT_LIST   (3) /** Client request list of supported exports (not followed by data) */

Definition at line 153 of file cliserv.h.

#define NBD_REP_ACK   (1) /** ACK a request. Data: option number to be acked */

Definition at line 156 of file cliserv.h.

#define NBD_REP_ERR_INVALID   (3 | NBD_REP_FLAG_ERROR) /** Client issued an invalid request */

Definition at line 161 of file cliserv.h.

#define NBD_REP_ERR_PLATFORM   (4 | NBD_REP_FLAG_ERROR) /** Option not supported on this platform */

Definition at line 162 of file cliserv.h.

#define NBD_REP_ERR_POLICY   (2 | NBD_REP_FLAG_ERROR) /** Client requested an option not allowed by server configuration. (e.g., the option was disabled) */

Definition at line 160 of file cliserv.h.

#define NBD_REP_ERR_UNSUP   (1 | NBD_REP_FLAG_ERROR) /** Client requested an option not understood by this version of the server */

Definition at line 159 of file cliserv.h.

#define NBD_REP_FLAG_ERROR   (1 << 31) /** If the high bit is set, the reply is an error */

Definition at line 158 of file cliserv.h.

#define NBD_REP_SERVER   (2) /** Reply to NBD_OPT_LIST (one of these per server; must be followed by NBD_REP_ACK to signal the end of the list */

Definition at line 157 of file cliserv.h.


Function Documentation

void err ( const char *  s)

Definition at line 120 of file cliserv.h.

                        {
       err_nonfatal(s);
       exit(EXIT_FAILURE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void err_nonfatal ( const char *  s)

Definition at line 92 of file cliserv.h.

                                 {
       char s1[150], *s2;

       strncpy(s1, s, sizeof(s1));
       if ((s2 = strstr(s, "%m"))) {
              strcpy(s1 + (s2 - s), strerror(errno));
              s2 += 2;
              strcpy(s1 + strlen(s1), s2);
       }
#ifndef       sun
       /* Solaris doesn't have %h in syslog */
       else if ((s2 = strstr(s, "%h"))) {
              strcpy(s1 + (s2 - s), hstrerror(h_errno));
              s2 += 2;
              strcpy(s1 + strlen(s1), s2);
       }
#endif

       s1[sizeof(s1)-1] = '\0';
#ifdef ISSERVER
       syslog(LOG_ERR, "%s", s1);
       syslog(LOG_ERR, "Exiting.");
#endif
       fprintf(stderr, "Error: %s\nExiting.\n", s1);
}

Here is the caller graph for this function:

void logging ( void  )

Definition at line 125 of file cliserv.h.

                   {
#ifdef ISSERVER
       openlog(MY_NAME, LOG_PID, LOG_DAEMON);
#endif
       setvbuf(stdout, NULL, _IONBF, 0);
       setvbuf(stderr, NULL, _IONBF, 0);
}

Here is the caller graph for this function:

u64 ntohll ( u64  a)

Definition at line 138 of file cliserv.h.

                  {
       u32 lo = a & 0xffffffff;
       u32 hi = a >> 32U;
       lo = ntohl(lo);
       hi = ntohl(hi);
       return ((u64) lo) << 32U | hi;
}

Here is the caller graph for this function:

void setmysockopt ( int  sock)

Definition at line 64 of file cliserv.h.

                            {
       int size = 1;
#if 0
       if (setsockopt(sock, SOL_SOCKET, SO_SNDBUF, &size, sizeof(int)) < 0)
               INFO("(no sockopt/1: %m)");
#endif
#ifdef IPPROTO_TCP
       size = 1;
       if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &size, sizeof(int)) < 0)
               INFO("(no sockopt/2: %m)");
#endif
#if 0
       size = 1024;
       if (setsockopt(sock, IPPROTO_TCP, TCP_MAXSEG, &size, sizeof(int)) < 0)
               INFO("(no sockopt/3: %m)");
#endif
}

Here is the caller graph for this function:


Variable Documentation

u64 cliserv_magic = 0x00420281861253LL

Definition at line 57 of file cliserv.h.

u64 opts_magic = 0x49484156454F5054LL

Definition at line 58 of file cliserv.h.

u64 rep_magic = 0x3e889045565a9LL

Definition at line 59 of file cliserv.h.