Dnia wtorek, 23 listopada 2004 17:23, Bill Fenner napisaĆ:
> >That's good to know. Attached patch adds possbility to set uDNS host name,
> >secret and public ip (this is temporary - i just don't know good method to
> >retrieve address of interface with default route).
>
> If you know an IP address that is reached by the route you want to
> use, you can connect a udp socket to that destination and then use
> getsockname() to get the IP source address your system would use to
> reach that destination - works on at least *BSD, Linux, Solaris >=2.6
> and doesn't involve any actual network traffic.
Thanks for this tip, it allows do to 'right thing' in almost all cases without
any configuration. Updated patch can read public IP from file. If it cannot
be parsed as IP, it will be treated as interface name - useful for dynamic
ip. If public IP still has not been determined it will be guessed by
checking source address for connection to 1.1.1.1 (anyone has better idea?)
Another important question for Marc: i hate to bother you when you are so busy
with preparation of new MacOSX, but can you give me approximate date when new
mDNSResponder is going to be packaged? KDE 3.4alpha 1 is scheduled for Dec
3rd, and I can't add CVS version (+patches to apply) of responder as new
dependency. Of course, if there is no other way, I can patch it, make tarball
and publish it somewhere for download myself.
>
> Bill
diff -urd mDNSResponder-mod/mDNSPosix/mDNSPosix.c mDNSResponder-modmod/mDNSPosix/mDNSPosix.c
--- mDNSResponder-mod/mDNSPosix/mDNSPosix.c 2004-11-13 11:24:26.000000000 +0100
+++ mDNSResponder-modmod/mDNSPosix/mDNSPosix.c 2004-11-24 19:46:05.000000000 +0100
@@ -590,7 +590,7 @@
// Searches the interface list looking for the named interface.
// Returns a pointer to if it found, or NULL otherwise.
-mDNSlocal PosixNetworkInterface *SearchForInterfaceByName(mDNS *const m, const char *intfName)
+PosixNetworkInterface *SearchForInterfaceByName(mDNS *const m, const char *intfName)
{
PosixNetworkInterface *intf;
diff -urd mDNSResponder-mod/mDNSPosix/mDNSPosix.h mDNSResponder-modmod/mDNSPosix/mDNSPosix.h
--- mDNSResponder-mod/mDNSPosix/mDNSPosix.h 2004-02-06 02:19:51.000000000 +0100
+++ mDNSResponder-modmod/mDNSPosix/mDNSPosix.h 2004-11-24 19:46:45.000000000 +0100
@@ -114,6 +114,7 @@
};
extern mStatus mDNSPlatformPosixRefreshInterfaceList(mDNS *const m);
+
// See comment in implementation.
// Call mDNSPosixGetFDSet before calling select(), to update the parameters
@@ -133,6 +134,8 @@
extern mStatus mDNSPosixIgnoreSignalInEventLoop( int signum);
extern mStatus mDNSPosixRunEventLoopOnce( mDNS *m, const struct timeval *pTimeout, sigset_t *pSignalsReceived, mDNSBool *pDataDispatched);
+PosixNetworkInterface *SearchForInterfaceByName(mDNS *const m, const char *intfName);
+
#ifdef __cplusplus
}
#endif
diff -urd mDNSResponder-mod/mDNSPosix/PosixDaemon.c mDNSResponder-modmod/mDNSPosix/PosixDaemon.c
--- mDNSResponder-mod/mDNSPosix/PosixDaemon.c 2004-11-20 14:51:47.000000000 +0100
+++ mDNSResponder-modmod/mDNSPosix/PosixDaemon.c 2004-11-24 19:48:20.000000000 +0100
@@ -106,6 +106,11 @@
static void Reconfigure( mDNS *m);
static mStatus MainLoop( mDNS *m);
+static domainname DynDNSZone; // Default wide-area zone for service registration
+static domainname DynDNSHostname;
+
+#define CONFIG_FILE "/etc/mdnsd.conf"
+
#define uDNS_SERVERS_FILE "/etc/dns-sd.resolv.conf"
#define RR_CACHE_SIZE 500
static CacheRecord gRRCache[RR_CACHE_SIZE];
@@ -156,6 +161,15 @@
return err;
}
+mDNSlocal void SCPrefsDynDNSCallback(mDNS *const m, AuthRecord *const rr, mStatus result)
+ {
+ (void)m; // unused
+
+
+ debugf("SCPrefsDynDNSCallback: result %d for registration of name %##s", result, rr->resrec.name.c);
+// SetDDNSNameStatus(&rr->resrec.name, result);
+ }
+
#ifdef NOT_HAVE_DAEMON
static int Daemon_Init( int nochdir, int noclose )
@@ -265,11 +279,109 @@
return (numOfServers > 0) ? 0 : -1;
}
+mDNSlocal mDNSBool GetConfigOption(char *dst, int dstlen, const char *option, FILE *f)
+ {
+ char buf[1024];
+ int len;
+
+ fseek(f, 0, SEEK_SET); // set position to beginning of stream
+ while (fgets(buf, 1024, f))
+ {
+ len = strlen(option);
+ if (!strncmp(buf, option, len))
+ {
+ strncpy(dst, buf + len + 1,dstlen-1);
+ dst[dstlen-1] = '\0'; // just to be safe
+ len = strlen(dst);
+ if ( len && dst[len-1] == '\n') dst[len-1] = '\0'; // chop newline
+ return mDNStrue;
+ }
+ }
+ debugf("Option %s not set", option);
+ return mDNSfalse;
+ }
+
+mDNSlocal void ReadDDNSSettingsFromConfFile(mDNS *const m)
+ {
+ char zone[MAX_ESCAPED_DOMAIN_NAME], fqdn[MAX_ESCAPED_DOMAIN_NAME];
+ char secret[1024], primary[16];
+ mDNSAddr DynDNSIP;
+ int slen;
+ mStatus err;
+ FILE *f = NULL;
+
+ secret[0] = 0;
+ DynDNSZone.c[0] = 0;
+ DynDNSHostname.c[0] = 0;
+ DynDNSIP = zeroAddr;
+ DynDNSIP.type=mDNSAddrType_IPv4;
+ mDNS_SetPrimaryInterfaceInfo(m, &DynDNSIP, NULL);
+
+ f = fopen(CONFIG_FILE, "r");
+ if (f)
+ {
+ if (GetConfigOption(fqdn,MAX_ESCAPED_DOMAIN_NAME, "hostname", f) && !MakeDomainNameFromDNSNameString(&DynDNSHostname, fqdn)) goto badf;
+ if (GetConfigOption(primary, 16, "publicinterface", f))
+ if (!inet_aton(primary, &DynDNSIP.ip.v4))
+ {
+ PosixNetworkInterface *interface = SearchForInterfaceByName(m, primary);
+ if (interface && interface->coreIntf.IPv4Available) DynDNSIP.ip.v4 = interface->coreIntf.ip.ip.v4;
+ }
+ if (GetConfigOption(zone,MAX_ESCAPED_DOMAIN_NAME,"zone", f) && !MakeDomainNameFromDNSNameString(&DynDNSZone, zone)) goto badf;
+ GetConfigOption(secret,1024,"secret-64", f); // failure means no authentication
+ fclose(f);
+ f = NULL;
+ }
+ else
+ {
+ if (errno != ENOENT) LogMsg("ERROR: Config file exists, but cannot be opened.");
+ return;
+ }
+
+ if (secret[0])
+ {
+ // for now we assume keyname = service reg domain and we use same key for service and hostname registration
+ slen = strlen(secret);
+ err = mDNS_SetSecretForZone(m, &DynDNSZone, &DynDNSZone, secret, slen, mDNStrue);
+ if (err) LogMsg("ERROR: mDNS_SetSecretForZone returned %d for domain %##s", err, DynDNSZone.c);
+ }
+
+ // Note - set secret *before* passing hostname/zone to core
+// if (DynDNSZone.c[0]) AddDefRegDomain(&DynDNSZone); //set default (empty-string) service registration domain
+ if (DynDNSHostname.c[0]) mDNS_AddDynDNSHostName(m, &DynDNSHostname, SCPrefsDynDNSCallback, NULL);
+ if (mDNSAddressIsZero(&DynDNSIP))
+ {
+ // try default route
+ struct sockaddr_in addr;
+ socklen_t len = sizeof(addr);
+ int sock = socket(AF_INET,SOCK_DGRAM,0);
+ if (sock==-1) return;
+ addr.sin_family = AF_INET;
+ // not important, any port and public address will do
+ addr.sin_port = 1;
+ addr.sin_addr.s_addr = 0x01010101;
+ if ( (connect(sock,(const struct sockaddr*)&addr,sizeof(addr))) == -1) return;
+ if ( (getsockname(sock,(struct sockaddr*)&addr,&len)) == -1) return;
+ close(sock);
+ DynDNSIP.ip.v4.NotAnInteger = (mDNSu32)addr.sin_addr.s_addr;
+ }
+ mDNS_SetPrimaryInterfaceInfo(m, &DynDNSIP, NULL);
+
+ return;
+
+ badf:
+ LogMsg("ERROR: malformatted config file");
+ if (f) fclose(f);
+ }
+
+
+
static void Reconfigure( mDNS *m)
{
mDNS_DeregisterDNSList(m);
if (ParseDNSServers( m, uDNS_SERVERS_FILE) < 0)
LogMsg("Unable to parse DNS server list. Unicast DNS-SD unavailable");
+ ReadDDNSSettingsFromConfFile(m);
}
static void DumpStateLog(mDNS *const m)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Rendezvous-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/rendezvous-dev/email@hidden
This email sent to email@hidden