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