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.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.
34 Revision 1.16 2004/11/12 03:21:41 rpantos
35 rdar://problem/3809541 Add DNSSDMapIfIndexToName, DNSSDMapNameToIfIndex.
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)"
40 Revision 1.14 2004/10/01 22:15:55 rpantos
41 rdar://problem/3824265: Replace APSL in client lib with BSD license.
43 Revision 1.13 2004/09/16 23:14:25 cheshire
44 Changes for Windows compatibility
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
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
53 Revision 1.10 2004/07/07 17:39:25 shersche
54 Change MDNS_SERVERPORT from 5533 to 5354.
56 Revision 1.9 2004/06/25 00:26:27 rpantos
57 Changes to fix the Posix build on Solaris.
59 Revision 1.8 2004/06/18 04:56:51 rpantos
60 Add layer for platform code
62 Revision 1.7 2004/06/12 01:08:14 cheshire
63 Changes for Windows compatibility
65 Revision 1.6 2003/08/12 19:56:25 cheshire
77 // Common cross platform services
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()
90 # define getpid _getpid
92 # include <sys/types.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
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
115 # define dnssd_sockaddr_t struct sockaddr_in
117 # define AF_DNSSD AF_LOCAL
118 # define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
120 // longest legal control path length
121 # define MAX_CTLPATH 256
122 # define dnssd_sockaddr_t struct sockaddr_un
126 //#define UDSDEBUG // verbose debug output
128 // Compatibility workaround
130 #define AF_LOCAL AF_UNIX
133 // General UDS constants
134 #define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
136 // IPC data encoding constants and types
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
144 connection
= 1, // connected socket via DNSServiceConnect()
145 reg_record_request
, // reg/remove record only valid for connected sockets
146 remove_record_request
,
152 reconfirm_record_request
,
154 update_record_request
,
160 enumeration_reply
= 64,
168 typedef struct ipc_msg_hdr_struct ipc_msg_hdr
;
170 // client stub callback to process message from server and deliver results to
171 // client application
173 typedef void (*process_reply_callback
)
180 // allow 64-bit client to interoperate w/ 32-bit daemon
187 typedef struct ipc_msg_hdr_struct
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
;
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
205 void put_long(const uint32_t l
, char **ptr
);
206 uint32_t get_long(char **ptr
);
208 void put_short(uint16_t s
, char **ptr
);
209 uint16_t get_short(char **ptr
);
211 #define put_flags put_long
212 #define get_flags get_long
214 #define put_error_code put_long
215 #define get_error_code get_long
217 int put_string(const char *str
, char **ptr
);
218 int get_string(char **ptr
, char *buffer
, int buflen
);
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.
224 void ConvertHeaderBytes(ipc_msg_hdr
*hdr
);
226 #endif // DNSSD_IPC_H