/* -*- Mode: C; tab-width: 4 -*-
*
* Copyright (c) 2002-2015 Apple 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
*
*
* 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 "mDNSEmbeddedAPI.h" // Defines the interface provided to the client layer above
#include "DNSCommon.h"
#include "mDNSPosix.h" // Defines the specific types needed to run mDNS on this platform
#include "dns_sd.h"
#include "dnssec.h"
#include "nsec.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <syslog.h>
#include <stdarg.h>
#include <fcntl.h>
#include <time.h> // platform support for UTC time
#if USES_NETLINK
#include <linux/rtnetlink.h>
#else // USES_NETLINK
#endif // USES_NETLINK
#include "mDNSUNP.h"
#include "GenLinkedList.h"
// ***************************************************************************
// Structures
// We keep a list of client-supplied event sources in PosixEventSource records
struct PosixEventSource
{
void *Context;
int fd;
};
// Context record for interface change callback
struct IfChangeRec
{
int NotifySD;
};
// Note that static data is initialized to zero in (modern) C.
// ***************************************************************************
// Globals (for debugging)
static int num_registered_interfaces = 0;
static int num_pkts_accepted = 0;
static int num_pkts_rejected = 0;
// ***************************************************************************
// Functions
int gMDNSPlatformPosixVerboseLevel = 0;
mDNSlocal void SockAddrTomDNSAddr(const struct sockaddr *const sa, mDNSAddr *ipAddr, mDNSIPPort *ipPort)
{
{
case AF_INET:
{
break;
}
#if HAVE_IPV6
case AF_INET6:
{
#ifndef NOT_HAVE_SA_LEN
#endif
break;
}
#endif
default:
break;
}
}
#endif
// mDNS core calls this routine when it needs to send a packet.
mDNSexport mStatus mDNSPlatformSendUDP(const mDNS *const m, const void *const msg, const mDNSu8 *const end,
{
int err = 0;
(void)src; // Will need to use this parameter once we implement mDNSPlatformUDPSocket/mDNSPlatformUDPClose
(void) useBackgroundTrafficClass;
if (dstPort.NotAnInteger == 0)
{
LogMsg("mDNSPlatformSendUDP: Invalid argument -dstPort is set to 0");
return PosixErrorToStatus(EINVAL);
}
{
#ifndef NOT_HAVE_SA_LEN
#endif
}
#if HAVE_IPV6
{
#ifndef NOT_HAVE_SA_LEN
#endif
}
#endif
if (sendingsocket >= 0)
err = sendto(sendingsocket, msg, (char*)end - (char*)msg, 0, (struct sockaddr *)&to, GET_SA_LEN(to));
else if (err < 0)
{
static int MessageCount = 0;
// Don't report EHOSTDOWN (i.e. ARP failure), ENETDOWN, or no route to host for unicast destinations
if (!mDNSAddressIsAllDNSLinkGroup(dst))
if (errno == EHOSTDOWN || errno == ENETDOWN || errno == EHOSTUNREACH || errno == ENETUNREACH) return(mStatus_TransientErr);
/* dont report ENETUNREACH */
if (MessageCount < 1000)
{
MessageCount++;
if (thisIntf)
LogMsg("mDNSPlatformSendUDP got error %d (%s) sending packet to %#a on interface %#a/%s/%d",
else
}
}
return PosixErrorToStatus(err);
}
// This routine is called when the main loop detects that data is available on a socket.
{
int flags;
flags = 0;
packetLen = recvfrom_flags(skt, &packet, sizeof(packet), &flags, (struct sockaddr *) &from, &fromLen, &packetInfo, &ttl);
if (packetLen >= 0)
{
// If we have broken IP_RECVDSTADDR functionality (so far
// I've only seen this on OpenBSD) then apply a hack to
// convince mDNS Core that this isn't a spoof packet.
// Basically what we do is check to see whether the
// packet arrived as a multicast and, if so, set its
// destAddr to the mDNS address.
//
// I must admit that I could just be doing something
// wrong on OpenBSD and hence triggering this problem
// but I'm at a loss as to how.
//
// If this platform doesn't have IP_PKTINFO or IP_RECVDSTADDR, then we have
// no way to tell the destination address or interface this packet arrived on,
// so all we can do is just assume it's a multicast
{
}
#endif
// We only accept the packet if the interface on which it came
// in matches the interface associated with this socket.
// We do this match by name or by index, depending on which
// information is available. recvfrom_flags sets the name
// to "" if the name isn't available, or the index to -1
// if the index is available. This accomodates the various
// different capabilities of our target platforms.
if (!intf)
{
// Ignore multicasts accidentally delivered to our unicast receiving socket
}
else
{
if (reject)
{
verbosedebugf("SocketDataReady ignored a packet from %#a to %#a on interface %s/%d expecting %#a/%s/%d/%d",
packetLen = -1;
{
"*** WARNING: Received %d packets; Accepted %d packets; Rejected %d packets because of interface mismatch\n",
num_pkts_accepted = 0;
num_pkts_rejected = 0;
}
}
else
{
verbosedebugf("SocketDataReady got a packet from %#a to %#a on interface %#a/%s/%d/%d",
}
}
}
if (packetLen >= 0)
}
{
(void)m; // unused
(void)src; // unused
return mDNSfalse;
}
mDNSexport TCPSocket *mDNSPlatformTCPSocket(mDNS * const m, TCPSocketFlags flags, mDNSIPPort * port, mDNSBool useBackgroundTrafficClass)
{
(void)m; // Unused
(void)flags; // Unused
(void)port; // Unused
(void)useBackgroundTrafficClass; // Unused
return NULL;
}
{
(void)flags; // Unused
(void)sd; // Unused
return NULL;
}
{
(void)sock; // Unused
return -1;
}
mDNSexport mStatus mDNSPlatformTCPConnect(TCPSocket *sock, const mDNSAddr *dst, mDNSOpaque16 dstport, domainname *hostname, mDNSInterfaceID InterfaceID,
{
(void)sock; // Unused
(void)dst; // Unused
(void)dstport; // Unused
(void)hostname; // Unused
(void)InterfaceID; // Unused
(void)callback; // Unused
(void)context; // Unused
return(mStatus_UnsupportedErr);
}
{
(void)sock; // Unused
}
mDNSexport long mDNSPlatformReadTCP(TCPSocket *sock, void *buf, unsigned long buflen, mDNSBool * closed)
{
(void)sock; // Unused
(void)buf; // Unused
(void)buflen; // Unused
(void)closed; // Unused
return 0;
}
{
(void)sock; // Unused
(void)msg; // Unused
(void)len; // Unused
return 0;
}
{
(void)m; // Unused
(void)port; // Unused
return NULL;
}
{
(void)sock; // Unused
}
{
(void)m; // Unused
(void)InterfaceID; // Unused
}
mDNSexport void mDNSPlatformSendRawPacket(const void *const msg, const mDNSu8 *const end, mDNSInterfaceID InterfaceID)
{
(void)msg; // Unused
(void)end; // Unused
(void)InterfaceID; // Unused
}
mDNSexport void mDNSPlatformSetLocalAddressCacheEntry(mDNS *const m, const mDNSAddr *const tpa, const mDNSEthAddr *const tha, mDNSInterfaceID InterfaceID)
{
(void)m; // Unused
(void)tpa; // Unused
(void)tha; // Unused
(void)InterfaceID; // Unused
}
{
return(mStatus_UnsupportedErr);
}
{
}
{
(void) m;
(void) allowSleep;
(void) reason;
}
#pragma mark -
#endif
{
(void)m; // unused
(void)rr;
(void)result;
}
#endif
/*
* Stub to set or get DNS config. Even if it actually does not do anything, it has to
* make sure the data is zeroed properly.
*/
mDNSexport mDNSBool mDNSPlatformSetDNSConfig(mDNS *const m, mDNSBool setservers, mDNSBool setsearch, domainname *const fqdn, DNameListElem **RegDomains,
{
(void) m;
(void) setservers;
(void) setsearch;
(void) ackConfig;
return mDNStrue;
}
mDNSexport mStatus mDNSPlatformGetPrimaryInterface(mDNS * const m, mDNSAddr * v4, mDNSAddr * v6, mDNSAddr * router)
{
(void) m;
(void) v4;
(void) v6;
(void) router;
return mStatus_UnsupportedErr;
}
mDNSexport void mDNSPlatformDynDNSHostNameStatusChanged(const domainname *const dname, const mStatus status)
{
(void) dname;
(void) status;
}
#endif
// This gets the current hostname, truncating it at the first dot if necessary
{
int len = 0;
}
// On OS X this gets the text of the field labelled "Computer Name" in the Sharing Prefs Control Panel
// Other platforms can either get the information from the appropriate place,
// or they can alternatively just require all registering services to provide an explicit name
{
// On Unix we have no better name than the host name, so we just use that.
}
{
int numOfServers = 0;
{
{
mDNS_AddDNSServer(m, NULL, mDNSInterface_Any, 0, &DNSAddr, UnicastDNSPort, kScopeNone, 0, mDNSfalse, 0, mDNStrue, mDNStrue, mDNSfalse);
numOfServers++;
}
}
return (numOfServers > 0) ? 0 : -1;
}
// Searches the interface list looking for the named interface.
// Returns a pointer to if it found, or NULL otherwise.
{
return intf;
}
{
return (mDNSInterfaceID) intf;
}
mDNSexport mDNSu32 mDNSPlatformInterfaceIndexfromInterfaceID(mDNS *const m, mDNSInterfaceID id, mDNSBool suppressNetworkChange)
{
(void) suppressNetworkChange; // Unused
// If we didn't find the interface, check the RecentInterfaces list as well
}
// Frees the specified PosixNetworkInterface structure. The underlying
// interface must have already been deregistered with the mDNS core.
{
#if HAVE_IPV6
#endif
// Move interface to the RecentInterfaces list for a minute
}
// Grab the first interface, deregister it, free it, and repeat until done.
{
while (m->HostInterfaces)
{
if (gMDNSPlatformPosixVerboseLevel > 0) fprintf(stderr, "Deregistered interface %s\n", intf->intfName);
}
num_pkts_accepted = 0;
num_pkts_rejected = 0;
}
// If mDNSIPPort port is non-zero, then it's a multicast socket on the specified interface
// If mDNSIPPort port is zero, then it's a randomly assigned port number, used for sending unicast queries
mDNSlocal int SetupSocket(struct sockaddr *intfAddr, mDNSIPPort port, int interfaceIndex, int *sktPtr)
{
int err = 0;
(void) interfaceIndex; // This parameter unused on plaforms that don't have IPv6
// Open the socket...
#if HAVE_IPV6
#endif
else return EINVAL;
if (*sktPtr < 0) { err = errno; perror((intfAddr->sa_family == AF_INET) ? "socket AF_INET" : "socket AF_INET6"); }
// ... with a shared UDP port, if it's for multicast receiving
{
// <rdar://problem/20946253>
// We test for SO_REUSEADDR first, as suggested by Jonny Törnbom from Axis Communications
// Linux kernel versions 3.9 introduces support for socket option
// SO_REUSEPORT, however this is not implemented the same as on *BSD
// systems. Linux version implements a "port hijacking" prevention
// mechanism, limiting processes wanting to bind to an already existing
// addr:port to have the same effective UID as the first who bound it. What
// this meant for us was that the daemon ran as one user and when for
// instance mDNSClientPosix was executed by another user, it wasn't allowed
// to bind to the socket. Our suggestion was to switch the order in which
// SO_REUSEPORT and SO_REUSEADDR was tested so that SO_REUSEADDR stays on
// top and SO_REUSEPORT to be used only if SO_REUSEADDR doesn't exist.
#if defined(SO_REUSEADDR) && !defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
#elif defined(SO_REUSEPORT)
#else
#endif
// Enable inbound packets on IFEF_AWDL interface.
// Only done for multicast sockets, since we don't expect unicast socket operations
// on the IFEF_AWDL interface. Operation is a no-op for other interface types.
#ifdef SO_RECV_ANYIF
if (setsockopt(*sktPtr, SOL_SOCKET, SO_RECV_ANYIF, &kOn, sizeof(kOn)) < 0) perror("setsockopt - SO_RECV_ANYIF");
#endif
}
// We want to receive destination addresses and interface identifiers.
{
if (err == 0)
{
#if defined(IP_PKTINFO) // Linux
#if defined(IP_RECVDSTADDR)
#endif
#if defined(IP_RECVIF)
if (err == 0)
{
}
#endif
#else
#warning This platform has no way to get the destination interface information -- will only work for single-homed hosts
#endif
}
#if defined(IP_RECVTTL) // Linux
if (err == 0)
{
// We no longer depend on being able to get the received TTL, so don't worry if the option fails
}
#endif
// Add multicast group membership on this interface
if (err == 0 && JoinMulticastGroup)
{
}
// Specify outgoing interface too
if (err == 0 && JoinMulticastGroup)
{
err = setsockopt(*sktPtr, IPPROTO_IP, IP_MULTICAST_IF, &((struct sockaddr_in*)intfAddr)->sin_addr, sizeof(struct in_addr));
}
// Per the mDNS spec, send unicast packets with TTL 255
if (err == 0)
{
}
// and multicast packets with TTL 255 too
// There's some debate as to whether IP_MULTICAST_TTL is an int or a byte so we just try both.
if (err == 0)
{
err = setsockopt(*sktPtr, IPPROTO_IP, IP_MULTICAST_TTL, &kByteTwoFiveFive, sizeof(kByteTwoFiveFive));
}
// And start listening for packets
if (err == 0)
{
}
} // endif (intfAddr->sa_family == AF_INET)
#if HAVE_IPV6
{
#if defined(IPV6_RECVPKTINFO) // Solaris
if (err == 0)
{
}
#elif defined(IPV6_PKTINFO)
if (err == 0)
{
}
#else
#warning This platform has no way to get the destination interface information for IPv6 -- will only work for single-homed hosts
#endif
#if defined(IPV6_RECVHOPLIMIT)
if (err == 0)
{
}
#elif defined(IPV6_HOPLIMIT)
if (err == 0)
{
}
#endif
// Add multicast group membership on this interface
if (err == 0 && JoinMulticastGroup)
{
//LogMsg("Joining %.16a on %d", &imr6.ipv6mr_multiaddr, imr6.ipv6mr_interface);
if (err < 0)
{
verbosedebugf("IPV6_JOIN_GROUP %.16a on %d failed.\n", &imr6.ipv6mr_multiaddr, imr6.ipv6mr_interface);
perror("setsockopt - IPV6_JOIN_GROUP");
}
}
// Specify outgoing interface too
if (err == 0 && JoinMulticastGroup)
{
}
// We want to receive only IPv6 packets on this socket.
// Without this option, we may get IPv4 addresses as mapped addresses.
if (err == 0)
{
}
// Per the mDNS spec, send unicast packets with TTL 255
if (err == 0)
{
err = setsockopt(*sktPtr, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &kIntTwoFiveFive, sizeof(kIntTwoFiveFive));
}
// and multicast packets with TTL 255 too
// There's some debate as to whether IPV6_MULTICAST_HOPS is an int or a byte so we just try both.
if (err == 0)
{
err = setsockopt(*sktPtr, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &kByteTwoFiveFive, sizeof(kByteTwoFiveFive));
err = setsockopt(*sktPtr, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &kIntTwoFiveFive, sizeof(kIntTwoFiveFive));
}
// And start listening for packets
if (err == 0)
{
#ifndef NOT_HAVE_SA_LEN
#endif
bindAddr6.sin6_flowinfo = 0;
bindAddr6.sin6_scope_id = 0;
}
} // endif (intfAddr->sa_family == AF_INET6)
#endif
// Set the socket to non-blocking.
if (err == 0)
{
else
{
}
}
// Clean up
return err;
}
// Creates a PosixNetworkInterface for the interface whose IP address is
// intfAddr and whose name is intfName and registers it with mDNS core.
mDNSlocal int SetupOneInterface(mDNS *const m, struct sockaddr *intfAddr, struct sockaddr *intfMask, const char *intfName, int intfIndex)
{
int err = 0;
// Allocate the interface structure itself.
// And make a copy of the intfName.
if (err == 0)
{
}
if (err == 0)
{
// Set up the fields required by the mDNS core.
//LogMsg("SetupOneInterface: %#a %#a", &intf->coreIntf.ip, &intf->coreIntf.mask);
// Set up the extra fields in PosixNetworkInterface.
#if HAVE_IPV6
#endif
debugf("SetupOneInterface: %s %#a is an alias of %#a", intfName, &intf->coreIntf.ip, &alias->coreIntf.ip);
}
// Set up the multicast socket
if (err == 0)
{
#if HAVE_IPV6
#endif
}
// If interface is a direct link, address record will be marked as kDNSRecordTypeKnownUnique
#ifdef DIRECTLINK_INTERFACE_NAME
#endif
// The interface is all ready to go, let's register it with the mDNS core.
if (err == 0)
// Clean up.
if (err == 0)
{
if (gMDNSPlatformPosixVerboseLevel > 0)
}
else
{
// Use intfName instead of intf->intfName in the next line to avoid dereferencing NULL.
}
return err;
}
// Call get_ifi_info() to obtain a list of active interfaces and call SetupOneInterface() on each one.
{
int err = 0;
debugf("SetupInterfaceList");
#if HAVE_IPV6
if (err == 0) /* Link the IPv6 list to the end of the IPv4 list */
{
while (*p) p = &(*p)->ifi_next;
}
#endif
if (err == 0)
{
while (i)
{
#if HAVE_IPV6
#endif
{
if (i->ifi_flags & IFF_LOOPBACK)
{
if (firstLoopback == NULL)
firstLoopback = i;
}
else
{
}
}
i = i->ifi_next;
}
// If we found no normal interfaces but we did find a loopback interface, register the
// loopback interface. This allows self-discovery if no interfaces are configured.
// Temporary workaround: Multicast loopback on IPv6 interfaces appears not to work.
// In the interim, we skip loopback interface only if we found at least one v4 interface to use
// if ((m->HostInterfaces == NULL) && (firstLoopback != NULL))
if (!foundav4 && firstLoopback)
(void) SetupOneInterface(m, firstLoopback->ifi_addr, firstLoopback->ifi_netmask, firstLoopback->ifi_name, firstLoopback->ifi_index);
}
// Clean up.
// Clean up any interfaces that have been hanging around on the RecentInterfaces list for more than a minute
while (*ri)
{
}
return err;
}
#if USES_NETLINK
// See <http://www.faqs.org/rfcs/rfc3549.html> for a description of NetLink
// Open a socket that will receive interface change notifications
{
int sock;
int ret;
if (sock < 0)
return errno;
// Configure read to be non-blocking because inbound msg size is not known in advance
/* Subscribe the socket to Link & IP addr notifications. */
if (0 == ret)
else
return err;
}
#if MDNS_DEBUGMSGS
{
const char *kNLRtMsgTypes[] = { "RTM_NEWLINK", "RTM_DELLINK", "RTM_GETLINK", "RTM_NEWADDR", "RTM_DELADDR", "RTM_GETADDR" };
pNLMsg->nlmsg_type < RTM_BASE ? kNLMsgTypes[pNLMsg->nlmsg_type] : kNLRtMsgTypes[pNLMsg->nlmsg_type - RTM_BASE],
{
}
{
}
printf("\n");
}
#endif
// Read through the messages on sd and if any indicate that any interface records should
// be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0.
{
// The structure here is more complex than it really ought to be because,
// unfortunately, there's no good way to size a buffer in advance large
// enough to hold all pending data and so avoid message fragmentation.
// (Note that FIONREAD is not supported on AF_NETLINK.)
while (1)
{
// Make sure we've got an entire nlmsghdr in the buffer, and payload, too.
// If not, discard already-processed messages in buffer and read more data.
{
{
// discard processed data
// read more data
continue; // spin around and revalidate with new readCount
}
else
break; // Otherwise message does not fit in buffer
}
#if MDNS_DEBUGMSGS
#endif
// Process the NetLink message
// Advance pNLMsg to the next message in the buffer
{
}
else
break; // all done!
}
return result;
}
#else // USES_NETLINK
// Open a socket that will receive interface change notifications
{
if (*pFD < 0)
return mStatus_UnknownErr;
// Configure read to be non-blocking because inbound msg size is not known in advance
return mStatus_NoError;
}
#if MDNS_DEBUGMSGS
{
"RTM_REDIRECT", "RTM_MISS", "RTM_LOCK", "RTM_OLDADD", "RTM_OLDDEL", "RTM_RESOLVE",
"RTM_NEWADDR", "RTM_DELADDR", "RTM_IFINFO", "RTM_NEWMADDR", "RTM_DELMADDR" };
int index = pRSMsg->ifam_type == RTM_IFINFO ? ((struct if_msghdr*) pRSMsg)->ifm_index : pRSMsg->ifam_index;
printf("ifa_msghdr len=%d, type=%s, index=%d\n", pRSMsg->ifam_msglen, kRSMsgTypes[pRSMsg->ifam_type], index);
}
#endif
// Read through the messages on sd and if any indicate that any interface records should
// be torn down and rebuilt, return affected indices as a bitmask. Otherwise return 0.
{
return mStatus_UnsupportedErr; // cannot decipher message
#if MDNS_DEBUGMSGS
#endif
// Process the message
{
case RTM_NEWADDR:
case RTM_DELADDR:
case RTM_IFINFO:
/*
* ADD & DELETE are happening when IPv6 announces are changing,
* and for some reason it will stop mdnsd to announce IPv6
* addresses. So we force mdnsd to check interfaces.
*/
case RTM_ADD:
case RTM_DELETE:
else
break;
}
return result;
}
#endif // USES_NETLINK
// Called when data appears on interface change notification socket
{
(void)fd; // Unused
(void)filter; // Unused
do
{
}
// Currently we rebuild the entire interface list whenever any interface change is
// detected. If this ever proves to be a performance issue in a multi-homed
// configuration, more care should be paid to changedInterfaces.
if (changedInterfaces)
}
// Register with either a Routing Socket or RtNetLink to listen for interface changes.
{
return mStatus_NoMemoryErr;
if (err == 0)
return err;
}
// Test to see if we're the first client running on UDP port 5353, by trying to bind to 5353 without using SO_REUSEPORT.
// If we fail, someone else got here first. That's not a big problem; we can share the port for multicast responses --
// we just need to be aware that we shouldn't expect to successfully receive unicast UDP responses.
{
int err;
close(s);
else debugf("Unicast UDP responses okay");
return(err == 0);
}
// mDNS core calls this routine to initialise the platform-specific data.
{
int err = 0;
// Tell mDNS core the names of this machine.
// Set up the nice label
m->nicelabel.c[0] = 0;
// Set up the RFC 1034-compliant label
m->hostlabel.c[0] = 0;
mDNS_SetFQDN(m);
m->p->unicastSocket4 = -1;
#if HAVE_IPV6
m->p->unicastSocket6 = -1;
#endif
// Tell mDNS core about the network interfaces on this machine.
// Tell mDNS core about DNS Servers
mDNS_Lock(m);
mDNS_Unlock(m);
if (err == mStatus_NoError)
{
err = WatchForInterfaceChange(m);
// Failure to observe interface changes is non-fatal.
if (err != mStatus_NoError)
{
}
}
// We don't do asynchronous initialization on the Posix platform, so by the time
// we get here the setup will already have succeeded or failed. If it succeeded,
// we should just call mDNSCoreInitComplete() immediately.
if (err == mStatus_NoError)
return PosixErrorToStatus(err);
}
// mDNS core calls this routine to clean up the platform-specific data.
// In our case all we need to do is to tear down every network interface.
{
#if HAVE_IPV6
#endif
}
// This is used internally by InterfaceChangeCallback.
// It's also exported so that the Standalone Responder (mDNSResponderPosix)
// can call it in response to a SIGHUP (mainly for debugging purposes).
{
int err;
// This is a pretty heavyweight way to process interface changes --
// destroying the entire interface list and then making fresh one from scratch.
// We should make it like the OS X version, which leaves unchanged interfaces alone.
err = SetupInterfaceList(m);
return PosixErrorToStatus(err);
}
#endif
// On the Posix platform, locking is a no-op because we only ever enter
// mDNS core on the main thread.
// mDNS core calls this routine when it wants to prevent
// the platform from reentering mDNS core code.
{
(void) m; // Unused
}
// mDNS core calls this routine when it release the lock taken by
// mDNSPlatformLock and allow the platform to reenter mDNS core code.
{
(void) m; // Unused
}
#endif
// mDNS core calls this routine to copy C strings.
// On the Posix platform this maps directly to the ANSI C strcpy.
{
}
// mDNS core calls this routine to get the length of a C string.
// On the Posix platform this maps directly to the ANSI C strlen.
{
}
// mDNS core calls this routine to copy memory.
// On the Posix platform this maps directly to the ANSI C memcpy.
{
}
// mDNS core calls this routine to test whether blocks of memory are byte-for-byte
// identical. On the Posix platform this is a simple wrapper around ANSI C memcmp.
{
}
// If the caller wants to know the exact return of memcmp, then use this instead
// of mDNSPlatformMemSame
{
}
mDNSexport void mDNSPlatformQsort(void *base, int nel, int width, int (*compar)(const void *, const void *))
{
}
// DNSSEC stub functions
{
(void)m;
(void)dv;
(void)q;
}
mDNSexport mDNSBool AddNSECSForCacheRecord(mDNS *const m, CacheRecord *crlist, CacheRecord *negcr, mDNSu8 rcode)
{
(void)m;
(void)crlist;
(void)negcr;
(void)rcode;
return mDNSfalse;
}
mDNSexport void BumpDNSSECStats(mDNS *const m, DNSSECStatsAction action, DNSSECStatsType type, mDNSu32 value)
{
(void)m;
(void)action;
(void)type;
(void)value;
}
// Proxy stub functions
mDNSexport mDNSu8 *DNSProxySetAttributes(DNSQuestion *q, DNSMessageHeader *h, DNSMessage *msg, mDNSu8 *ptr, mDNSu8 *limit)
{
(void) q;
(void) h;
(void) msg;
(void) ptr;
(void) limit;
return ptr;
}
{
(void) m;
(void) IpIfArr;
(void) OpIf;
}
{
(void) m;
}
// mDNS core calls this routine to clear blocks of memory.
// On the Posix platform this is a simple wrapper around ANSI C memset.
{
}
{
}
{
// No special setup is required on Posix -- we just use gettimeofday();
// This is not really safe, because gettimeofday can go backwards if the user manually changes the date or time
// We should find a better way to do this
return(mStatus_NoError);
}
{
// tv.tv_sec is seconds since 1st January 1970 (GMT, with no adjustment for daylight savings time)
// tv.tv_usec is microseconds since the start of this second (i.e. values 0 to 999999)
// We use the lower 22 bits of tv.tv_sec for the top 22 bits of our result
// and we multiply tv.tv_usec by 16 / 15625 to get a value in the range 0-1023 to go in the bottom 10 bits.
// This gives us a proper modular (cyclic) counter that has a resolution of roughly 1ms (actually 1/1024 second)
// and correctly cycles every 2^22 seconds (4194304 seconds = approx 48 days).
}
{
}
mDNSexport void mDNSPlatformSendWakeupPacket(mDNS *const m, mDNSInterfaceID InterfaceID, char *EthAddr, char *IPAddr, int iteration)
{
(void) m;
(void) InterfaceID;
(void) EthAddr;
(void) IPAddr;
(void) iteration;
}
mDNSexport mDNSBool mDNSPlatformValidRecordForInterface(AuthRecord *rr, const NetworkInterfaceInfo *intf)
{
(void) rr;
(void) intf;
return 1;
}
mDNSexport mDNSBool mDNSPlatformValidQuestionForInterface(DNSQuestion *q, const NetworkInterfaceInfo *intf)
{
(void) q;
(void) intf;
return 1;
}
// Used for debugging purposes. For now, just set the buffer to zero
{
(void) te;
}
mDNSexport void mDNSPlatformSendKeepalive(mDNSAddr *sadd, mDNSAddr *dadd, mDNSIPPort *lport, mDNSIPPort *rport, mDNSu32 seq, mDNSu32 ack, mDNSu16 win)
{
(void) sadd; // Unused
(void) dadd; // Unused
(void) lport; // Unused
(void) rport; // Unused
(void) seq; // Unused
(void) ack; // Unused
(void) win; // Unused
}
mDNSexport mStatus mDNSPlatformRetrieveTCPInfo(mDNS *const m, mDNSAddr *laddr, mDNSIPPort *lport, mDNSAddr *raddr, mDNSIPPort *rport, mDNSTCPInfo *mti)
{
(void) m; // Unused
(void) laddr; // Unused
(void) raddr; // Unused
(void) lport; // Unused
(void) rport; // Unused
(void) mti; // Unused
return mStatus_NoError;
}
{
(void) raddr; // Unused
(void) m; // Unused
return mStatus_NoError;
}
{
(void) spsaddr; // Unused
(void) ifname; // Unused
return mStatus_NoError;
}
{
return mStatus_NoError;
}
{
(void) sock; // unused
return (mDNSu16)-1;
}
{
(void) InterfaceID; // unused
return mDNSfalse;
}
mDNSexport void mDNSPlatformGetDNSRoutePolicy(mDNS *const m, DNSQuestion *q, mDNSBool *isCellBlocked)
{
(void) m;
q->ServiceID = -1;
}
{
(void) src;
(void) dst;
(void) q;
}
{
return 0;
}
{
}
{
// 1. Call mDNS_Execute() to let mDNSCore do what it needs to do
// 2. Build our list of active file descriptors
#if HAVE_IPV6
#endif
while (info)
{
#if HAVE_IPV6
#endif
}
// 3. Calculate the time remaining to the next scheduled event (in struct timeval format)
// 4. If client's proposed timeout is more than what we want, then reduce it
}
{
{
}
#if HAVE_IPV6
{
}
#endif
while (info)
{
{
}
#if HAVE_IPV6
{
}
#endif
}
}
// update gMaxFD
{
gMaxFD = 0;
}
// Add a file descriptor to the set that mDNSPosixRunEventLoopOnce() listens to.
{
if (gEventSources.LinkOffset == 0)
return mStatus_UnsupportedErr;
return mStatus_BadParamErr;
return mStatus_NoMemoryErr;
return mStatus_NoError;
}
// Remove a file descriptor from the set that mDNSPosixRunEventLoopOnce() listens to.
{
{
{
return mStatus_NoError;
}
}
return mStatus_NoSuchNameErr;
}
// Simply note the received signal in gEventSignals.
{
}
// Tell the event package to listen for signal and report it in mDNSPosixRunEventLoopOnce().
{
return err;
}
// Tell the event package to stop listening for signal in mDNSPosixRunEventLoopOnce().
{
return err;
}
// Do a single pass through the attendent event sources and dispatch any found to their callbacks.
// Return as soon as internal timeout expires, or a signal we're listening for is received.
{
// Include the sockets that are listening to the wire in our select() set
// If any data appeared, invoke its callback
if (numReady > 0)
{
{
{
break; // in case callback removed elements from gEventSources
}
}
}
else
return mStatus_NoError;
}