Kaydet (Commit) 03fd0a02 authored tarafından Siqi LIU's avatar Siqi LIU Kaydeden (comit) siqi

build mDNSResponder on Windows within LibO

Change-Id: I6973be21f6f4009d6934220f978e9369fef67ede
üst 61a2c9fb
......@@ -562,6 +562,23 @@ $(eval $(call gb_Library_add_exception_objects,sd,\
sd/source/ui/remotecontrol/DiscoveryService \
))
ifeq ($(OS),WNT)
$(eval $(call gb_Library_add_exception_objects,sd,\
sd/source/ui/remotecontrol/WINNetworkService \
))
$(eval $(call gb_Library_add_cobjects,sd,\
sd/source/ui/remotecontrol/mDNSResponder/DebugServices \
sd/source/ui/remotecontrol/mDNSResponder/dnssd_clientlib \
sd/source/ui/remotecontrol/mDNSResponder/dnssd_clientstub \
sd/source/ui/remotecontrol/mDNSResponder/dnssd_ipc \
sd/source/ui/remotecontrol/mDNSResponder/GenLinkedList \
sd/source/ui/remotecontrol/mDNSResponder/dllmain \
))
endif
endif
$(eval $(call gb_Library_add_defs,sd,\
......
......@@ -95,7 +95,7 @@ static void create_services(AvahiClient *c) {
if (avahi_entry_group_is_empty(group)) {
fprintf(stderr, "Adding service '%s'\n", avahiService->getName().c_str());
snprintf(r, sizeof(r), "random=%i", rand());
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), avahiService->getName().c_str(), "_impressremote._tcp", NULL, NULL, 1599, "local", r, NULL)) < 0) {
if ((ret = avahi_entry_group_add_service(group, AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC, static_cast<AvahiPublishFlags>(0), avahiService->getName().c_str(), kREG_TYPE, NULL, NULL, 1599, "local", r, NULL)) < 0) {
if (ret == AVAHI_ERR_COLLISION){
/* A service name collision with a local service happened. Let's
......
......@@ -27,6 +27,8 @@
#include <winsock2.h>
#include <ws2tcpip.h>
#include "WINNetworkService.hxx"
typedef int socklen_t;
#else
#include <unistd.h>
......@@ -70,6 +72,10 @@ DiscoveryService::DiscoveryService()
zService = new AvahiNetworkService(hostname);
#endif
#ifdef WIN32
zService = new WINNetworkService();
#endif
if (zService)
zService->setup();
......@@ -111,9 +117,9 @@ DiscoveryService::DiscoveryService()
DiscoveryService::~DiscoveryService()
{
#ifdef WNT
closesocket( mSocket );
closesocket( mSocket );
#else
close( mSocket );
close( mSocket );
#endif
if (zService)
......
......@@ -17,7 +17,7 @@
- (void) publishImpressRemoteServiceOnLocalNetworkWithName:(NSString *)sName
{
netService = [[NSNetService alloc] initWithDomain:@"local" type:@"_impressremote._tcp" name:sName port:1599];
netService = [[NSNetService alloc] initWithDomain:@"local" type:@kREG_TYPE name:sName port:1599];
if (netService != nil)
{
......
#include <string>
#include <iostream>
#include "WINNetworkService.hxx"
#include "mDNSResponder/dns_sd.h"
void sd::WINNetworkService::setup()
{
DNSServiceErrorType err = DNSServiceRegister(&client, 0, 0, NULL, kREG_TYPE, NULL, NULL, 1599, 1, "", NULL, this );
if ( err == 0 ) {
SAL_INFO("sd", "Windows bonjour service setup");
} // Fail silently otherwise
}
void sd::WINNetworkService::clear()
{
DNSServiceRefDeallocate(client);
SAL_INFO("sd", "Windows mDNSResponder removed");
}
\ No newline at end of file
#ifndef WINNETWORKSERVICE_HXX
#define WINNETWORKSERVICE_HXX
#include <string>
#undef WB_LEFT
#undef WB_RIGHT
#include "mDNSResponder/dns_sd.h"
#include "ZeroconfService.hxx"
namespace sd{
class WINNetworkService : public ZeroconfService
{
private:
DNSServiceRef client;
public:
WINNetworkService(const std::string& aname = "", unsigned int aport = 1599)
: ZeroconfService(aname, aport), client(0) {}
virtual ~WINNetworkService(){}
void clear();
void setup();
};
}
#endif
\ No newline at end of file
......@@ -19,6 +19,8 @@
#define PORT_DISCOVERY 1598
#define BUFFER_SIZE 200
#define kREG_TYPE "_impressremote._tcp"
#define CHARSET RTL_TEXTENCODING_UTF8
struct sockaddr_in;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
File: GenLinkedList.c
Contains: implementation of generic linked lists.
Version: 1.0
Tabs: 4 spaces
*/
#include "GenLinkedList.h"
// Return the link pointer contained within element e at offset o.
#define GETLINK( e, o) ( *(void**)((char*) (e) + (o)) )
// Assign the link pointer l to element e at offset o.
#define ASSIGNLINK( e, l, o) ( *((void**)((char*) (e) + (o))) = (l))
// GenLinkedList /////////////////////////////////////////////////////////////
void InitLinkedList( GenLinkedList *pList, size_t linkOffset)
/* Initialize the block of memory pointed to by pList as a linked list. */
{
pList->Head = NULL;
pList->Tail = NULL;
pList->LinkOffset = linkOffset;
}
void AddToTail( GenLinkedList *pList, void *elem)
/* Add a linked list element to the tail of the list. */
{
if ( pList->Tail) {
ASSIGNLINK( pList->Tail, elem, pList->LinkOffset);
} else
pList->Head = elem;
ASSIGNLINK( elem, NULL, pList->LinkOffset);
pList->Tail = elem;
}
void AddToHead( GenLinkedList *pList, void *elem)
/* Add a linked list element to the head of the list. */
{
ASSIGNLINK( elem, pList->Head, pList->LinkOffset);
if ( pList->Tail == NULL)
pList->Tail = elem;
pList->Head = elem;
}
int RemoveFromList( GenLinkedList *pList, void *elem)
/* Remove a linked list element from the list. Return 0 if it was not found. */
/* If the element is removed, its link will be set to NULL. */
{
void *iElem, *lastElem;
for ( iElem = pList->Head, lastElem = NULL; iElem; iElem = GETLINK( iElem, pList->LinkOffset)) {
if ( iElem == elem) {
if ( lastElem) { // somewhere past the head
ASSIGNLINK( lastElem, GETLINK( elem, pList->LinkOffset), pList->LinkOffset);
} else { // at the head
pList->Head = GETLINK( elem, pList->LinkOffset);
}
if ( pList->Tail == elem)
pList->Tail = lastElem ? lastElem : NULL;
ASSIGNLINK( elem, NULL, pList->LinkOffset); // maybe catch a stale reference bug.
return 1;
}
lastElem = iElem;
}
return 0;
}
int ReplaceElem( GenLinkedList *pList, void *elemInList, void *newElem)
/* Replace an element in the list with a new element, in the same position. */
{
void *iElem, *lastElem;
if ( elemInList == NULL || newElem == NULL)
return 0;
for ( iElem = pList->Head, lastElem = NULL; iElem; iElem = GETLINK( iElem, pList->LinkOffset))
{
if ( iElem == elemInList)
{
ASSIGNLINK( newElem, GETLINK( elemInList, pList->LinkOffset), pList->LinkOffset);
if ( lastElem) // somewhere past the head
{
ASSIGNLINK( lastElem, newElem, pList->LinkOffset);
}
else // at the head
{
pList->Head = newElem;
}
if ( pList->Tail == elemInList)
pList->Tail = newElem;
return 1;
}
lastElem = iElem;
}
return 0;
}
// GenDoubleLinkedList /////////////////////////////////////////////////////////
void InitDoubleLinkedList( GenDoubleLinkedList *pList, size_t fwdLinkOffset,
size_t backLinkOffset)
/* Initialize the block of memory pointed to by pList as a double linked list. */
{
pList->Head = NULL;
pList->Tail = NULL;
pList->FwdLinkOffset = fwdLinkOffset;
pList->BackLinkOffset = backLinkOffset;
}
void DLLAddToHead( GenDoubleLinkedList *pList, void *elem)
/* Add a linked list element to the head of the list. */
{
void *pNext;
pNext = pList->Head;
// fix up the forward links
ASSIGNLINK( elem, pList->Head, pList->FwdLinkOffset);
pList->Head = elem;
// fix up the backward links
if ( pNext) {
ASSIGNLINK( pNext, elem, pList->BackLinkOffset);
} else
pList->Tail = elem;
ASSIGNLINK( elem, NULL, pList->BackLinkOffset);
}
void DLLRemoveFromList( GenDoubleLinkedList *pList, void *elem)
/* Remove a linked list element from the list. */
/* When the element is removed, its link will be set to NULL. */
{
void *pNext, *pPrev;
pNext = GETLINK( elem, pList->FwdLinkOffset);
pPrev = GETLINK( elem, pList->BackLinkOffset);
// fix up the forward links
if ( pPrev)
ASSIGNLINK( pPrev, pNext, pList->FwdLinkOffset);
else
pList->Head = pNext;
// fix up the backward links
if ( pNext)
ASSIGNLINK( pNext, pPrev, pList->BackLinkOffset);
else
pList->Tail = pPrev;
ASSIGNLINK( elem, NULL, pList->FwdLinkOffset);
ASSIGNLINK( elem, NULL, pList->BackLinkOffset);
}
// GenLinkedOffsetList /////////////////////////////////////////////////////
// Extract the Next offset from element
#define GETOFFSET( e, o) ( *(size_t*)((char*) (e) + (o)) )
static void AssignOffsetLink( void *elem, void *link, size_t linkOffset);
static void AssignOffsetLink( void *elem, void *link, size_t linkOffset)
// Assign link to elem as an offset from elem. Assign 0 to elem if link is NULL.
{
GETOFFSET( elem, linkOffset) = link ? (size_t) link - (size_t) elem : 0;
}
void *GetHeadPtr( GenLinkedOffsetList *pList)
/* Return a pointer to the head element of a list, or NULL if none. */
{
return pList->Head ? ( (char*) (pList) + pList->Head) : NULL;
}
void *GetTailPtr( GenLinkedOffsetList *pList)
/* Return a pointer to the tail element of a list, or NULL if none. */
{
return pList->Tail ? ( (char*) (pList) + pList->Tail) : NULL;
}
void *GetOffsetLink( GenLinkedOffsetList *pList, void *elem)
/* Return the link pointer contained within element e for pList, or NULL if it is 0. */
{
size_t nextOffset;
nextOffset = GETOFFSET( elem, pList->LinkOffset);
return nextOffset ? (char*) elem + nextOffset : NULL;
}
void InitLinkedOffsetList( GenLinkedOffsetList *pList, size_t linkOffset)
/* Initialize the block of memory pointed to by pList as a linked list. */
{
pList->Head = 0;
pList->Tail = 0;
pList->LinkOffset = linkOffset;
}
void OffsetAddToTail( GenLinkedOffsetList *pList, void *elem)
/* Add a linked list element to the tail of the list. */
{
if ( pList->Tail) {
AssignOffsetLink( GetTailPtr( pList), elem, pList->LinkOffset);
} else
pList->Head = (size_t) elem - (size_t) pList;
AssignOffsetLink( elem, NULL, pList->LinkOffset);
pList->Tail = (size_t) elem - (size_t) pList;
}
void OffsetAddToHead( GenLinkedOffsetList *pList, void *elem)
/* Add a linked list element to the head of the list. */
{
AssignOffsetLink( elem, GetHeadPtr( pList), pList->LinkOffset);
if ( pList->Tail == 0)
pList->Tail = (size_t) elem - (size_t) pList;
pList->Head = (size_t) elem - (size_t) pList;
}
int OffsetRemoveFromList( GenLinkedOffsetList *pList, void *elem)
/* Remove a linked list element from the list. Return 0 if it was not found. */
/* If the element is removed, its link will be set to NULL. */
{
void *iElem, *lastElem;
for ( iElem = GetHeadPtr( pList), lastElem = NULL; iElem;
iElem = GetOffsetLink( pList, iElem))
{
if ( iElem == elem) {
if ( lastElem) { // somewhere past the head
AssignOffsetLink( lastElem, GetOffsetLink( pList, elem), pList->LinkOffset);
} else { // at the head
iElem = GetOffsetLink( pList, elem);
pList->Head = iElem ? (size_t) iElem - (size_t) pList : 0;
}
if ( GetTailPtr( pList) == elem)
pList->Tail = lastElem ? (size_t) lastElem - (size_t) pList : 0;
AssignOffsetLink( elem, NULL, pList->LinkOffset); // maybe catch a stale reference bug.
return 1;
}
lastElem = iElem;
}
return 0;
}
int OffsetReplaceElem( GenLinkedOffsetList *pList, void *elemInList, void *newElem)
/* Replace an element in the list with a new element, in the same position. */
{
void *iElem, *lastElem;
if ( elemInList == NULL || newElem == NULL)
return 0;
for ( iElem = GetHeadPtr( pList), lastElem = NULL; iElem;
iElem = GetOffsetLink( pList, iElem))
{
if ( iElem == elemInList)
{
AssignOffsetLink( newElem, GetOffsetLink( pList, elemInList), pList->LinkOffset);
if ( lastElem) // somewhere past the head
{
AssignOffsetLink( lastElem, newElem, pList->LinkOffset);
}
else // at the head
{
pList->Head = (size_t) newElem - (size_t) pList;
}
if ( GetTailPtr( pList) == elemInList)
pList->Tail = (size_t) newElem - (size_t) pList;
return 1;
}
lastElem = iElem;
}
return 0;
}
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __GenLinkedList__
#define __GenLinkedList__
#include <stddef.h>
struct GenLinkedList
{
void *Head,
*Tail;
size_t LinkOffset;
};
typedef struct GenLinkedList GenLinkedList;
void InitLinkedList( GenLinkedList *pList, size_t linkOffset);
void AddToHead( GenLinkedList *pList, void *elem);
void AddToTail( GenLinkedList *pList, void *elem);
int RemoveFromList( GenLinkedList *pList, void *elem);
int ReplaceElem( GenLinkedList *pList, void *elemInList, void *newElem);
struct GenDoubleLinkedList
{
void *Head,
*Tail;
size_t FwdLinkOffset,
BackLinkOffset;
};
typedef struct GenDoubleLinkedList GenDoubleLinkedList;
void InitDoubleLinkedList( GenDoubleLinkedList *pList, size_t fwdLinkOffset,
size_t backLinkOffset);
void DLLAddToHead( GenDoubleLinkedList *pList, void *elem);
void DLLRemoveFromList( GenDoubleLinkedList *pList, void *elem);
/* A GenLinkedOffsetList is like a GenLinkedList that stores the *Next field as a signed */
/* offset from the address of the beginning of the element, rather than as a pointer. */
struct GenLinkedOffsetList
{
size_t Head,
Tail;
size_t LinkOffset;
};
typedef struct GenLinkedOffsetList GenLinkedOffsetList;
void InitLinkedOffsetList( GenLinkedOffsetList *pList, size_t linkOffset);
void *GetHeadPtr( GenLinkedOffsetList *pList);
void *GetTailPtr( GenLinkedOffsetList *pList);
void *GetOffsetLink( GenLinkedOffsetList *pList, void *elem);
void OffsetAddToHead( GenLinkedOffsetList *pList, void *elem);
void OffsetAddToTail( GenLinkedOffsetList *pList, void *elem);
int OffsetRemoveFromList( GenLinkedOffsetList *pList, void *elem);
int OffsetReplaceElem( GenLinkedOffsetList *pList, void *elemInList, void *newElem);
#endif // __GenLinkedList__
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// #include <windows.h>
#include <DebugServices.h>
#include <stdlib.h>
BOOL APIENTRY DllMain( HANDLE inModule, DWORD inReason, LPVOID inReserved )
{
(void) inModule;
(void) inReserved;
switch( inReason )
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return( TRUE );
}
BOOL
IsSystemServiceDisabled()
{
ENUM_SERVICE_STATUS * lpService = NULL;
SC_HANDLE sc;
BOOL ret = FALSE;
BOOL ok;
DWORD bytesNeeded = 0;
DWORD srvCount;
DWORD resumeHandle = 0;
DWORD srvType;
DWORD srvState;
DWORD dwBytes = 0;
DWORD i;
OSStatus err;
sc = OpenSCManager( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE );
err = translate_errno( sc, GetLastError(), kUnknownErr );
require_noerr( err, exit );
srvType = SERVICE_WIN32;
srvState = SERVICE_STATE_ALL;
for ( ;; )
{
// Call EnumServicesStatus using the handle returned by OpenSCManager
ok = EnumServicesStatus ( sc, srvType, srvState, lpService, dwBytes, &bytesNeeded, &srvCount, &resumeHandle );
if ( ok || ( GetLastError() != ERROR_MORE_DATA ) )
{
break;
}
if ( lpService )
{
free( lpService );
}
dwBytes = bytesNeeded;
lpService = ( ENUM_SERVICE_STATUS* ) malloc( dwBytes );
require_action( lpService, exit, ret = FALSE );
}
err = translate_errno( ok, GetLastError(), kUnknownErr );
require_noerr( err, exit );
for ( i = 0; i < srvCount; i++ )
{
if ( strcmp( lpService[i].lpServiceName, "Bonjour Service" ) == 0 )
{
if ( ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_PAUSED ) || ( lpService[i].ServiceStatus.dwCurrentState == SERVICE_STOPPED ) )
{
ret = TRUE;
}
break;
}
}
exit:
if ( lpService )
{
free( lpService );
}
if ( sc )
{
CloseServiceHandle ( sc );
}
return ret;
}
This diff is collapsed.
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "dnssd_ipc.h"
#if defined(_WIN32)
char *win32_strerror(int inErrorCode)
{
static char buffer[1024];
DWORD n;
memset(buffer, 0, sizeof(buffer));
n = FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
(DWORD) inErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
buffer,
sizeof(buffer),
NULL);
if (n > 0)
{
// Remove any trailing CR's or LF's since some messages have them.
while ((n > 0) && isspace(((unsigned char *) buffer)[n - 1]))
buffer[--n] = '\0';
}
return buffer;
}
#endif
void put_uint32(const uint32_t l, char **ptr)
{
(*ptr)[0] = (char)((l >> 24) & 0xFF);
(*ptr)[1] = (char)((l >> 16) & 0xFF);
(*ptr)[2] = (char)((l >> 8) & 0xFF);
(*ptr)[3] = (char)((l ) & 0xFF);
*ptr += sizeof(uint32_t);
}
uint32_t get_uint32(const char **ptr, const char *end)
{
if (!*ptr || *ptr + sizeof(uint32_t) > end)
{
*ptr = NULL;
return(0);
}
else
{
uint8_t *p = (uint8_t*) *ptr;
*ptr += sizeof(uint32_t);
return((uint32_t) ((uint32_t)p[0] << 24 | (uint32_t)p[1] << 16 | (uint32_t)p[2] << 8 | p[3]));
}
}
void put_uint16(uint16_t s, char **ptr)
{
(*ptr)[0] = (char)((s >> 8) & 0xFF);
(*ptr)[1] = (char)((s ) & 0xFF);
*ptr += sizeof(uint16_t);
}
uint16_t get_uint16(const char **ptr, const char *end)
{
if (!*ptr || *ptr + sizeof(uint16_t) > end)
{
*ptr = NULL;
return(0);
}
else
{
uint8_t *p = (uint8_t*) *ptr;
*ptr += sizeof(uint16_t);
return((uint16_t) ((uint16_t)p[0] << 8 | p[1]));
}
}
int put_string(const char *str, char **ptr)
{
if (!str) str = "";
strcpy(*ptr, str);
*ptr += strlen(str) + 1;
return 0;
}
int get_string(const char **ptr, const char *const end, char *buffer, int buflen)
{
if (!*ptr)
{
*buffer = 0;
return(-1);
}
else
{
char *lim = buffer + buflen; // Calculate limit
while (*ptr < end && buffer < lim)
{
char c = *buffer++ = *(*ptr)++;
if (c == 0) return(0); // Success
}
if (buffer == lim) buffer--;
*buffer = 0; // Failed, so terminate string,
*ptr = NULL; // clear pointer,
return(-1); // and return failure indication
}
}
void put_rdata(const int rdlen, const unsigned char *rdata, char **ptr)
{
memcpy(*ptr, rdata, rdlen);
*ptr += rdlen;
}
const char *get_rdata(const char **ptr, const char *end, int rdlen)
{
if (!*ptr || *ptr + rdlen > end)
{
*ptr = NULL;
return(0);
}
else
{
const char *rd = *ptr;
*ptr += rdlen;
return rd;
}
}
void ConvertHeaderBytes(ipc_msg_hdr *hdr)
{
hdr->version = htonl(hdr->version);
hdr->datalen = htonl(hdr->datalen);
hdr->ipc_flags = htonl(hdr->ipc_flags);
hdr->op = htonl(hdr->op );
hdr->reg_index = htonl(hdr->reg_index);
}
/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2003-2004, Apple Computer, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef DNSSD_IPC_H
#define DNSSD_IPC_H
//
// Common cross platform services
//
#if defined(WIN32)
# include <winsock2.h>
#endif
#include "dns_sd.h"
#if defined(WIN32)
# define dnssd_InvalidSocket INVALID_SOCKET
# define dnssd_SocketValid(s) ((s) != INVALID_SOCKET)
# define dnssd_EWOULDBLOCK WSAEWOULDBLOCK
# define dnssd_EINTR WSAEINTR
# define dnssd_ECONNRESET WSAECONNRESET
# define dnssd_sock_t SOCKET
# define dnssd_socklen_t int
# define dnssd_close(sock) closesocket(sock)
# define dnssd_errno WSAGetLastError()
# define dnssd_strerror(X) win32_strerror(X)
# define ssize_t int
# define getpid _getpid
# define unlink _unlink
extern char *win32_strerror(int inErrorCode);
#else
# include <sys/types.h>
# include <unistd.h>
# include <sys/un.h>
# include <string.h>
# include <stdio.h>
# include <stdlib.h>
# include <sys/stat.h>
# include <sys/socket.h>
# include <netinet/in.h>
# include <arpa/inet.h>
# define dnssd_InvalidSocket -1
# define dnssd_SocketValid(s) ((s) >= 0)
# define dnssd_EWOULDBLOCK EWOULDBLOCK
# define dnssd_EINTR EINTR
# define dnssd_ECONNRESET ECONNRESET
# define dnssd_EPIPE EPIPE
# define dnssd_sock_t int
# define dnssd_socklen_t unsigned int
# define dnssd_close(sock) close(sock)
# define dnssd_errno errno
# define dnssd_strerror(X) strerror(X)
#endif
#if defined(USE_TCP_LOOPBACK)
# define AF_DNSSD AF_INET
# define MDNS_TCP_SERVERADDR "127.0.0.1"
# define MDNS_TCP_SERVERPORT 5354
# define LISTENQ 5
# define dnssd_sockaddr_t struct sockaddr_in
#else
# define AF_DNSSD AF_LOCAL
# ifndef MDNS_UDS_SERVERPATH
# define MDNS_UDS_SERVERPATH "/var/run/mDNSResponder"
# endif
# define LISTENQ 100
// longest legal control path length
# define MAX_CTLPATH 256
# define dnssd_sockaddr_t struct sockaddr_un
#endif
// Compatibility workaround
#ifndef AF_LOCAL
#define AF_LOCAL AF_UNIX
#endif
// General UDS constants
#define TXT_RECORD_INDEX ((uint32_t)(-1)) // record index for default text record
// IPC data encoding constants and types
#define VERSION 1
#define IPC_FLAGS_NOREPLY 1 // set flag if no asynchronous replies are to be sent to client
// Structure packing macro. If we're not using GNUC, it's not fatal. Most compilers naturally pack the on-the-wire
// structures correctly anyway, so a plain "struct" is usually fine. In the event that structures are not packed
// correctly, our compile-time assertion checks will catch it and prevent inadvertent generation of non-working code.
#ifndef packedstruct
#if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 9)))
#define packedstruct struct __attribute__((__packed__))
#define packedunion union __attribute__((__packed__))
#else
#define packedstruct struct
#define packedunion union
#endif
#endif
typedef enum
{
request_op_none = 0, // No request yet received on this connection
connection_request = 1, // connected socket via DNSServiceConnect()
reg_record_request, // reg/remove record only valid for connected sockets
remove_record_request,
enumeration_request,
reg_service_request,
browse_request,
resolve_request,
query_request,
reconfirm_record_request,
add_record_request,
update_record_request,
setdomain_request, // Up to here is in Tiger and B4W 1.0.3
getproperty_request, // New in B4W 1.0.4
port_mapping_request, // New in Leopard and B4W 2.0
addrinfo_request,
send_bpf, // New in SL
release_request,
cancel_request = 63
} request_op_t;
typedef enum
{
enumeration_reply_op = 64,
reg_service_reply_op,
browse_reply_op,
resolve_reply_op,
query_reply_op,
reg_record_reply_op, // Up to here is in Tiger and B4W 1.0.3
getproperty_reply_op, // New in B4W 1.0.4
port_mapping_reply_op, // New in Leopard and B4W 2.0
addrinfo_reply_op
} reply_op_t;
#if defined(_WIN64)
# pragma pack(push,4)
#endif
// Define context object big enough to hold a 64-bit pointer,
// to accomodate 64-bit clients communicating with 32-bit daemon.
// There's no reason for the daemon to ever be a 64-bit process, but its clients might be
typedef packedunion
{
void *context;
uint32_t u32[2];
} client_context_t;
typedef packedstruct
{
uint32_t version;
uint32_t datalen;
uint32_t ipc_flags;
uint32_t op; // request_op_t or reply_op_t
client_context_t client_context; // context passed from client, returned by server in corresponding reply
uint32_t reg_index; // identifier for a record registered via DNSServiceRegisterRecord() on a
// socket connected by DNSServiceCreateConnection(). Must be unique in the scope of the connection, such that and
// index/socket pair uniquely identifies a record. (Used to select records for removal by DNSServiceRemoveRecord())
} ipc_msg_hdr;
#if defined(_WIN64)
# pragma pack(pop)
#endif
// routines to write to and extract data from message buffers.
// caller responsible for bounds checking.
// ptr is the address of the pointer to the start of the field.
// it is advanced to point to the next field, or the end of the message
void put_uint32(const uint32_t l, char **ptr);
uint32_t get_uint32(const char **ptr, const char *end);
void put_uint16(uint16_t s, char **ptr);
uint16_t get_uint16(const char **ptr, const char *end);
#define put_flags put_uint32
#define get_flags get_uint32
#define put_error_code put_uint32
#define get_error_code get_uint32
int put_string(const char *str, char **ptr);
int get_string(const char **ptr, const char *const end, char *buffer, int buflen);
void put_rdata(const int rdlen, const unsigned char *rdata, char **ptr);
const char *get_rdata(const char **ptr, const char *end, int rdlen); // return value is rdata pointed to by *ptr -
// rdata is not copied from buffer.
void ConvertHeaderBytes(ipc_msg_hdr *hdr);
struct CompileTimeAssertionChecks_dnssd_ipc
{
// Check that the compiler generated our on-the-wire packet format structure definitions
// properly packed, without adding padding bytes to align fields on 32-bit or 64-bit boundaries.
char assert0[(sizeof(client_context_t) == 8) ? 1 : -1];
char assert1[(sizeof(ipc_msg_hdr) == 28) ? 1 : -1];
};
#endif // DNSSD_IPC_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment