]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSShared/dnssd_ipc.h
mDNSResponder-87.tar.gz
[apple/mdnsresponder.git] / mDNSShared / dnssd_ipc.h
1 /*
2 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
13 * contributors may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 Change History (most recent first):
28
29 $Log: dnssd_ipc.h,v $
30 Revision 1.17 2004/11/23 03:39:47 cheshire
31 Let interface name/index mapping capability live directly in JNISupport.c,
32 instead of having to call through to the daemon via IPC to get this information.
33
34 Revision 1.16 2004/11/12 03:21:41 rpantos
35 rdar://problem/3809541 Add DNSSDMapIfIndexToName, DNSSDMapNameToIfIndex.
36
37 Revision 1.15 2004/10/06 02:22:20 cheshire
38 Changed MacRoman copyright symbol (should have been UTF-8 in any case :-) to ASCII-compatible "(c)"
39
40 Revision 1.14 2004/10/01 22:15:55 rpantos
41 rdar://problem/3824265: Replace APSL in client lib with BSD license.
42
43 Revision 1.13 2004/09/16 23:14:25 cheshire
44 Changes for Windows compatibility
45
46 Revision 1.12 2004/09/16 21:46:38 ksekar
47 <rdar://problem/3665304> Need SPI for LoginWindow to associate a UID with a Wide Area Rendezvous domain
48
49 Revision 1.11 2004/08/10 06:24:56 cheshire
50 Use types with precisely defined sizes for 'op' and 'reg_index', for better
51 compatibility if the daemon and the client stub are built using different compilers
52
53 Revision 1.10 2004/07/07 17:39:25 shersche
54 Change MDNS_SERVERPORT from 5533 to 5354.
55
56 Revision 1.9 2004/06/25 00:26:27 rpantos
57 Changes to fix the Posix build on Solaris.
58
59 Revision 1.8 2004/06/18 04:56:51 rpantos
60 Add layer for platform code
61
62 Revision 1.7 2004/06/12 01:08:14 cheshire
63 Changes for Windows compatibility
64
65 Revision 1.6 2003/08/12 19:56:25 cheshire
66 Update to APSL 2.0
67
68 */
69
70 #ifndef DNSSD_IPC_H
71 #define DNSSD_IPC_H
72
73 #include "dns_sd.h"
74
75
76 //
77 // Common cross platform services
78 //
79 #if defined(WIN32)
80 # include <winsock2.h>
81 # define dnssd_InvalidSocket INVALID_SOCKET
82 # define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
83 # define dnssd_EINTR WSAEINTR
84 # define MSG_WAITALL 0
85 # define dnssd_sock_t SOCKET
86 # define dnssd_sockbuf_t
87 # define dnssd_close(sock) closesocket(sock)
88 # define dnssd_errno() WSAGetLastError()
89 # define ssize_t int
90 # define getpid _getpid
91 #else
92 # include <sys/types.h>
93 # include <unistd.h>
94 # include <sys/un.h>
95 # include <string.h>
96 # include <stdio.h>
97 # include <stdlib.h>
98 # include <sys/stat.h>
99 # include <sys/socket.h>
100 # include <netinet/in.h>
101 # define dnssd_InvalidSocket -1
102 # define dnssd_EWOULDBLOCK EWOULDBLOCK
103 # define dnssd_EINTR EINTR
104 # define dnssd_EPIPE EPIPE
105 # define dnssd_sock_t int
106 # define dnssd_close(sock) close(sock)
107 # define dnssd_errno() errno
108 #endif
109
110 #if defined(USE_TCP_LOOPBACK)
111 # define AF_DNSSD AF_INET
112 # define MDNS_TCP_SERVERADDR "127.0.0.1"
113 # define MDNS_TCP_SERVERPORT 5354
114 # define LISTENQ 5
115 # define dnssd_sockaddr_t struct sockaddr_in
116 #else
117 # define AF_DNSSD AF_LOCAL
118 # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
119 # define LISTENQ 100
120 // longest legal control path length
121 # define MAX_CTLPATH 256
122 # define dnssd_sockaddr_t struct sockaddr_un
123 #endif
124
125
126 //#define UDSDEBUG // verbose debug output
127
128 // Compatibility workaround
129 #ifndef AF_LOCAL
130 #define AF_LOCAL AF_UNIX
131 #endif
132
133 // General UDS constants
134 #define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
135
136 // IPC data encoding constants and types
137 #define VERSION 1
138 #define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
139 #define IPC_FLAGS_REUSE_SOCKET 2 // set flag if synchronous errors are to be sent via the primary socket
140 // (if not set, first string in message buffer must be path to error socket
141
142 typedef enum
143 {
144 connection = 1, // connected socket via DNSServiceConnect()
145 reg_record_request, // reg/remove record only valid for connected sockets
146 remove_record_request,
147 enumeration_request,
148 reg_service_request,
149 browse_request,
150 resolve_request,
151 query_request,
152 reconfirm_record_request,
153 add_record_request,
154 update_record_request,
155 setdomain_request
156 } request_op_t;
157
158 typedef enum
159 {
160 enumeration_reply = 64,
161 reg_service_reply,
162 browse_reply,
163 resolve_reply,
164 query_reply,
165 reg_record_reply
166 } reply_op_t;
167
168 typedef struct ipc_msg_hdr_struct ipc_msg_hdr;
169
170 // client stub callback to process message from server and deliver results to
171 // client application
172
173 typedef void (*process_reply_callback)
174 (
175 DNSServiceRef sdr,
176 ipc_msg_hdr *hdr,
177 char *msg
178 );
179
180 // allow 64-bit client to interoperate w/ 32-bit daemon
181 typedef union
182 {
183 void *context;
184 uint32_t ptr64[2];
185 } client_context_t;
186
187 typedef struct ipc_msg_hdr_struct
188 {
189 uint32_t version;
190 uint32_t datalen;
191 uint32_t flags;
192 uint32_t op; // request_op_t or reply_op_t
193 client_context_t client_context; // context passed from client, returned by server in corresponding reply
194 uint32_t reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
195 // socket connected by DNSServiceConnect(). Must be unique in the scope of the connection, such that and
196 // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
197 } ipc_msg_hdr_struct;
198
199 // it is advanced to point to the next field, or the end of the message
200 // routines to write to and extract data from message buffers.
201 // caller responsible for bounds checking.
202 // ptr is the address of the pointer to the start of the field.
203 // it is advanced to point to the next field, or the end of the message
204
205 void put_long(const uint32_t l, char **ptr);
206 uint32_t get_long(char **ptr);
207
208 void put_short(uint16_t s, char **ptr);
209 uint16_t get_short(char **ptr);
210
211 #define put_flags put_long
212 #define get_flags get_long
213
214 #define put_error_code put_long
215 #define get_error_code get_long
216
217 int put_string(const char *str, char **ptr);
218 int get_string(char **ptr, char *buffer, int buflen);
219
220 void put_rdata(const int rdlen, const char *rdata, char **ptr);
221 char *get_rdata(char **ptr, int rdlen); // return value is rdata pointed to by *ptr -
222 // rdata is not copied from buffer.
223
224 void ConvertHeaderBytes(ipc_msg_hdr *hdr);
225
226 #endif // DNSSD_IPC_H