2N/A/*
2N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2N/A */
2N/A/* -*- Mode: C; tab-width: 4 -*-
2N/A *
2N/A * Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
2N/A *
2N/A * Redistribution and use in source and binary forms, with or without
2N/A * modification, are permitted provided that the following conditions are met:
2N/A *
2N/A * 1. Redistributions of source code must retain the above copyright notice,
2N/A * this list of conditions and the following disclaimer.
2N/A * 2. Redistributions in binary form must reproduce the above copyright notice,
2N/A * this list of conditions and the following disclaimer in the documentation
2N/A * and/or other materials provided with the distribution.
2N/A * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
2N/A * contributors may be used to endorse or promote products derived from this
2N/A * software without specific prior written permission.
2N/A *
2N/A * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
2N/A * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
2N/A * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2N/A * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
2N/A * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2N/A * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2N/A * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2N/A * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2N/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2N/A
2N/A Change History (most recent first):
2N/A
2N/A$Log: dnssd_ipc.h,v $
2N/ARevision 1.23 2006/08/14 23:05:53 cheshire
2N/AAdded "tab-width" emacs header line
2N/A
2N/ARevision 1.22 2006/06/28 08:56:26 cheshire
2N/AAdded "_op" to the end of the operation code enum values,
2N/Ato differentiate them from the routines with the same names
2N/A
2N/ARevision 1.21 2005/09/29 06:38:13 herscher
2N/ARemove #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.
2N/A
2N/ARevision 1.20 2005/03/21 00:39:31 shersche
2N/A<rdar://problem/4021486> Fix build warnings on Win32 platform
2N/A
2N/ARevision 1.19 2005/02/02 02:25:22 cheshire
2N/A<rdar://problem/3980388> /var/run/mDNSResponder should be /var/run/mdnsd on Linux
2N/A
2N/ARevision 1.18 2005/01/27 22:57:56 cheshire
2N/AFix compile errors on gcc4
2N/A
2N/ARevision 1.17 2004/11/23 03:39:47 cheshire
2N/ALet interface name/index mapping capability live directly in JNISupport.c,
2N/Ainstead of having to call through to the daemon via IPC to get this information.
2N/A
2N/ARevision 1.16 2004/11/12 03:21:41 rpantos
2N/Ardar://problem/3809541 Add DNSSDMapIfIndexToName, DNSSDMapNameToIfIndex.
2N/A
2N/ARevision 1.15 2004/10/06 02:22:20 cheshire
2N/AChanged MacRoman copyright symbol (should have been UTF-8 in any case :-) to ASCII-compatible "(c)"
2N/A
2N/ARevision 1.14 2004/10/01 22:15:55 rpantos
2N/Ardar://problem/3824265: Replace APSL in client lib with BSD license.
2N/A
2N/ARevision 1.13 2004/09/16 23:14:25 cheshire
2N/AChanges for Windows compatibility
2N/A
2N/ARevision 1.12 2004/09/16 21:46:38 ksekar
2N/A<rdar://problem/3665304> Need SPI for LoginWindow to associate a UID with a Wide Area domain
2N/A
2N/ARevision 1.11 2004/08/10 06:24:56 cheshire
2N/AUse types with precisely defined sizes for 'op' and 'reg_index', for better
2N/Acompatibility if the daemon and the client stub are built using different compilers
2N/A
2N/ARevision 1.10 2004/07/07 17:39:25 shersche
2N/AChange MDNS_SERVERPORT from 5533 to 5354.
2N/A
2N/ARevision 1.9 2004/06/25 00:26:27 rpantos
2N/AChanges to fix the Posix build on Solaris.
2N/A
2N/ARevision 1.8 2004/06/18 04:56:51 rpantos
2N/AAdd layer for platform code
2N/A
2N/ARevision 1.7 2004/06/12 01:08:14 cheshire
2N/AChanges for Windows compatibility
2N/A
2N/ARevision 1.6 2003/08/12 19:56:25 cheshire
2N/AUpdate to APSL 2.0
2N/A
2N/A */
2N/A
2N/A#ifndef DNSSD_IPC_H
2N/A#define DNSSD_IPC_H
2N/A
2N/A#include <paths.h>
2N/A#include "dns_sd.h"
2N/A
2N/A
2N/A//
2N/A// Common cross platform services
2N/A//
2N/A#if defined(WIN32)
2N/A# include <winsock2.h>
2N/A# define dnssd_InvalidSocket INVALID_SOCKET
2N/A# define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
2N/A# define dnssd_EINTR WSAEINTR
2N/A# define dnssd_sock_t SOCKET
2N/A# define dnssd_socklen_t int
2N/A# define dnssd_sockbuf_t const char*
2N/A# define dnssd_close(sock) closesocket(sock)
2N/A# define dnssd_errno() WSAGetLastError()
2N/A# define ssize_t int
2N/A# define getpid _getpid
2N/A#else
2N/A# include <sys/types.h>
2N/A# include <unistd.h>
2N/A# include <sys/un.h>
2N/A# include <string.h>
2N/A# include <stdio.h>
2N/A# include <stdlib.h>
2N/A# include <sys/stat.h>
2N/A# include <sys/socket.h>
2N/A# include <netinet/in.h>
2N/A# define dnssd_InvalidSocket -1
2N/A# define dnssd_EWOULDBLOCK EWOULDBLOCK
2N/A# define dnssd_EINTR EINTR
2N/A# define dnssd_EPIPE EPIPE
2N/A# define dnssd_sock_t int
2N/A# define dnssd_socklen_t unsigned int
2N/A# define dnssd_sockbuf_t const char*
2N/A# define dnssd_close(sock) close(sock)
2N/A# define dnssd_errno() errno
2N/A#endif
2N/A
2N/A#if defined(USE_TCP_LOOPBACK)
2N/A# define AF_DNSSD AF_INET
2N/A# define MDNS_TCP_SERVERADDR "127.0.0.1"
2N/A# define MDNS_TCP_SERVERPORT 5354
2N/A# define LISTENQ 5
2N/A# define dnssd_sockaddr_t struct sockaddr_in
2N/A#else
2N/A# define AF_DNSSD AF_LOCAL
2N/A# ifndef MDNS_UDS_SERVERPATH
2N/A# define MDNS_UDS_SERVERPATH _PATH_SYSVOL "/mDNSResponder"
2N/A# endif
2N/A# define LISTENQ 100
2N/A // longest legal control path length
2N/A# define MAX_CTLPATH 256
2N/A# define dnssd_sockaddr_t struct sockaddr_un
2N/A#endif
2N/A
2N/A
2N/A//#define UDSDEBUG // verbose debug output
2N/A
2N/A// Compatibility workaround
2N/A#ifndef AF_LOCAL
2N/A#define AF_LOCAL AF_UNIX
2N/A#endif
2N/A
2N/A// General UDS constants
2N/A#define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
2N/A
2N/A// IPC data encoding constants and types
2N/A#define VERSION 1
2N/A#define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
2N/A#define IPC_FLAGS_REUSE_SOCKET 2 // set flag if synchronous errors are to be sent via the primary socket
2N/A // (if not set, first string in message buffer must be path to error socket
2N/A
2N/Atypedef enum
2N/A {
2N/A connection = 1, // connected socket via DNSServiceConnect()
2N/A reg_record_request, // reg/remove record only valid for connected sockets
2N/A remove_record_request,
2N/A enumeration_request,
2N/A reg_service_request,
2N/A browse_request,
2N/A resolve_request,
2N/A query_request,
2N/A reconfirm_record_request,
2N/A add_record_request,
2N/A update_record_request,
2N/A setdomain_request
2N/A } request_op_t;
2N/A
2N/Atypedef enum
2N/A {
2N/A enumeration_reply_op = 64,
2N/A reg_service_reply_op,
2N/A browse_reply_op,
2N/A resolve_reply_op,
2N/A query_reply_op,
2N/A reg_record_reply_op
2N/A } reply_op_t;
2N/A
2N/Atypedef struct ipc_msg_hdr_struct ipc_msg_hdr;
2N/A
2N/A// client stub callback to process message from server and deliver results to
2N/A// client application
2N/A
2N/Atypedef void (*process_reply_callback)
2N/A (
2N/A DNSServiceRef sdr,
2N/A ipc_msg_hdr *hdr,
2N/A char *msg
2N/A );
2N/A
2N/A// allow 64-bit client to interoperate w/ 32-bit daemon
2N/Atypedef union
2N/A {
2N/A void *context;
2N/A uint32_t ptr64[2];
2N/A } client_context_t;
2N/A
2N/Atypedef struct ipc_msg_hdr_struct
2N/A {
2N/A uint32_t version;
2N/A uint32_t datalen;
2N/A uint32_t flags;
2N/A uint32_t op; // request_op_t or reply_op_t
2N/A client_context_t client_context; // context passed from client, returned by server in corresponding reply
2N/A uint32_t reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
2N/A // socket connected by DNSServiceConnect(). Must be unique in the scope of the connection, such that and
2N/A // index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
2N/A uint32_t padbytes;
2N/A } ipc_msg_hdr_struct;
2N/A
2N/A// it is advanced to point to the next field, or the end of the message
2N/A// routines to write to and extract data from message buffers.
2N/A// caller responsible for bounds checking.
2N/A// ptr is the address of the pointer to the start of the field.
2N/A// it is advanced to point to the next field, or the end of the message
2N/A
2N/Avoid put_long(const uint32_t l, char **ptr);
2N/Auint32_t get_long(char **ptr);
2N/A
2N/Avoid put_short(uint16_t s, char **ptr);
2N/Auint16_t get_short(char **ptr);
2N/A
2N/A#define put_flags put_long
2N/A#define get_flags get_long
2N/A
2N/A#define put_error_code put_long
2N/A#define get_error_code get_long
2N/A
2N/Aint put_string(const char *str, char **ptr);
2N/Aint get_string(char **ptr, char *buffer, int buflen);
2N/A
2N/Avoid put_rdata(const int rdlen, const unsigned char *rdata, char **ptr);
2N/Achar *get_rdata(char **ptr, int rdlen); // return value is rdata pointed to by *ptr -
2N/A // rdata is not copied from buffer.
2N/A
2N/Avoid ConvertHeaderBytes(ipc_msg_hdr *hdr);
2N/A
2N/A#endif // DNSSD_IPC_H