include /Developer/Makefiles/pb_makefiles/platform.make
-MVERS = "mDNSResponder-58.6"
+MVERS = "mDNSResponder-58.8"
install:
cd "$(SRCROOT)/mDNSMacOSX"; pbxbuild install OBJROOT=$(OBJROOT) SYMROOT=$(SYMROOT) DSTROOT=$(DSTROOT) MVERS=$(MVERS)
Change History (most recent first):
$Log: mDNS.c,v $
+Revision 1.307.2.8 2004/04/03 05:18:19 bradley
+Added cast to fix signed/unsigned warning due to int promotion.
+
+Revision 1.307.2.7 2004/03/30 06:46:24 cheshire
+Compiler warning fixes from Don Woodward at Roku Labs
+
+Revision 1.307.2.6 2004/03/09 03:03:38 cheshire
+<rdar://problem/3581961> Don't take lock until after mDNS_Update() has validated that the data is good
+
Revision 1.307.2.5 2004/03/02 02:55:24 cheshire
<rdar://problem/3549576> Properly support "_services._dns-sd._udp" meta-queries
const domainname *const name = estimate ? &rr->name : mDNSNULL;
switch (rr->rrtype)
{
- case kDNSType_A: return(sizeof(rd->ip)); break;
+ case kDNSType_A: return(sizeof(rd->ip));
case kDNSType_CNAME:// Same as PTR
case kDNSType_PTR: return(CompressedDomainNameLength(&rd->name, name));
case kDNSType_HINFO:return(mDNSu16)(2 + (int)rd->data[0] + (int)rd->data[1 + (int)rd->data[0]]);
case kDNSType_NULL: // Same as TXT -- not self-describing, so have to just trust rdlength
case kDNSType_TXT: return(rr->rdlength); // TXT is not self-describing, so have to just trust rdlength
- case kDNSType_AAAA: return(sizeof(rd->ipv6)); break;
+ case kDNSType_AAAA: return(sizeof(rd->ipv6));
case kDNSType_SRV: return(mDNSu16)(6 + CompressedDomainNameLength(&rd->srv.target, name));
default: debugf("Warning! Don't know how to get length of resource type %d", rr->rrtype);
return(rr->rdlength);
mDNSlocal mDNSu8 *putDomainNameAsLabels(const DNSMessage *const msg,
mDNSu8 *ptr, const mDNSu8 *const limit, const domainname *const name)
{
- const mDNSu8 *const base = (const mDNSu8 *const)msg;
+ const mDNSu8 *const base = (const mDNSu8 *)msg;
const mDNSu8 * np = name->c;
const mDNSu8 *const max = name->c + MAX_DOMAIN_NAME; // Maximum that's valid
const mDNSu8 * pointer = mDNSNULL;
if (TimeToSendThisQuestion(q, m->timenow + q->ThisQInterval/2))
{
// We forecast: qname (n) type (2) class (2)
- mDNSu32 forecast = DomainNameLength(&q->qname) + 4;
+ mDNSu32 forecast = (mDNSu32)DomainNameLength(&q->qname) + 4;
CacheRecord *rr;
for (rr=m->rrcache_hash[HashSlot(&q->qname)]; rr; rr=rr->next) // If we have a resource record in our cache,
if (rr->resrec.rdlength <= SmallRecordLimit && // which is small enough to sensibly fit in the packet
const mDNSu16 newrdlength,
RData *const newrdata, mDNSRecordUpdateCallback *Callback)
{
- mDNS_Lock(m);
-
if (!ValidateRData(rr->resrec.rrtype, newrdlength, newrdata))
{ LogMsg("Attempt to update record with invalid rdata: %s", GetRRDisplayString_rdb(m, &rr->resrec, &newrdata->u)); return(mStatus_Invalid); }
+ mDNS_Lock(m);
+
// If TTL is unspecified, leave TTL unchanged
if (newttl == 0) newttl = rr->resrec.rroriginalttl;
Change History (most recent first):
$Log: mDNSClientAPI.h,v $
+Revision 1.114.2.9 2004/04/22 03:17:35 cheshire
+Fix use of "struct __attribute__((__packed__))" so it only applies on GCC >= 2.9
+
+Revision 1.114.2.8 2004/03/30 06:55:37 cheshire
+Gave name to anonymous struct, to avoid errors on certain compilers.
+(Thanks to ramaprasad.kr@hp.com for reporting this.)
+
+Revision 1.114.2.7 2004/03/09 02:31:27 cheshire
+Remove erroneous underscore in 'packed_struct' (makes no difference now, but might in future)
+
Revision 1.114.2.6 2004/03/02 02:55:25 cheshire
<rdar://problem/3549576> Properly support "_services._dns-sd._udp" meta-queries
// 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, mDNS_Init() will detect this and report an error, so the
// developer will know what's wrong, and can investigate what needs to be done on that compiler to provide proper packing.
-#ifndef packed_struct
- #ifdef __GNUC__
+#ifndef packedstruct
+ #if ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 9)))
#define packedstruct struct __attribute__((__packed__))
#define packedunion union __attribute__((__packed__))
#else
// To enforce useful type checking, we make mDNSInterfaceID be a pointer to a dummy struct
// This way, mDNSInterfaceIDs can be assigned, and compared with each other, but not with other types
// Declaring the type to be the typical generic "void *" would lack this type checking
-typedef struct { void *dummy; } *mDNSInterfaceID;
+typedef struct mDNSInterfaceID_dummystruct { void *dummy; } *mDNSInterfaceID;
// These types are for opaque two- and four-byte identifiers.
// The "NotAnInteger" fields of the unions allow the value to be conveniently passed around in a
Change History (most recent first):
$Log: CFSocket.c,v $
+Revision 1.115.2.4 2004/04/23 00:34:06 cheshire
+<rdar://problem/3628978>: mDNSResponder messages on wake
+Take care to correctly update InterfaceIDs when a dormant interface comes back to life
+
+Revision 1.115.2.3 2004/04/08 23:18:11 cheshire
+<rdar://problem/3609972> When interface turned off, browse "remove" events delivered with interface index zero
+Refinement from Bob Bradley: Should use "mDNS *const m" instead of referencing mDNSStorage directly
+
+Revision 1.115.2.2 2004/04/08 00:42:37 cheshire
+<rdar://problem/3609972> When interface turned off, browse "remove" events delivered with interface index zero
+Unify use of the InterfaceID field, and make code that walks the list respect the CurrentlyActive flag
+
+Revision 1.115.2.1 2004/04/07 01:08:15 cheshire
+<rdar://problem/3609972> When interface turned off, browse "remove" events delivered with interface index zero
+
Revision 1.115 2003/09/10 00:45:55 cheshire
<rdar://problem/3412328> Don't log "sendto failed" errors during the first two minutes of startup
if (index == (uint32_t)~0) return((mDNSInterfaceID)~0);
if (index)
for (i = m->p->InterfaceList; i; i = i->next)
- if (i->scope_id == index)
+ if (i->ifinfo.InterfaceID && i->scope_id == index) // Don't get tricked by inactive interfaces
return(i->ifinfo.InterfaceID);
return(mDNSNULL);
}
if (id == (mDNSInterfaceID)~0) return((mDNSu32)~0);
if (id)
for (i = m->p->InterfaceList; i; i = i->next)
- if (i->ifinfo.InterfaceID == id)
+ // Don't use i->ifinfo.InterfaceID here because we want to find inactive interfaces where that's not set
+ if ((mDNSInterfaceID)i == id)
return i->scope_id;
return 0;
}
NetworkInterfaceInfoOSX *i;
for (i = m->p->InterfaceList; i; i = i->next)
if (!strcmp(i->ifa_name, ifname) &&
+ i->CurrentlyActive &&
((AAAA_OVER_V4 ) ||
(type == AF_INET && i->ifinfo.ip.type == mDNSAddrType_IPv4) ||
(type == AF_INET6 && i->ifinfo.ip.type == mDNSAddrType_IPv6) )) return(i);
{
NetworkInterfaceInfoOSX *i;
for (i = m->p->InterfaceList; i; i = i->next)
- {
- mStatus err = 0;
- NetworkInterfaceInfo *n = &i->ifinfo;
- NetworkInterfaceInfoOSX *alias = SearchForInterfaceByName(m, i->ifa_name, i->sa_family);
- if (!alias) alias = i;
-
- if (n->InterfaceID && n->InterfaceID != (mDNSInterfaceID)alias)
- {
- LogMsg("SetupActiveInterfaces ERROR! n->InterfaceID %p != alias %p", n->InterfaceID, alias);
- n->InterfaceID = mDNSNULL;
- }
-
- if (!n->InterfaceID)
- {
- n->InterfaceID = (mDNSInterfaceID)alias;
- mDNS_RegisterInterface(m, n);
- debugf("SetupActiveInterfaces: Registered %s(%lu) InterfaceID %p %#a%s",
- i->ifa_name, i->scope_id, alias, &n->ip, n->InterfaceActive ? " (Primary)" : "");
- }
-
- if (!n->TxAndRx)
- debugf("SetupActiveInterfaces: No TX/Rx on %s(%lu) InterfaceID %p %#a", i->ifa_name, i->scope_id, alias, &n->ip);
- else
+ if (i->CurrentlyActive)
{
- if (i->sa_family == AF_INET && alias->sktv4 == -1)
+ mStatus err = 0;
+ NetworkInterfaceInfo *n = &i->ifinfo;
+ NetworkInterfaceInfoOSX *alias = SearchForInterfaceByName(m, i->ifa_name, i->sa_family);
+ if (!alias) alias = i;
+
+ if (n->InterfaceID && n->InterfaceID != (mDNSInterfaceID)alias)
+ {
+ LogMsg("SetupActiveInterfaces ERROR! n->InterfaceID %p != alias %p", n->InterfaceID, alias);
+ n->InterfaceID = mDNSNULL;
+ }
+
+ if (!n->InterfaceID)
{
- #if mDNS_AllowPort53
- err = SetupSocket(i, UnicastDNSPort, &alias->skt53, &alias->cfs53);
- #endif
- if (!err) err = SetupSocket(i, MulticastDNSPort, &alias->sktv4, &alias->cfsv4);
- if (err == 0) debugf("SetupActiveInterfaces: v4 socket%2d %s(%lu) InterfaceID %p %#a", alias->sktv4, i->ifa_name, i->scope_id, n->InterfaceID, &n->ip);
- else LogMsg("SetupActiveInterfaces: v4 socket%2d %s(%lu) InterfaceID %p %#a FAILED", alias->sktv4, i->ifa_name, i->scope_id, n->InterfaceID, &n->ip);
+ n->InterfaceID = (mDNSInterfaceID)alias;
+ mDNS_RegisterInterface(m, n);
+ debugf("SetupActiveInterfaces: Registered %s(%lu) InterfaceID %p %#a%s",
+ i->ifa_name, i->scope_id, alias, &n->ip, n->InterfaceActive ? " (Primary)" : "");
}
- if (i->sa_family == AF_INET6 && alias->sktv6 == -1)
+ if (!n->TxAndRx)
+ debugf("SetupActiveInterfaces: No TX/Rx on %s(%lu) InterfaceID %p %#a", i->ifa_name, i->scope_id, alias, &n->ip);
+ else
{
- err = SetupSocket(i, MulticastDNSPort, &alias->sktv6, &alias->cfsv6);
- if (err == 0) debugf("SetupActiveInterfaces: v6 socket%2d %s(%lu) InterfaceID %p %#a", alias->sktv6, i->ifa_name, i->scope_id, n->InterfaceID, &n->ip);
- else LogMsg("SetupActiveInterfaces: v6 socket%2d %s(%lu) InterfaceID %p %#a FAILED", alias->sktv6, i->ifa_name, i->scope_id, n->InterfaceID, &n->ip);
+ if (i->sa_family == AF_INET && alias->sktv4 == -1)
+ {
+ #if mDNS_AllowPort53
+ err = SetupSocket(i, UnicastDNSPort, &alias->skt53, &alias->cfs53);
+ #endif
+ if (!err) err = SetupSocket(i, MulticastDNSPort, &alias->sktv4, &alias->cfsv4);
+ if (err == 0) debugf("SetupActiveInterfaces: v4 socket%2d %s(%lu) InterfaceID %p %#a", alias->sktv4, i->ifa_name, i->scope_id, n->InterfaceID, &n->ip);
+ else LogMsg("SetupActiveInterfaces: v4 socket%2d %s(%lu) InterfaceID %p %#a FAILED", alias->sktv4, i->ifa_name, i->scope_id, n->InterfaceID, &n->ip);
+ }
+
+ if (i->sa_family == AF_INET6 && alias->sktv6 == -1)
+ {
+ err = SetupSocket(i, MulticastDNSPort, &alias->sktv6, &alias->cfsv6);
+ if (err == 0) debugf("SetupActiveInterfaces: v6 socket%2d %s(%lu) InterfaceID %p %#a", alias->sktv6, i->ifa_name, i->scope_id, n->InterfaceID, &n->ip);
+ else LogMsg("SetupActiveInterfaces: v6 socket%2d %s(%lu) InterfaceID %p %#a FAILED", alias->sktv6, i->ifa_name, i->scope_id, n->InterfaceID, &n->ip);
+ }
}
}
- }
}
mDNSlocal void MarkAllInterfacesInactive(mDNS *const m)
i->CurrentlyActive = mDNSfalse;
}
+mDNSlocal mDNSu32 NumCacheRecordsForInterfaceID(mDNS *const m, mDNSInterfaceID id)
+ {
+ mDNSu32 slot, used = 0;
+ CacheRecord *rr;
+ for (slot = 0; slot < CACHE_HASH_SLOTS; slot++)
+ for (rr = m->rrcache_hash[slot]; rr; rr=rr->next)
+ if (rr->resrec.InterfaceID == id) used++;
+ return(used);
+ }
+
mDNSlocal void ClearInactiveInterfaces(mDNS *const m)
{
// First pass:
NetworkInterfaceInfoOSX *i;
for (i = m->p->InterfaceList; i; i = i->next)
{
- // 1. If this interface is no longer active, or it's InterfaceID is changing, deregister it
+ // 1. If this interface is no longer active, or its InterfaceID is changing, deregister it
NetworkInterfaceInfoOSX *alias = (NetworkInterfaceInfoOSX *)(i->ifinfo.InterfaceID);
- if (i->ifinfo.InterfaceID && (!i->CurrentlyActive || (alias && !alias->CurrentlyActive) || i->CurrentlyActive == 2))
+ NetworkInterfaceInfoOSX *newalias = SearchForInterfaceByName(m, i->ifa_name, i->sa_family);
+ if (!newalias) newalias = i;
+ if (i->ifinfo.InterfaceID && (!i->CurrentlyActive || (alias && !alias->CurrentlyActive) || i->CurrentlyActive == 2 || newalias != alias))
{
debugf("ClearInactiveInterfaces: Deregistering %#a", &i->ifinfo.ip);
mDNS_DeregisterInterface(m, &i->ifinfo);
i->cfsv4 = i->cfsv6 = NULL;
// 3. If no longer active, delete interface from list and free memory
- if (!i->CurrentlyActive)
+ if (!i->CurrentlyActive && NumCacheRecordsForInterfaceID(m, (mDNSInterfaceID)i) == 0)
{
debugf("ClearInactiveInterfaces: Deleting %#a", &i->ifinfo.ip);
*p = i->next;
Change History (most recent first):
$Log: daemon.c,v $
+Revision 1.134.2.6 2004/04/06 19:50:36 cheshire
+<rdar://problem/3605898> mDNSResponder will not launch if "nobody" user doesn't exist.
+After more discussion, we've decided to use userid -2 if "nobody" user doesn't exist.
+
+Revision 1.134.2.5 2004/04/03 01:29:07 cheshire
+<rdar://problem/3605898> mDNSResponder will not launch if "nobody" user doesn't exist.
+If "nobody" user doesn't exist, log a message and continue as "root"
+
+Revision 1.134.2.4 2004/04/02 21:50:21 cheshire
+Fix errors in comments
+
Revision 1.134.2.3 2003/12/12 01:21:30 cheshire
<rdar://problem/3491108> mDNSResponder should not run as root
signal(SIGTERM, HandleSIGTERM);
signal(SIGINFO, HandleSIGINFO);
- // Register the server with mach_init for automatic restart only during debug mode
+ // Register the server with mach_init for automatic restart only during normal (non-debug) mode
if (!debug_mode)
registerBootstrapService();
int fd = open(_PATH_DEVNULL, O_RDWR, 0);
if (fd != -1)
{
- // Avoid to unnecessarily duplicate a file descriptor to itself
+ // Avoid unnecessarily duplicating a file descriptor to itself
if (fd != STDIN_FILENO) (void)dup2(fd, STDIN_FILENO);
if (fd != STDOUT_FILENO) (void)dup2(fd, STDOUT_FILENO);
if (fd != STDERR_FILENO) (void)dup2(fd, STDERR_FILENO);
if ( pw != NULL)
setuid( pw->pw_uid);
else
- status = mStatus_Incompatible; // refuse to run as root
+ setuid(-2); // User "nobody" is -2; use that value if "nobody" does not appear in the password database
if (status == 0)
{
};
F525E72804AA167501F1CF4D = {
fileEncoding = 4;
+ indentWidth = 4;
isa = PBXFileReference;
path = uds_daemon.c;
refType = 4;
+ tabWidth = 4;
+ usesTabs = 0;
};
F525E72904AA167501F1CF4D = {
fileRef = F525E72804AA167501F1CF4D;
Change History (most recent first):
$Log: Responder.c,v $
+Revision 1.16.2.1 2004/04/07 23:51:09 cheshire
+Remove obsolete comments referring to doing mDNS on port 53
+
Revision 1.16 2003/08/14 02:19:55 cheshire
<rdar://problem/3375491> Split generic ResourceRecord type into two separate types: AuthRecord and CacheRecord
static void PrintUsage()
{
fprintf(stderr,
- "Usage: %s [-v level ] [-r] [-n name] [-t type] [-d domain] [-x TXT] [-p port] [-f file] [-b] [-P pidfile]\n",
+ "Usage: %s [-v level ] [-n name] [-t type] [-d domain] [-x TXT] [-p port] [-f file] [-b] [-P pidfile]\n",
gProgramName);
fprintf(stderr, " -v verbose mode, level is a number from 0 to 2\n");
fprintf(stderr, " 0 = no debugging info (default)\n");
fprintf(stderr, " 1 = standard debugging info\n");
fprintf(stderr, " 2 = intense debugging info\n");
fprintf(stderr, " can be cycled kill -USR1\n");
- fprintf(stderr, " -r also bind to port 53 (port 5353 is always bound)\n");
fprintf(stderr, " -n uses 'name' as the host name (default is none)\n");
fprintf(stderr, " -t uses 'type' as the service type (default is '%s')\n", kDefaultServiceType);
fprintf(stderr, " -d uses 'domain' as the service domain (default is '%s')\n", kDefaultServiceDomain);
fprintf(stderr, " only meaningful if -b also specified\n");
}
-static mDNSBool gAvoidPort53 = mDNStrue;
static const char *gRichTextHostName = "";
static const char *gServiceType = kDefaultServiceType;
static const char *gServiceDomain = kDefaultServiceDomain;
exit(1);
}
break;
- case 'r':
- gAvoidPort53 = mDNSfalse;
- break;
case 'n':
gRichTextHostName = optarg;
if ( ! CheckThatRichTextHostNameIsUsable(gRichTextHostName, mDNStrue) ) {
Change History (most recent first):
$Log: mDNSPosix.c,v $
+Revision 1.25.2.1 2004/04/09 17:57:31 cheshire
+Make sure to set the TxAndRx field so that duplicate suppression works correctly
+
Revision 1.25 2003/10/30 19:25:49 cheshire
Fix signed/unsigned warning on certain compilers
// Set up the fields required by the mDNS core.
SockAddrTomDNSAddr(intfAddr, &intf->coreIntf.ip, NULL);
intf->coreIntf.Advertise = m->AdvertiseLocalAddresses;
+ intf->coreIntf.TxAndRx = mDNStrue;
// Set up the extra fields in PosixNetworkInterface.
assert(intf->intfName != NULL); // intf->intfName already set up above
Change History (most recent first):
$Log: mDNSVxWorks.c,v $
+Revision 1.7.2.2 2004/04/09 17:57:31 cheshire
+Make sure to set the TxAndRx field so that duplicate suppression works correctly
+
+Revision 1.7.2.1 2004/04/03 21:31:20 bradley
+Integrated changes from TOT to remove legacy port 53 support.
+
+Revision 1.8 2003/10/28 10:08:27 bradley
+Removed legacy port 53 support as it is no longer needed.
+
Revision 1.7 2003/08/20 05:58:54 bradley
Removed dependence on modified mDNSCore: define structures/prototypes locally.
MDNSInterfaceItem * next;
char name[ 32 ];
MDNSSocketRef multicastSocketRef;
- MDNSSocketRef unicastSocketRef;
MDNSSocketRef sendingSocketRef;
NetworkInterfaceInfo hostSet;
mDNSBool hostRegistered;
int sendUnicastCounter;
int sendErrorCounter;
- int recvMulticastCounter;
- int recvUnicastCounter;
+ int recvCounter;
int recvErrorCounter;
int recvLoopCounter;
};
require_action( item, exit, err = mStatus_NoMemoryErr );
strcpy( item->name, inAddr->ifa_name );
item->multicastSocketRef = kInvalidSocketRef;
- item->unicastSocketRef = kInvalidSocketRef;
item->sendingSocketRef = kInvalidSocketRef;
// Set up the multicast DNS (port 5353) socket for this interface.
err = SetupSocket( inMDNS, inAddr, MulticastDNSPort, &socketRef );
require_noerr( err, exit );
item->multicastSocketRef = socketRef;
-
- // Set up the unicast DNS (port 53) socket for this interface (to handle normal DNS requests).
-
- err = SetupSocket( inMDNS, inAddr, UnicastDNSPort, &socketRef );
- require_noerr( err, exit );
- item->unicastSocketRef = socketRef;
-
+
// Set up the sending socket for this interface.
err = SetupSocket( inMDNS, inAddr, zeroIPPort, &socketRef );
item->hostSet.ip.type = mDNSAddrType_IPv4;
item->hostSet.ip.ip.v4.NotAnInteger = ipv4->sin_addr.s_addr;
item->hostSet.Advertise = inMDNS->AdvertiseLocalAddresses;
+ item->hostSet.TxAndRx = mDNStrue;
err = mDNS_RegisterInterface( inMDNS, &item->hostSet );
require_noerr( err, exit );
dlog( kDebugLevelVerbose, DEBUG_NAME "tearing down multicast socket %d\n", socketRef );
close( socketRef );
}
-
- // Close the unicast socket.
-
- socketRef = inItem->unicastSocketRef;
- inItem->unicastSocketRef = kInvalidSocketRef;
- if( socketRef != kInvalidSocketRef )
- {
- dlog( kDebugLevelVerbose, DEBUG_NAME "tearing down unicast socket %d\n", socketRef );
- close( socketRef );
- }
-
+
// Close the sending socket.
socketRef = inItem->sendingSocketRef;
require_errno_action( socketRef, errno, exit, err = mStatus_UnknownErr );
// A port of zero means this socket is for sending and should be set up for sending. Otherwise, it is for receiving
- // and should be set up for receiving. The reason for separate sending vs receiving sockets to workaround problems
+ // and should be set up for receiving. The reason for separate sending vs receiving sockets is to workaround problems
// with VxWorks IP stack when using dynamic IP configuration such as DHCP (problems binding to wildcard IP when the
// IP address later changes). Since we have to bind the Multicast DNS address to workaround these issues we have to
// use a separate sending socket since it is illegal to send a packet with a multicast source address (RFC 1122).
err = setsockopt( socketRef, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof( mreq ) );
check_errno( err, errno );
- // Bind to the multicast DNS address and specified port (53 for unicast or 5353 for multicast).
+ // Bind to the multicast DNS address and port 5353.
memset( &addr, 0, sizeof( addr ) );
addr.sin_family = AF_INET;
err = setsockopt( socketRef, IPPROTO_IP, IP_MULTICAST_TTL, (char *) &optionByte, sizeof( optionByte ) );
check_errno( err, errno );
+ // WARNING: Setting this option causes unicast responses to be routed to the wrong interface so they are
+ // WARNING: disabled. These options were only hints to improve 802.11 performance (and not implemented) anyway.
+
+#if 0
// Mark packets as high-throughput/low-delay (i.e. lowest reliability) to maximize 802.11 multicast rate.
option = IPTOS_LOWDELAY | IPTOS_THROUGHPUT;
err = setsockopt( socketRef, IPPROTO_IP, IP_TOS, (char *) &option, sizeof( option ) );
check_errno( err, errno );
-
+#endif
+
dlog( kDebugLevelVerbose, DEBUG_NAME "setting up sending socket done (%s, %u.%u.%u.%u, %d)\n",
inAddr->ifa_name, ip.b[ 0 ], ip.b[ 1 ], ip.b[ 2 ], ip.b[ 3 ], socketRef );
}
TaskProcessPacket( inMDNS, item, item->multicastSocketRef );
++n;
}
- if( FD_ISSET( item->unicastSocketRef, &readSet ) )
- {
- TaskProcessPacket( inMDNS, item, item->unicastSocketRef );
- ++n;
- }
}
// Check for a pending command and process it.
for( item = inMDNS->p->interfaceList; item; item = item->next )
{
FD_SET( item->multicastSocketRef, outReadSet );
- FD_SET( item->unicastSocketRef, outReadSet );
if( item->multicastSocketRef > maxSocket )
{
maxSocket = item->multicastSocketRef;
}
- if( item->unicastSocketRef > maxSocket )
- {
- maxSocket = item->unicastSocketRef;
- }
}
// Add the command pipe to the read set.
mDNSlocal void TaskProcessPacket( mDNS *inMDNS, MDNSInterfaceItem *inItem, MDNSSocketRef inSocketRef )
{
int n;
- mDNSBool isMulticast;
DNSMessage packet;
struct sockaddr_in addr;
int addrSize;
mDNSIPPort srcPort;
mDNSAddr dstAddr;
mDNSIPPort dstPort;
-
- isMulticast = ( inSocketRef == inItem->multicastSocketRef );
-
+
// Receive the packet.
addrSize = sizeof( addr );
srcAddr.ip.v4.NotAnInteger = addr.sin_addr.s_addr;
srcPort.NotAnInteger = addr.sin_port;
dstAddr.type = mDNSAddrType_IPv4;
- dstAddr.ip.v4 = isMulticast ? AllDNSLinkGroup : inItem->hostSet.ip.ip.v4;
- dstPort = isMulticast ? MulticastDNSPort : UnicastDNSPort;
+ dstAddr.ip.v4 = AllDNSLinkGroup;
+ dstPort = MulticastDNSPort;
dlog( kDebugLevelChatty, DEBUG_NAME "packet received\n" );
dlog( kDebugLevelChatty, DEBUG_NAME " size = %d\n", n );
// Update counters.
- inItem->recvMulticastCounter += isMulticast;
- inItem->recvUnicastCounter += !isMulticast;
- inItem->recvErrorCounter += ( n < 0 );
+ inItem->recvCounter += 1;
+ inItem->recvErrorCounter += ( n < 0 );
}
#if 0
printf( " -- interface %u --\n", n );
printf( " name = \"%s\"\n", item->name );
printf( " multicastSocketRef = %d\n", item->multicastSocketRef );
- printf( " unicastSocketRef = %d\n", item->unicastSocketRef );
printf( " sendingSocketRef = %d\n", item->sendingSocketRef );
ip = item->hostSet.ip;
printf( " hostSet.ip = %u.%u.%u.%u\n", ip.ip.v4.b[ 0 ], ip.ip.v4.b[ 1 ],
printf( " sendMulticastCounter = %d\n", item->sendMulticastCounter );
printf( " sendUnicastCounter = %d\n", item->sendUnicastCounter );
printf( " sendErrorCounter = %d\n", item->sendErrorCounter );
- printf( " recvMulticastCounter = %d\n", item->recvMulticastCounter );
- printf( " recvUnicastCounter = %d\n", item->recvUnicastCounter );
+ printf( " recvCounter = %d\n", item->recvCounter );
printf( " recvErrorCounter = %d\n", item->recvErrorCounter );
printf( " recvLoopCounter = %d\n", item->recvLoopCounter );
printf( "\n" );
MDNSInterfaceItem * item;
int n;
AuthRecord * record;
- char name[ 512 ];
+ char name[ MAX_ESCAPED_DOMAIN_NAME ];
printf( "\n-- mDNS resource records --\n" );
n = 1;
Change History (most recent first):
$Log: mDNSWin32.c,v $
+Revision 1.22.2.1 2004/04/03 05:26:07 bradley
+Integrated changes from TOT to remove legacy port 53 support.
+
+Revision 1.24 2003/10/24 23:23:02 bradley
+Removed legacy port 53 support as it is no longer needed.
+
+Revision 1.23 2003/10/14 03:26:12 bradley
+Clear interface list buffer to workaround Windows CE bug where interfaces are not reported correctly.
+
Revision 1.22 2003/08/20 06:21:25 bradley
Updated to latest internal version of the Rendezvous for Windows platform plugin: Added support
for Windows CE/PocketPC 2003; re-did interface-related code to emulate getifaddrs/freeifaddrs for
mDNSlocal mStatus TearDownInterface( mDNS * const inMDNS, mDNSInterfaceData *inIFD );
mDNSlocal mStatus SetupSocket( mDNS * const inMDNS,
const struct sockaddr_in * inAddress,
- mDNSIPPort inPort,
SocketRef * outSocketRef );
mDNSlocal mStatus SetupNotifications( mDNS * const inMDNS );
mDNSlocal mStatus TearDownNotifications( mDNS * const inMDNS );
// Send the packet.
ifd = (mDNSInterfaceData *) inInterfaceID;
- check( IsValidSocket( ifd->multicastSocketRef ) );
+ check( IsValidSocket( ifd->sock ) );
addr.sin_family = AF_INET;
addr.sin_port = inDstPort.NotAnInteger;
addr.sin_addr.s_addr = inDstIP->ip.v4.NotAnInteger;
n = (int)( inMsgEnd - ( (const mDNSu8 * const) inMsg ) );
- n = sendto( ifd->multicastSocketRef, (char *) inMsg, n, 0, (struct sockaddr *) &addr, sizeof( addr ) );
+ n = sendto( ifd->sock, (char *) inMsg, n, 0, (struct sockaddr *) &addr, sizeof( addr ) );
check_errno( n, errno_compat() );
ifd->sendErrorCounter += ( n < 0 );
{
check( inMDNS );
check( inMDNS->p );
+ check( inMDNS->p->lockInitialized );
check( inMDNS->p->threadID );
- // When an API routine is called, "m->NextScheduledEvent" is reset to "timenow" before calling mDNSPlatformUnlock()
- // Since our main mDNS_Execute() loop is on a different thread, we need to wake up that thread to:
- // (a) handle immediate work (if any) resulting from this API call
- // (b) calculate the next sleep time between now and the next interesting event
+ // Signal a wakeup event if when called from a task other than the mDNS task since if we are called from mDNS task,
+ // we'll loop back and call mDNS_Execute anyway. Signaling is needed to re-evaluate the wakeup via mDNS_Execute.
- if( ( mDNSPlatformTimeNow() - inMDNS->NextScheduledEvent ) >= 0 )
+ if( GetCurrentThreadId() != inMDNS->p->threadID )
{
- // We only need to case a wakeup event when called from a task other than the mDNS task since if we are
- // called from mDNS task, we'll loop back and call mDNS_Execute. This avoids filling up the command queue.
+ BOOL wasSet;
- if( GetCurrentThreadId() != inMDNS->p->threadID )
- {
- BOOL wasSet;
-
- wasSet = SetEvent( inMDNS->p->wakeupEvent );
- check( wasSet );
- }
+ wasSet = SetEvent( inMDNS->p->wakeupEvent );
+ check( wasSet );
}
LeaveCriticalSection( &inMDNS->p->lock );
}
mDNSInterfaceData * ifd;
struct ifaddrs * addrs;
struct ifaddrs * p;
- struct ifaddrs * loopback;
u_int flagMask;
u_int flagTest;
flagMask = IFF_UP | IFF_MULTICAST | IFF_LOOPBACK | IFF_POINTTOPOINT;
flagTest = IFF_UP | IFF_MULTICAST;
- loopback = NULL;
next = &inMDNS->p->interfaceList;
err = getifaddrs( &addrs );
ifd = (mDNSInterfaceData *) calloc( 1, sizeof( *ifd ) );
require_action( ifd, exit, err = mStatus_NoMemoryErr );
- ifd->multicastSocketRef = kInvalidSocketRef;
- ifd->unicastSocketRef = kInvalidSocketRef;
-
- ///
- /// Set up multicast portion of interface.
- ///
-
- // Set up the multicast DNS (port 5353) socket for this interface.
-
- err = SetupSocket( inMDNS, inAddress, MulticastDNSPort, &socketRef );
- require_noerr( err, exit );
- ifd->multicastSocketRef = socketRef;
-
- // Set up the read pending event and associate it so we can block until data is available for this socket.
+ ifd->sock = kInvalidSocketRef;
- ifd->multicastReadPendingEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
- require_action( ifd->multicastReadPendingEvent, exit, err = mStatus_NoMemoryErr );
+ // Set up a multicast DNS (port 5353) socket for this interface.
- err = WSAEventSelect( ifd->multicastSocketRef, ifd->multicastReadPendingEvent, FD_READ );
+ err = SetupSocket( inMDNS, inAddress, &socketRef );
require_noerr( err, exit );
-
- ///
- /// Set up unicast portion of interface.
- ///
-
- // Set up the unicast DNS (port 53) socket for this interface (to handle normal DNS requests).
-
- err = SetupSocket( inMDNS, inAddress, UnicastDNSPort, &socketRef );
- require_noerr( err, exit );
- ifd->unicastSocketRef = socketRef;
+ ifd->sock = socketRef;
// Set up the read pending event and associate it so we can block until data is available for this socket.
- ifd->unicastReadPendingEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
- require_action( ifd->unicastReadPendingEvent, exit, err = mStatus_NoMemoryErr );
+ ifd->readPendingEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
+ require_action( ifd->readPendingEvent, exit, err = mStatus_NoMemoryErr );
- err = WSAEventSelect( ifd->unicastSocketRef, ifd->unicastReadPendingEvent, FD_READ );
+ err = WSAEventSelect( ifd->sock, ifd->readPendingEvent, FD_READ );
require_noerr( err, exit );
-
+
// Register this interface with mDNS.
ifd->hostSet.InterfaceID = (mDNSInterfaceID) ifd;
// Tear down the multicast socket.
- if( inIFD->multicastReadPendingEvent )
+ if( inIFD->readPendingEvent )
{
- CloseHandle( inIFD->multicastReadPendingEvent );
- inIFD->multicastReadPendingEvent = 0;
+ CloseHandle( inIFD->readPendingEvent );
+ inIFD->readPendingEvent = 0;
}
- socketRef = inIFD->multicastSocketRef;
- inIFD->multicastSocketRef = kInvalidSocketRef;
+ socketRef = inIFD->sock;
+ inIFD->sock = kInvalidSocketRef;
if( IsValidSocket( socketRef ) )
{
- dlog( kDebugLevelVerbose, DEBUG_NAME "tearing down multicast socket %d\n", socketRef );
+ dlog( kDebugLevelVerbose, DEBUG_NAME "tearing down socket %d\n", socketRef );
close_compat( socketRef );
}
-
- // Tear down the unicast socket.
-
- if( inIFD->unicastReadPendingEvent )
- {
- CloseHandle( inIFD->unicastReadPendingEvent );
- inIFD->unicastReadPendingEvent = 0;
- }
-
- socketRef = inIFD->unicastSocketRef;
- inIFD->unicastSocketRef = kInvalidSocketRef;
- if( IsValidSocket( socketRef ) )
- {
- dlog( kDebugLevelVerbose, DEBUG_NAME "tearing down unicast socket %d\n", socketRef );
- close_compat( socketRef );
- }
-
+
// Free the memory used by the interface info.
free( inIFD );
SetupSocket(
mDNS * const inMDNS,
const struct sockaddr_in * inAddress,
- mDNSIPPort inPort,
SocketRef * outSocketRef )
{
mStatus err;
require_action( IsValidSocket( socketRef ), exit, err = mStatus_NoMemoryErr );
// Turn on reuse address option so multiple servers can listen for Multicast DNS packets.
-
+
option = 1;
err = setsockopt( socketRef, SOL_SOCKET, SO_REUSEADDR, (char *) &option, sizeof( option ) );
check_errno( err, errno_compat() );
- // Bind to the specified port (53 for unicast or 5353 for multicast).
+ // Bind to the mutlicast DNS port 5353.
ip.NotAnInteger = inAddress->sin_addr.s_addr;
memset( &addr, 0, sizeof( addr ) );
addr.sin_family = AF_INET;
- addr.sin_port = inPort.NotAnInteger;
+ addr.sin_port = MulticastDNSPort.NotAnInteger;
addr.sin_addr.s_addr = ip.NotAnInteger;
err = bind( socketRef, (struct sockaddr *) &addr, sizeof( addr ) );
- if( err && ( inPort.NotAnInteger == UnicastDNSPort.NotAnInteger ) )
- {
- // Some systems prevent code without root permissions from binding to the DNS port so ignore this
- // error since it is not critical. This should only occur with non-root processes.
-
- err = 0;
- }
check_errno( err, errno_compat() );
// Join the all-DNS multicast group so we receive Multicast DNS packets.
- if( inPort.NotAnInteger == MulticastDNSPort.NotAnInteger )
- {
- mreq.imr_multiaddr.s_addr = AllDNSLinkGroup.NotAnInteger;
- mreq.imr_interface.s_addr = ip.NotAnInteger;
- err = setsockopt( socketRef, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof( mreq ) );
- check_errno( err, errno_compat() );
- }
+ mreq.imr_multiaddr.s_addr = AllDNSLinkGroup.NotAnInteger;
+ mreq.imr_interface.s_addr = ip.NotAnInteger;
+ err = setsockopt( socketRef, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof( mreq ) );
+ check_errno( err, errno_compat() );
// Direct multicast packets to the specified interface.
// Success!
- dlog( kDebugLevelVerbose, DEBUG_NAME "setting up socket done (%u.%u.%u.%u:%u, %d)\n",
- ip.b[ 0 ], ip.b[ 1 ], ip.b[ 2 ], ip.b[ 3 ], ntohs( inPort.NotAnInteger ), socketRef );
+ dlog( kDebugLevelVerbose, DEBUG_NAME "setting up socket done (%u.%u.%u.%u, %d)\n",
+ ip.b[ 0 ], ip.b[ 1 ], ip.b[ 2 ], ip.b[ 3 ], socketRef );
*outSocketRef = socketRef;
socketRef = kInvalidSocketRef;
n = 0;
for( ifd = m->p->interfaceList; ifd; ifd = ifd->next )
{
- if( ifd->multicastReadPendingEvent == signaledObject )
+ if( ifd->readPendingEvent == signaledObject )
{
- ProcessingThreadProcessPacket( m, ifd, ifd->multicastSocketRef );
- ++n;
- }
- if( ifd->unicastReadPendingEvent == signaledObject )
- {
- ProcessingThreadProcessPacket( m, ifd, ifd->unicastSocketRef );
+ ProcessingThreadProcessPacket( m, ifd, ifd->sock );
++n;
}
}
// Allocate an array to hold all the objects to wait on.
- waitListCount = kWaitListFixedItemCount + ( 2 * inMDNS->p->interfaceCount );
+ waitListCount = kWaitListFixedItemCount + inMDNS->p->interfaceCount;
waitList = (HANDLE *) malloc( waitListCount * sizeof( *waitList ) );
require_action( waitList, exit, err = mStatus_NoMemoryErr );
waitItemPtr = waitList;
for( ifd = inMDNS->p->interfaceList; ifd; ifd = ifd->next )
{
- *waitItemPtr++ = ifd->multicastReadPendingEvent;
- *waitItemPtr++ = ifd->unicastReadPendingEvent;
+ *waitItemPtr++ = ifd->readPendingEvent;
}
*outWaitList = waitList;
mDNSlocal void ProcessingThreadProcessPacket( mDNS *inMDNS, mDNSInterfaceData *inIFD, SocketRef inSocketRef )
{
int n;
- mDNSBool isMulticast;
DNSMessage packet;
struct sockaddr_in addr;
int addrSize;
mDNSAddr dstAddr;
mDNSIPPort dstPort;
- isMulticast = (mDNSBool)( inSocketRef == inIFD->multicastSocketRef );
-
// Receive the packet.
addrSize = sizeof( addr );
srcAddr.ip.v4.NotAnInteger = addr.sin_addr.s_addr;
srcPort.NotAnInteger = addr.sin_port;
dstAddr.type = mDNSAddrType_IPv4;
- dstAddr.ip.v4 = isMulticast ? AllDNSLinkGroup : inIFD->hostSet.ip.ip.v4;
- dstPort = isMulticast ? MulticastDNSPort : UnicastDNSPort;
+ dstAddr.ip.v4 = AllDNSLinkGroup;
+ dstPort = MulticastDNSPort;
dlog( kDebugLevelChatty, DEBUG_NAME "packet received\n" );
dlog( kDebugLevelChatty, DEBUG_NAME " size = %d\n", n );
// Update counters.
- inIFD->recvMulticastCounter += isMulticast;
- inIFD->recvUnicastCounter += !isMulticast;
- inIFD->recvErrorCounter += ( n < 0 );
+ inIFD->recvCounter += 1;
+ inIFD->recvErrorCounter += ( n < 0 );
}
//===========================================================================================================================
require_action( size > 0, exit, err = -1 );
size *= 2;
- buffer = malloc( size );
+ buffer = calloc( 1, size );
require_action( buffer, exit, err = -1 );
// We now know the size of the list and have a buffer to hold so call WSAIoctl again to get it.
Change History (most recent first):
$Log: mDNSWin32.h,v $
+Revision 1.9.2.1 2004/04/03 05:26:08 bradley
+Integrated changes from TOT to remove legacy port 53 support.
+
+Revision 1.10 2003/10/24 23:23:02 bradley
+Removed legacy port 53 support as it is no longer needed.
+
Revision 1.9 2003/08/20 06:21:25 bradley
Updated to latest internal version of the Rendezvous for Windows platform plugin: Added support
for Windows CE/PocketPC 2003; re-did interface-related code to emulate getifaddrs/freeifaddrs for
{
mDNSInterfaceData * next;
char name[ 256 ];
- SocketRef multicastSocketRef;
- HANDLE multicastReadPendingEvent;
- SocketRef unicastSocketRef;
- HANDLE unicastReadPendingEvent;
+ SocketRef sock;
+ HANDLE readPendingEvent;
NetworkInterfaceInfo hostSet;
mDNSBool hostRegistered;
int sendUnicastCounter;
int sendErrorCounter;
- int recvMulticastCounter;
- int recvUnicastCounter;
+ int recvCounter;
int recvErrorCounter;
};