2 * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
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.
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.
27 Change History (most recent first):
30 Revision 1.20 2005/03/21 00:39:31 shersche
31 <rdar://problem/4021486> Fix build warnings on Win32 platform
33 Revision 1.19 2005/02/02 02:25:22 cheshire
34 <rdar://problem/3980388> /var/run/mDNSResponder should be /var/run/mdnsd on Linux
36 Revision 1.18 2005/01/27 22:57:56 cheshire
37 Fix compile errors on gcc4
39 Revision 1.17 2004/11/23 03:39:47 cheshire
40 Let interface name/index mapping capability live directly in JNISupport.c,
41 instead of having to call through to the daemon via IPC to get this information.
43 Revision 1.16 2004/11/12 03:21:41 rpantos
44 rdar://problem/3809541 Add DNSSDMapIfIndexToName, DNSSDMapNameToIfIndex.
46 Revision 1.15 2004/10/06 02:22:20 cheshire
47 Changed MacRoman copyright symbol (should have been UTF-8 in any case :-) to ASCII-compatible "(c)"
49 Revision 1.14 2004/10/01 22:15:55 rpantos
50 rdar://problem/3824265: Replace APSL in client lib with BSD license.
52 Revision 1.13 2004/09/16 23:14:25 cheshire
53 Changes for Windows compatibility
55 Revision 1.12 2004/09/16 21:46:38 ksekar
56 <rdar://problem/3665304> Need SPI for LoginWindow to associate a UID with a Wide Area domain
58 Revision 1.11 2004/08/10 06:24:56 cheshire
59 Use types with precisely defined sizes for 'op' and 'reg_index', for better
60 compatibility if the daemon and the client stub are built using different compilers
62 Revision 1.10 2004/07/07 17:39:25 shersche
63 Change MDNS_SERVERPORT from 5533 to 5354.
65 Revision 1.9 2004/06/25 00:26:27 rpantos
66 Changes to fix the Posix build on Solaris.
68 Revision 1.8 2004/06/18 04:56:51 rpantos
69 Add layer for platform code
71 Revision 1.7 2004/06/12 01:08:14 cheshire
72 Changes for Windows compatibility
74 Revision 1.6 2003/08/12 19:56:25 cheshire
86 // Common cross platform services
89 # include <winsock2.h>
90 # define dnssd_InvalidSocket INVALID_SOCKET
91 # define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
92 # define dnssd_EINTR WSAEINTR
93 # define MSG_WAITALL 0
94 # define dnssd_sock_t SOCKET
95 # define dnssd_socklen_t int
96 # define dnssd_sockbuf_t const char*
97 # define dnssd_close(sock) closesocket(sock)
98 # define dnssd_errno() WSAGetLastError()
100 # define getpid _getpid
102 # include <sys/types.h>
108 # include <sys/stat.h>
109 # include <sys/socket.h>
110 # include <netinet/in.h>
111 # define dnssd_InvalidSocket -1
112 # define dnssd_EWOULDBLOCK EWOULDBLOCK
113 # define dnssd_EINTR EINTR
114 # define dnssd_EPIPE EPIPE
115 # define dnssd_sock_t int
116 # define dnssd_socklen_t unsigned int
117 # define dnssd_sockbuf_t const char*
118 # define dnssd_close(sock) close(sock)
119 # define dnssd_errno() errno
122 #if defined(USE_TCP_LOOPBACK)
123 # define AF_DNSSD AF_INET
124 # define MDNS_TCP_SERVERADDR "127.0.0.1"
125 # define MDNS_TCP_SERVERPORT 5354
127 # define dnssd_sockaddr_t struct sockaddr_in
129 # define AF_DNSSD AF_LOCAL
130 # ifndef MDNS_UDS_SERVERPATH
131 # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
134 // longest legal control path length
135 # define MAX_CTLPATH 256
136 # define dnssd_sockaddr_t struct sockaddr_un
140 //#define UDSDEBUG // verbose debug output
142 // Compatibility workaround
144 #define AF_LOCAL AF_UNIX
147 // General UDS constants
148 #define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
150 // IPC data encoding constants and types
152 #define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
153 #define IPC_FLAGS_REUSE_SOCKET 2 // set flag if synchronous errors are to be sent via the primary socket
154 // (if not set, first string in message buffer must be path to error socket
158 connection
= 1, // connected socket via DNSServiceConnect()
159 reg_record_request
, // reg/remove record only valid for connected sockets
160 remove_record_request
,
166 reconfirm_record_request
,
168 update_record_request
,
174 enumeration_reply
= 64,
182 typedef struct ipc_msg_hdr_struct ipc_msg_hdr
;
184 // client stub callback to process message from server and deliver results to
185 // client application
187 typedef void (*process_reply_callback
)
194 // allow 64-bit client to interoperate w/ 32-bit daemon
201 typedef struct ipc_msg_hdr_struct
206 uint32_t op
; // request_op_t or reply_op_t
207 client_context_t client_context
; // context passed from client, returned by server in corresponding reply
208 uint32_t reg_index
; // identifier for a record registered via DNSServiceRegisterRecord() on a
209 // socket connected by DNSServiceConnect(). Must be unique in the scope of the connection, such that and
210 // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
211 } ipc_msg_hdr_struct
;
213 // it is advanced to point to the next field, or the end of the message
214 // routines to write to and extract data from message buffers.
215 // caller responsible for bounds checking.
216 // ptr is the address of the pointer to the start of the field.
217 // it is advanced to point to the next field, or the end of the message
219 void put_long(const uint32_t l
, char **ptr
);
220 uint32_t get_long(char **ptr
);
222 void put_short(uint16_t s
, char **ptr
);
223 uint16_t get_short(char **ptr
);
225 #define put_flags put_long
226 #define get_flags get_long
228 #define put_error_code put_long
229 #define get_error_code get_long
231 int put_string(const char *str
, char **ptr
);
232 int get_string(char **ptr
, char *buffer
, int buflen
);
234 void put_rdata(const int rdlen
, const unsigned char *rdata
, char **ptr
);
235 char *get_rdata(char **ptr
, int rdlen
); // return value is rdata pointed to by *ptr -
236 // rdata is not copied from buffer.
238 void ConvertHeaderBytes(ipc_msg_hdr
*hdr
);
240 #endif // DNSSD_IPC_H