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