~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to lib/include/vmci_sockets.h

  • Committer: Package Import Robot
  • Author(s): Nate Muench
  • Date: 2012-06-20 15:59:51 UTC
  • mfrom: (1.4.8)
  • Revision ID: package-import@ubuntu.com-20120620155951-6rupmpb0f70b52zr
Tags: 2012.05.21-724730-0ubuntu1
* Merging upstream version 2012.05.21-724730.
  - Fixes building against the current Quantal kernel. (LP: #1000344)
  - Fixes Quantal installation issues. (LP: #1019031)

* Sync with Debian
  - Updating to debhelper version 9.
  - Updating to standards version 3.9.3.
  - Updating copyright file machine-readable format version 1.0.
  - Building without multiarch paths for now

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*********************************************************
2
 
 * Copyright (C) 2007 VMware, Inc. All rights reserved.
 
2
 * Copyright (C) 2007-2012 VMware, Inc. All rights reserved.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of the GNU Lesser General Public License as published
43
43
#endif // linux && !VMKERNEL
44
44
#endif
45
45
 
46
 
/*
47
 
 * We use the same value for the AF family and the socket option
48
 
 * level. To set options, use the value of VMCISock_GetAFValue for
49
 
 * 'level' and these constants for the optname.
 
46
/**
 
47
 * \brief Option name for STREAM socket buffer size.
 
48
 *
 
49
 * Use as the option name in \c setsockopt(3) or \c getsockopt(3) to set
 
50
 * or get an \c unsigned \c long \c long that specifies the size of the
 
51
 * buffer underlying a vSockets STREAM socket.
 
52
 *
 
53
 * \note Value is clamped to the MIN and MAX.
 
54
 *
 
55
 * \see VMCISock_GetAFValueFd()
 
56
 * \see SO_VMCI_BUFFER_MIN_SIZE
 
57
 * \see SO_VMCI_BUFFER_MAX_SIZE
 
58
 *
 
59
 * An example is given below.
 
60
 *
 
61
 * \code
 
62
 * int vmciFd;
 
63
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
64
 * unsigned long long val = 0x1000;
 
65
 * int fd = socket(af, SOCK_STREAM, 0);
 
66
 * setsockopt(fd, af, SO_VMCI_BUFFER_SIZE, &val, sizeof val);
 
67
 * ...
 
68
 * close(fd);
 
69
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
70
 * \endcode
50
71
 */
51
72
 
52
73
#define SO_VMCI_BUFFER_SIZE                 0
 
74
 
 
75
/**
 
76
 * \brief Option name for STREAM socket minimum buffer size.
 
77
 *
 
78
 * Use as the option name in \c setsockopt(3) or \c getsockopt(3) to set
 
79
 * or get an \c unsigned \c long \c long that specifies the minimum size
 
80
 * allowed for the buffer underlying a vSockets STREAM socket.
 
81
 *
 
82
 * \see VMCISock_GetAFValueFd()
 
83
 * \see SO_VMCI_BUFFER_SIZE
 
84
 * \see SO_VMCI_BUFFER_MAX_SIZE
 
85
 *
 
86
 * An example is given below.
 
87
 *
 
88
 * \code
 
89
 * int vmciFd;
 
90
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
91
 * unsigned long long val = 0x500;
 
92
 * int fd = socket(af, SOCK_STREAM, 0);
 
93
 * setsockopt(fd, af, SO_VMCI_BUFFER_MIN_SIZE, &val, sizeof val);
 
94
 * ...
 
95
 * close(fd);
 
96
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
97
 * \endcode
 
98
 */
 
99
 
53
100
#define SO_VMCI_BUFFER_MIN_SIZE             1
 
101
 
 
102
/**
 
103
 * \brief Option name for STREAM socket maximum buffer size.
 
104
 *
 
105
 * Use as the option name in \c setsockopt(3) or \c getsockopt(3) to set or
 
106
 * get an unsigned long long that specifies the maximum size allowed for the
 
107
 * buffer underlying a vSockets STREAM socket.
 
108
 *
 
109
 * \see VMCISock_GetAFValueFd()
 
110
 * \see SO_VMCI_BUFFER_SIZE
 
111
 * \see SO_VMCI_BUFFER_MIN_SIZE
 
112
 *
 
113
 * An example is given below.
 
114
 *
 
115
 * \code
 
116
 * int vmciFd;
 
117
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
118
 * unsigned long long val = 0x4000;
 
119
 * int fd = socket(af, SOCK_STREAM, 0);
 
120
 * setsockopt(fd, af, SO_VMCI_BUFFER_MAX_SIZE, &val, sizeof val);
 
121
 * ...
 
122
 * close(fd);
 
123
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
124
 * \endcode
 
125
 */
 
126
 
54
127
#define SO_VMCI_BUFFER_MAX_SIZE             2
 
128
 
 
129
/**
 
130
 * \brief Option name for socket peer's host-specific VM ID.
 
131
 *
 
132
 * Use as the option name in \c getsockopt(3) to get a host-specific identifier
 
133
 * for the peer endpoint's VM.  The identifier is a signed integer.
 
134
 *
 
135
 * \note Only available for ESX (VMKernel/userworld) endpoints.
 
136
 *
 
137
 * An example is given below.
 
138
 *
 
139
 * \code
 
140
 * int vmciFd;
 
141
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
142
 * int id;
 
143
 * socklen_t len = sizeof id;
 
144
 * int fd = socket(af, SOCK_DGRAM, 0);
 
145
 * getsockopt(fd, af, SO_VMCI_PEER_HOST_VM_ID, &id, &len);
 
146
 * ...
 
147
 * close(fd);
 
148
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
149
 * \endcode
 
150
 */
 
151
 
55
152
#define SO_VMCI_PEER_HOST_VM_ID             3
 
153
 
 
154
/**
 
155
 * \brief Option name for socket's service label.
 
156
 *
 
157
 * Use as the option name in \c setsockopt(3) or \c getsockopt(3) to set or
 
158
 * get the service label for a socket.  The service label is a C-style
 
159
 * NUL-terminated string.
 
160
 *
 
161
 * \note Only available for ESX (VMkernel/userworld) endpoints.
 
162
 */
 
163
 
56
164
#define SO_VMCI_SERVICE_LABEL               4
 
165
 
 
166
/**
 
167
 * \brief Option name for determining if a socket is trusted.
 
168
 *
 
169
 * Use as the option name in \c getsockopt(3) to determine if a socket is
 
170
 * trusted.  The value is a signed integer.
 
171
 *
 
172
 * An example is given below.
 
173
 *
 
174
 * \code
 
175
 * int vmciFd;
 
176
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
177
 * int trusted;
 
178
 * socklen_t len = sizeof trusted;
 
179
 * int fd = socket(af, SOCK_DGRAM, 0);
 
180
 * getsockopt(fd, af, SO_VMCI_TRUSTED, &trusted, &len);
 
181
 * ...
 
182
 * close(fd);
 
183
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
184
 * \endcode
 
185
 */
 
186
 
57
187
#define SO_VMCI_TRUSTED                     5
 
188
 
 
189
/**
 
190
 * \brief Option name for STREAM socket connection timeout.
 
191
 *
 
192
 * Use as the option name in \c setsockopt(3) or \c getsockopt(3) to set or
 
193
 * get the connection timeout for a STREAM socket.  The value is platform
 
194
 * dependent.  On ESX, Linux and Mac OS, it is a \c struct \c timeval.
 
195
 * On Windows, it is a \c DWORD.
 
196
 *
 
197
 * An example is given below.
 
198
 *
 
199
 * \code
 
200
 * int vmciFd;
 
201
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
202
 * struct timeval t = { 5, 100000 }; // 5.1 seconds
 
203
 * int fd = socket(af, SOCK_STREAM, 0);
 
204
 * setsockopt(fd, af, SO_VMCI_CONNECT_TIMEOUT, &t, sizeof t);
 
205
 * ...
 
206
 * close(fd);
 
207
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
208
 * \endcode
 
209
 */
 
210
 
58
211
#define SO_VMCI_CONNECT_TIMEOUT             6
 
212
 
 
213
/**
 
214
 * \brief Option name for using non-blocking send/receive.
 
215
 *
 
216
 * Use as the option name for \c setsockopt(3) or \c getsockopt(3) to set or
 
217
 * get the non-blocking transmit/receive flag for a STREAM socket.  This flag
 
218
 * determines whether \c send() and \c recv() can be called in non-blocking
 
219
 * contexts for the given socket.  The value is a signed integer.
 
220
 *
 
221
 * This option is only relevant to kernel endpoints, where descheduling
 
222
 * the thread of execution is not allowed, for example, while holding a
 
223
 * spinlock.  It is not to be confused with conventional non-blocking socket
 
224
 * operations.
 
225
 *
 
226
 * \note Only available for VMKernel endpoints.
 
227
 *
 
228
 * An example is given below.
 
229
 *
 
230
 * \code
 
231
 * int vmciFd;
 
232
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
233
 * int nonblock;
 
234
 * socklen_t len = sizeof nonblock;
 
235
 * int fd = socket(af, SOCK_STREAM, 0);
 
236
 * getsockopt(fd, af, SO_VMCI_NONBLOCK_TXRX, &nonblock, &len);
 
237
 * ...
 
238
 * close(fd);
 
239
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
240
 * \endcode
 
241
 */
 
242
 
59
243
#define SO_VMCI_NONBLOCK_TXRX               7
60
244
 
61
 
/*
62
 
 * The VMCI sockets address equivalents of INADDR_ANY.  The first works for
63
 
 * the svm_cid (context id) field of the address structure below and indicates
64
 
 * the current guest (or the host, if running outside a guest), while the
65
 
 * second indicates any available port.
 
245
/**
 
246
 * \brief The vSocket equivalent of INADDR_ANY.
 
247
 *
 
248
 * This works for the \c svm_cid field of sockaddr_vm and indicates the
 
249
 * context ID of the current endpoint.
 
250
 *
 
251
 * \see sockaddr_vm
 
252
 *
 
253
 * An example is given below.
 
254
 *
 
255
 * \code
 
256
 * int vmciFd;
 
257
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
258
 * struct sockaddr_vm addr;
 
259
 * int fd = socket(af, SOCK_DGRAM, 0);
 
260
 * addr.svm_family = af;
 
261
 * addr.svm_cid = VMADDR_CID_ANY;
 
262
 * addr.svm_port = 2000;
 
263
 * bind(fd, &addr, sizeof addr);
 
264
 * ...
 
265
 * close(fd);
 
266
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
267
 * \endcode
66
268
 */
67
269
 
68
270
#define VMADDR_CID_ANY  ((unsigned int)-1)
 
271
 
 
272
/**
 
273
 * \brief Bind to any available port.
 
274
 *
 
275
 * Works for the \c svm_port field of sockaddr_vm.
 
276
 *
 
277
 * \see sockaddr_vm
 
278
 *
 
279
 * An example is given below.
 
280
 *
 
281
 * \code
 
282
 * int vmciFd;
 
283
 * int af = VMCISock_GetAFValueFd(&vmciFd);
 
284
 * struct sockaddr_vm addr;
 
285
 * int fd = socket(af, SOCK_DGRAM, 0);
 
286
 * addr.svm_family = af;
 
287
 * addr.svm_cid = VMADDR_CID_ANY;
 
288
 * addr.svm_port = VMADDR_PORT_ANY;
 
289
 * bind(fd, &addr, sizeof addr);
 
290
 * ...
 
291
 * close(fd);
 
292
 * VMCISock_ReleaseAFValueFd(vmciFd);
 
293
 * \endcode
 
294
 */
 
295
 
69
296
#define VMADDR_PORT_ANY ((unsigned int)-1)
70
297
 
71
 
 
72
 
/* Invalid VMCI sockets version. */
 
298
/**
 
299
 * \brief Invalid vSockets version.
 
300
 *
 
301
 * \see VMCISock_Version()
 
302
 */
73
303
 
74
304
#define VMCI_SOCKETS_INVALID_VERSION ((unsigned int)-1)
75
305
 
76
 
/*
77
 
 * Use these macros with the result of VMCISock_Version() to get the
78
 
 * component parts of a valid version.
 
306
/**
 
307
 * \brief The epoch (first) component of the vSockets version.
 
308
 *
 
309
 * A single byte representing the epoch component of the vSockets version.
 
310
 *
 
311
 * \see VMCISock_Version()
 
312
 *
 
313
 * An example is given below.
 
314
 *
 
315
 * \code
 
316
 * unsigned int ver = VMCISock_Version();
 
317
 * unsigned char epoch = VMCI_SOCKETS_VERSION_EPOCH(ver);
 
318
 * \endcode
79
319
 */
80
320
 
81
321
#define VMCI_SOCKETS_VERSION_EPOCH(_v) (((_v) & 0xFF000000) >> 24)
 
322
 
 
323
/**
 
324
 * \brief The major (second) component of the vSockets version.
 
325
 *
 
326
 * A single byte representing the major component of the vSockets version.
 
327
 * Typically changes for every major release of a product.
 
328
 *
 
329
 * \see VMCISock_Version()
 
330
 *
 
331
 * An example is given below.
 
332
 *
 
333
 * \code
 
334
 * unsigned int ver = VMCISock_Version();
 
335
 * unsigned char major = VMCI_SOCKETS_VERSION_MAJOR(ver);
 
336
 * \endcode
 
337
 */
 
338
 
82
339
#define VMCI_SOCKETS_VERSION_MAJOR(_v) (((_v) & 0x00FF0000) >> 16)
 
340
 
 
341
/**
 
342
 * \brief The minor (third) component of the vSockets version.
 
343
 *
 
344
 * Two bytes representing the minor component of the vSockets version.
 
345
 *
 
346
 * \see VMCISock_Version()
 
347
 *
 
348
 * An example is given below.
 
349
 *
 
350
 * \code
 
351
 * unsigned int ver = VMCISock_Version();
 
352
 * unsigned short minor = VMCI_SOCKETS_VERSION_MINOR(ver);
 
353
 * \endcode
 
354
 */
 
355
 
83
356
#define VMCI_SOCKETS_VERSION_MINOR(_v) (((_v) & 0x0000FFFF))
84
357
 
85
 
/* Missing types for some platforms. */
86
 
 
 
358
/** \cond PRIVATE */
87
359
#if defined(_WIN32) || defined(VMKERNEL)
88
360
   typedef unsigned short sa_family_t;
89
361
#endif // _WIN32
94
366
      char sa_data[14];
95
367
   };
96
368
#endif
 
369
/** \endcond */
97
370
 
98
 
/*
99
 
 * Address structure for VSockets VMCI sockets. The address family should be
100
 
 * set to AF_VMCI. The structure members should all align on their natural
101
 
 * boundaries without resorting to compiler packing directives.
 
371
/**
 
372
 * \brief Address structure for vSockets.
 
373
 *
 
374
 * The address family should be set to whatever VMCISock_GetAFValueFd()
 
375
 * returns.  The structure members should all align on their natural
 
376
 * boundaries without resorting to compiler packing directives.  The total
 
377
 * size of this structure should be exactly the same as that of \c struct
 
378
 * \c sockaddr.
 
379
 *
 
380
 * \see VMCISock_GetAFValueFd()
102
381
 */
103
382
 
104
383
struct sockaddr_vm {
105
384
#if defined(__APPLE__)
106
 
   unsigned char svm_len;                           // Mac OS has the length first.
 
385
   unsigned char svm_len;
107
386
#endif // __APPLE__
108
 
   sa_family_t svm_family;                          // AF_VMCI.
109
 
   unsigned short svm_reserved1;                    // Reserved.
110
 
   unsigned int svm_port;                           // Port.
111
 
   unsigned int svm_cid;                            // Context id.
112
 
   unsigned char svm_zero[sizeof(struct sockaddr) - // Same size as sockaddr.
 
387
 
 
388
   /** \brief Address family. \see VMCISock_GetAFValueFd() */
 
389
   sa_family_t svm_family;
 
390
 
 
391
   /** \cond PRIVATE */
 
392
   unsigned short svm_reserved1;
 
393
   /** \endcond */
 
394
 
 
395
   /** \brief Port.  \see VMADDR_PORT_ANY */
 
396
   unsigned int svm_port;
 
397
 
 
398
   /** \brief Context ID.  \see VMADDR_CID_ANY */
 
399
   unsigned int svm_cid;
 
400
 
 
401
   /** \cond PRIVATE */
 
402
   unsigned char svm_zero[sizeof(struct sockaddr) -
113
403
#if defined(__APPLE__)
114
404
                             sizeof(unsigned char) -
115
405
#endif // __APPLE__
117
407
                             sizeof(unsigned short) -
118
408
                             sizeof(unsigned int) -
119
409
                             sizeof(unsigned int)];
 
410
   /** \endcond */
120
411
};
121
412
 
122
413
 
187
478
 
188
479
#  include <stdio.h>
189
480
 
 
481
/** \cond PRIVATE */
190
482
#  define VMCI_SOCKETS_DEFAULT_DEVICE      "/dev/vsock"
191
483
#  define VMCI_SOCKETS_CLASSIC_ESX_DEVICE  "/vmfs/devices/char/vsock/vsock"
192
 
 
193
 
# if defined(linux)
194
 
#  define VMCI_SOCKETS_VERSION       1972
195
 
#  define VMCI_SOCKETS_GET_AF_VALUE  1976
196
 
#  define VMCI_SOCKETS_GET_LOCAL_CID 1977
197
 
# elif defined(__APPLE__)
198
 
#  include <sys/ioccom.h>
199
 
#  define VMCI_SOCKETS_VERSION       _IOR('V', 21,  unsigned)
200
 
#  define VMCI_SOCKETS_GET_AF_VALUE  _IOR('V', 25 , int)
201
 
#  define VMCI_SOCKETS_GET_LOCAL_CID _IOR('V', 26 , unsigned)
 
484
#  if defined(linux)
 
485
#     define VMCI_SOCKETS_VERSION       1972
 
486
#     define VMCI_SOCKETS_GET_AF_VALUE  1976
 
487
#     define VMCI_SOCKETS_GET_LOCAL_CID 1977
 
488
#  elif defined(__APPLE__)
 
489
#     include <sys/ioccom.h>
 
490
#     define VMCI_SOCKETS_VERSION       _IOR('V', 21,  unsigned)
 
491
#     define VMCI_SOCKETS_GET_AF_VALUE  _IOR('V', 25 , int)
 
492
#     define VMCI_SOCKETS_GET_LOCAL_CID _IOR('V', 26 , unsigned)
202
493
#endif
 
494
/** \endcond */
 
495
 
 
496
   /*
 
497
    ***********************************************************************
 
498
    * VMCISock_Version                                               */ /**
 
499
    *
 
500
    * \brief Retrieve the vSockets version.
 
501
    *
 
502
    * Returns the current version of vSockets.  The version is a 32-bit
 
503
    * unsigned integer that consist of three components: the epoch, the
 
504
    * major version, and the minor version.  Use the \c VMCI_SOCKETS_VERSION
 
505
    * macros to extract the components.
 
506
    *
 
507
    * \see VMCI_SOCKETS_VERSION_EPOCH()
 
508
    * \see VMCI_SOCKETS_VERSION_MAJOR()
 
509
    * \see VMCI_SOCKETS_VERSION_MINOR()
 
510
    *
 
511
    * \retval  VMCI_SOCKETS_INVALID_VERSION  Not available.
 
512
    * \retval  other                         The current version.
 
513
    *
 
514
    * An example is given below.
 
515
    *
 
516
    * \code
 
517
    * unsigned int ver = VMCISock_Version();
 
518
    * if (ver != VMCI_SOCKETS_INVALID_VERSION) {
 
519
    *    printf("vSockets version=%d.%d.%d\n",
 
520
    *           VMCI_SOCKETS_VERSION_EPOCH(ver),
 
521
    *           VMCI_SOCKETS_VERSION_MAJOR(ver),
 
522
    *           VMCI_SOCKETS_VERSION_MINOR(ver));
 
523
    * }
 
524
    * \endcode
 
525
    *
 
526
    ***********************************************************************
 
527
    */
203
528
 
204
529
   static inline unsigned int VMCISock_Version(void)
205
530
   {
223
548
   }
224
549
 
225
550
   /*
226
 
    *----------------------------------------------------------------------------
227
 
    *
228
 
    * VMCISock_GetAFValue and VMCISock_GetAFValueFd --
229
 
    *
230
 
    *      Returns the value to be used for the VMCI Sockets address family.
231
 
    *      This value should be used as the domain argument to socket(2) (when
232
 
    *      you might otherwise use AF_INET).  For VMCI Socket-specific options,
233
 
    *      this value should also be used for the level argument to
234
 
    *      setsockopt(2) (when you might otherwise use SOL_TCP).
235
 
    *
236
 
    *      This function leaves its descriptor to the vsock device open so that
237
 
    *      the socket implementation knows that the socket family is still in
238
 
    *      use.  We do this because we register our address family with the
239
 
    *      kernel on-demand and need a notification to unregister the address
240
 
    *      family.
241
 
    *
242
 
    *      For many programs this behavior is sufficient as is, but some may
243
 
    *      wish to close this descriptor once they are done with VMCI Sockets.
244
 
    *      For these programs, we provide a VMCISock_GetAFValueFd() that takes
245
 
    *      an optional outFd argument.  This value can be provided to
246
 
    *      VMCISock_ReleaseAFValueFd() only after the program no longer will
247
 
    *      use VMCI Sockets.  Note that outFd is only valid in cases where
248
 
    *      VMCISock_GetAFValueFd() returns a non-negative value.
249
 
    *
250
 
    * Results:
251
 
    *      The address family value to use on success, negative error code on
252
 
    *      failure.
253
 
    *
254
 
    *----------------------------------------------------------------------------
 
551
    ***********************************************************************
 
552
    * VMCISock_GetAFValueFd                                          */ /**
 
553
    *
 
554
    * \brief Retrieve the address family value for vSockets.
 
555
    *
 
556
    * Returns the value to be used for the VMCI Sockets address family.
 
557
    * This value should be used as the domain argument to \c socket(2) (when
 
558
    * you might otherwise use \c AF_INET).  For VMCI Socket-specific options,
 
559
    * this value should also be used for the level argument to
 
560
    * \c setsockopt(2) (when you might otherwise use \c SOL_TCP).
 
561
    *
 
562
    * \see VMCISock_ReleaseAFValueFd()
 
563
    * \see sockaddr_vm
 
564
    *
 
565
    * \param[out]    outFd    File descriptor to the VMCI device.  The
 
566
    *                         address family value is valid until this
 
567
    *                         descriptor is closed.  This parameter is
 
568
    *                         only valid if the return value is not -1.
 
569
    *                         Call VMCISock_ReleaseAFValueFd() to  close
 
570
    *                         this descriptor.
 
571
    *
 
572
    * \retval  -1       Not available.
 
573
    * \retval  other    The address family value.
 
574
    *
 
575
    * An example is given below.
 
576
    *
 
577
    * \code
 
578
    * int vmciFd;
 
579
    * int af = VMCISock_GetAFValueFd(&vmciFd);
 
580
    * if (af != -1) {
 
581
    *    int fd = socket(af, SOCK_STREAM, 0);
 
582
    *    ...
 
583
    *    close(fd);
 
584
    *    close(vmciFd);
 
585
    * }
 
586
    * \endcode
 
587
    *
 
588
    ***********************************************************************
255
589
    */
256
590
 
257
591
   static inline int VMCISock_GetAFValueFd(int *outFd)
280
614
      return family;
281
615
   }
282
616
 
 
617
   /** \cond PRIVATE */
 
618
   /*
 
619
    ***********************************************************************
 
620
    * VMCISock_GetAFValue                                            */ /**
 
621
    *
 
622
    * \brief Retrieve the address family value for vSockets.
 
623
    *
 
624
    * Returns the value to be used for the VMCI Sockets address family.
 
625
    * This value should be used as the domain argument to \c socket(2) (when
 
626
    * you might otherwise use \c AF_INET).  For VMCI Socket-specific options,
 
627
    * this value should also be used for the level argument to
 
628
    * \c setsockopt(2) (when you might otherwise use \c SOL_TCP).
 
629
    *
 
630
    * \note This function leaves its descriptor to the vsock device open so
 
631
    * that the socket implementation knows that the socket family is still in
 
632
    * use.  This is done because the address family is registered with the
 
633
    * kernel on-demand and a notification is needed to unregister the address
 
634
    * family.  Use of this function is thus discouraged; please use
 
635
    * VMCISock_GetAFValueFd() instead.
 
636
    *
 
637
    * \see VMCISock_GetAFValueFd()
 
638
    * \see sockaddr_vm
 
639
    *
 
640
    * \retval  -1       Not available.
 
641
    * \retval  other    The address family value.
 
642
    *
 
643
    * An example is given below.
 
644
    *
 
645
    * \code
 
646
    * int af = VMCISock_GetAFValue();
 
647
    * if (af != -1) {
 
648
    *    int fd = socket(af, SOCK_STREAM, 0);
 
649
    *    ...
 
650
    *    close(fd);
 
651
    * }
 
652
    * \endcode
 
653
    *
 
654
    ***********************************************************************
 
655
    */
 
656
 
283
657
   static inline int VMCISock_GetAFValue(void)
284
658
   {
285
659
      return VMCISock_GetAFValueFd(NULL);
286
660
   }
 
661
   /** \endcond PRIVATE */
287
662
 
 
663
   /*
 
664
    ***********************************************************************
 
665
    * VMCISock_ReleaseAFValueFd                                      */ /**
 
666
    *
 
667
    * \brief Release the file descriptor obtained when retrieving the
 
668
    *        address family value.
 
669
    *
 
670
    * Use this to release the file descriptor obtained by calling
 
671
    * VMCISock_GetAFValueFd().
 
672
    *
 
673
    * \see VMCISock_GetAFValueFd()
 
674
    *
 
675
    * \param[in]  fd    File descriptor to the VMCI device.
 
676
    *
 
677
    ***********************************************************************
 
678
    */
288
679
 
289
680
   static inline void VMCISock_ReleaseAFValueFd(int fd)
290
681
   {
293
684
      }
294
685
   }
295
686
 
 
687
   /*
 
688
    ***********************************************************************
 
689
    * VMCISock_GetLocalCID                                           */ /**
 
690
    *
 
691
    * \brief Retrieve the current context ID.
 
692
    *
 
693
    * \see VMADDR_CID_ANY
 
694
    *
 
695
    * \retval  VMADDR_CID_ANY    Not available.
 
696
    * \retval  other             The current context ID.
 
697
    *
 
698
    * An example is given below.
 
699
    *
 
700
    * \code
 
701
    * int vmciFd;
 
702
    * int af = VMCISock_GetAFValueFd(&vmciFd);
 
703
    * struct sockaddr_vm addr;
 
704
    * addr.svm_family = af;
 
705
    * addr.svm_cid = VMCISock_GetLocalCID();
 
706
    * VMCISock_ReleaseAFValueFd(vmciFd);
 
707
    * \endcode
 
708
    *
 
709
    ***********************************************************************
 
710
    */
 
711
 
296
712
   static inline unsigned int VMCISock_GetLocalCID(void)
297
713
   {
298
714
      int fd;