147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt/* -*- Mode: C; tab-width: 4 -*- 247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * 347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved. 447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * 547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * Licensed under the Apache License, Version 2.0 (the "License"); 647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * you may not use this file except in compliance with the License. 747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * You may obtain a copy of the License at 847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * 947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * http://www.apache.org/licenses/LICENSE-2.0 1047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * 1147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * Unless required by applicable law or agreed to in writing, software 1247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * distributed under the License is distributed on an "AS IS" BASIS, 1347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * See the License for the specific language governing permissions and 1547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt * limitations under the License. 1647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt */ 1747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 1847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#ifndef __mDNSPlatformPosix_h 1947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#define __mDNSPlatformPosix_h 2047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 2147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#include <signal.h> 2247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#include <sys/time.h> 23dd52342e088715929196886494c5055f9186d5c3Robert Greenwalt#ifdef __ANDROID__ 24dd52342e088715929196886494c5055f9186d5c3Robert Greenwalt#include <sys/select.h> 25dd52342e088715929196886494c5055f9186d5c3Robert Greenwalt#endif 2647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 2747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#ifdef __cplusplus 2847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt extern "C" { 2947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#endif 3047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 3147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// PosixNetworkInterface is a record extension of the core NetworkInterfaceInfo 3247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// type that supports extra fields needed by the Posix platform. 3347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// 3447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// IMPORTANT: coreIntf must be the first field in the structure because 3547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// we cast between pointers to the two different types regularly. 3647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 3747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalttypedef struct PosixNetworkInterface PosixNetworkInterface; 3847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 3947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltstruct PosixNetworkInterface 4047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt { 4147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt NetworkInterfaceInfo coreIntf; 4247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt const char * intfName; 4347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt PosixNetworkInterface * aliasIntf; 4447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt int index; 4547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt int multicastSocket4; 4647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#if HAVE_IPV6 4747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt int multicastSocket6; 4847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#endif 4947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt }; 5047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 5147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// This is a global because debugf_() needs to be able to check its value 5247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern int gMDNSPlatformPosixVerboseLevel; 5347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 5447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltstruct mDNS_PlatformSupport_struct 5547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt { 5647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt int unicastSocket4; 5747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#if HAVE_IPV6 5847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt int unicastSocket6; 5947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#endif 6047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt }; 6147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 6247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#define uDNS_SERVERS_FILE "/etc/resolv.conf" 6347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern int ParseDNSServers(mDNS *m, const char *filePath); 6447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern mStatus mDNSPlatformPosixRefreshInterfaceList(mDNS *const m); 6547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt // See comment in implementation. 6647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 6747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// Call mDNSPosixGetFDSet before calling select(), to update the parameters 6847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// as may be necessary to meet the needs of the mDNSCore code. 6947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// The timeout pointer MUST NOT be NULL. 7047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// Set timeout->tv_sec to 0x3FFFFFFF if you want to have effectively no timeout 7147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// After calling mDNSPosixGetFDSet(), call select(nfds, &readfds, NULL, NULL, &timeout); as usual 7247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt// After select() returns, call mDNSPosixProcessFDSet() to let mDNSCore do its work 7347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern void mDNSPosixGetFDSet(mDNS *m, int *nfds, fd_set *readfds, struct timeval *timeout); 7447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern void mDNSPosixProcessFDSet(mDNS *const m, fd_set *readfds); 7547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 7647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalttypedef void (*mDNSPosixEventCallback)(int fd, short filter, void *context); 7747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 7847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern mStatus mDNSPosixAddFDToEventLoop( int fd, mDNSPosixEventCallback callback, void *context); 7947e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern mStatus mDNSPosixRemoveFDFromEventLoop( int fd); 8047e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern mStatus mDNSPosixListenForSignalInEventLoop( int signum); 8147e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern mStatus mDNSPosixIgnoreSignalInEventLoop( int signum); 8247e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwaltextern mStatus mDNSPosixRunEventLoopOnce( mDNS *m, const struct timeval *pTimeout, sigset_t *pSignalsReceived, mDNSBool *pDataDispatched); 8347e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 8447e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#ifdef __cplusplus 8547e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt } 8647e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#endif 8747e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt 8847e4cebad7397422144bb03a21f3f7682c062c4aRobert Greenwalt#endif 89