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