]> git.saurik.com Git - apple/security.git/blob - cdsa/cdsa_utilities/fdmover.h
2d6a5b244c3a0f48808accc7933c1288433adbd3
[apple/security.git] / cdsa / cdsa_utilities / fdmover.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // fdmover - send/receive file descriptors over a UNIX domain socket connection
21 //
22 // An FdMover object is a very specialized Socket:
23 // It must be bound to a UNIX domain address
24 //
25 #ifndef _H_FDMOVER
26 #define _H_FDMOVER
27
28 #include "ip++.h"
29 #include <vector>
30
31 using namespace UnixPlusPlus;
32
33
34 namespace Security {
35 namespace IPPlusPlus {
36
37
38 // an ordered list of file descriptors
39 typedef std::vector<FileDesc> FdVector;
40
41
42 //
43 // An FdMover - a specialized Socket for transferring file descriptors
44 // across UNIX domain sockets.
45 //
46 class FdMover : public Socket {
47 private:
48 class Element : public cmsghdr {
49 public:
50 void *operator new (size_t base, size_t more);
51 void operator delete (void *addr, size_t size);
52
53 Element() { }
54 Element(int level, int type);
55
56 template <class T> T &payload() { return *reinterpret_cast<T *>(CMSG_DATA(this)); }
57 size_t payloadSize() const { return cmsg_len - ((caddr_t)CMSG_DATA(this) - (caddr_t)this); }
58 };
59
60 class Message : public msghdr {
61 public:
62 Message(const void *data, size_t length);
63 void set(Element *elem);
64 Element *element() const { return (Element *)msg_control; }
65 Element *next(Element *elem) const { return (Element *)CMSG_NXTHDR(this, elem); }
66
67 public:
68 IOVec iovec;
69 };
70
71 public:
72 FdMover() { }
73 FdMover(Socket s) : Socket(s) { }
74
75 size_t send(const void *data, size_t length, const FdVector &fds);
76 size_t receive(void *data, size_t length, FdVector &fds);
77
78 private:
79
80 };
81
82
83 } // end namespace IPPlusPlus
84 } // end namespace Security
85
86
87 #endif //_H_FDMOVER