ldmud-3.3.719/
ldmud-3.3.719/doc/
ldmud-3.3.719/doc/efun.de/
ldmud-3.3.719/doc/efun/
ldmud-3.3.719/doc/man/
ldmud-3.3.719/doc/other/
ldmud-3.3.719/mud/
ldmud-3.3.719/mud/heaven7/
ldmud-3.3.719/mud/lp-245/
ldmud-3.3.719/mud/lp-245/banish/
ldmud-3.3.719/mud/lp-245/doc/
ldmud-3.3.719/mud/lp-245/doc/examples/
ldmud-3.3.719/mud/lp-245/doc/sefun/
ldmud-3.3.719/mud/lp-245/log/
ldmud-3.3.719/mud/lp-245/obj/Go/
ldmud-3.3.719/mud/lp-245/players/lars/
ldmud-3.3.719/mud/lp-245/room/death/
ldmud-3.3.719/mud/lp-245/room/maze1/
ldmud-3.3.719/mud/lp-245/room/sub/
ldmud-3.3.719/mud/lp-245/secure/
ldmud-3.3.719/mud/sticklib/
ldmud-3.3.719/mud/sticklib/src/
ldmud-3.3.719/mudlib/deprecated/
ldmud-3.3.719/mudlib/uni-crasher/
ldmud-3.3.719/pkg/
ldmud-3.3.719/pkg/debugger/
ldmud-3.3.719/pkg/diff/
ldmud-3.3.719/pkg/misc/
ldmud-3.3.719/src/
ldmud-3.3.719/src/autoconf/
ldmud-3.3.719/src/ptmalloc/
ldmud-3.3.719/src/util/
ldmud-3.3.719/src/util/erq/
ldmud-3.3.719/src/util/indent/hosts/next/
ldmud-3.3.719/src/util/xerq/
ldmud-3.3.719/src/util/xerq/lpc/
ldmud-3.3.719/src/util/xerq/lpc/www/
ldmud-3.3.719/test/generic/
ldmud-3.3.719/test/inc/
ldmud-3.3.719/test/t-0000398/
ldmud-3.3.719/test/t-0000548/
ldmud-3.3.719/test/t-030925/
ldmud-3.3.719/test/t-040413/
ldmud-3.3.719/test/t-041124/
ldmud-3.3.719/test/t-language/
void
dns_resolve (string hostname, closure callback)

// Try to lookup the IP for the fully qualified <hostname> using direct ERQ
// communication. Once the name is resolved, call callback() with the
// resolved name as parameter.
//
// Note: If the ERQ is unavailable, callback() is called with the original
// hostname.
//
// preferably to be installed as "simul efun." latest version available
// in world/net/library.i of psycMUVE (download from http://muve.pages.de)
// this version runs with broken and fixed erq's alike.
//
// Written by Tobias@Heldensaga and Arne@Elridion.

{
	closure c;

	if (sscanf(hostname,"%~D.%~D.%~D.%~D") == 4) {
	    // hostname is an IP already. Just call the callback.
	    funcall(callback, hostname);
	    return;
	}
	
       	c = lambda( ({ 'name }), ({ 
	(#'switch), ({ #'sizeof, 'name }),
	({ 4 }), // ERQ: name resolved!
	({ (#',),
		({ (#'=),'name,({ (#'map),'name,#'&,255 }) }),
		({ (#'=),'name,
		 ({
			(#'sprintf),"%d.%d.%d.%d",
						({ #'[, 'name, 0 }),
						({ #'[, 'name, 1 }),
						({ #'[, 'name, 2 }),
						({ #'[, 'name, 3 })
		  })
		 }),
		({ (#'funcall), callback, 'name })
	}),
	(#'break),
	({ 6 + strlen(hostname) }), // XERQ
	({ (#',),
                ({ (#'=),'name,({ (#'map),'name,#'&,255 }) }),
                ({ (#'=),'name,
                 ({
                        (#'sprintf),"%d.%d.%d.%d",
                                                ({ #'[, 'name, 1
}),
                                                ({ #'[, 'name, 2
}),
                                                ({ #'[, 'name, 3
}),
                                                ({ #'[, 'name, 4 })
                  })
                 }),
                ({ (#'funcall), callback, 'name })
        }),
	(#'break),
	({ #'default }),
	({
	 #'debug_message, "FATAL: ERQ could not resolve \""
		 + hostname + "\". The callback will not be called.\n"
		 }),
	(#'break)
	})
					);
#ifdef THEDAYWEARESURENOONERUNSABUGGYERQ
	if (!send_erq(ERQ_LOOKUP, hostname, c))
#else
	// appending the zero byte fixes a bug in erq. sick!
	if (!send_erq(ERQ_LOOKUP, to_array(hostname) + ({ 0 }), c))
#endif
	{
	    // if we cannot resolve using erq, we'll send back the hostname,
	    // so the driver can do a blocking resolve itself (needed for
	    // net_connect())
	    funcall(callback, hostname);
	}
}

#if 0

/*------------------------------------------------------------------------*/
// typical usage example taken from PSYCmuve world/net/irc/gatebot.c
// this ensures a non-blocking connect to a remote service even by name.
//
connect(host, port) {
	unless (host) host = IRCNET_HOST;
	unless (port) port = IRCNET_PORT;
	D2( D("IRCgate resolving hostname "+ host +"\n"); )
	dns_resolve(host, lambda(({ 'result }),
				 ({ #'connect2, 'result, port })));
}
connect2(host, port) {
#if __EFUN_DEFINED__(net_connect)
	int res;

	D0( D(S("IRCgate attempting connect to %O:%O\n", host, port)); )
	res = net_connect(host, port);
	if (res) monitor_report("_failure_network_connect_call",
		     "ircbot: connect to "+host+" returns "+ res);
	return res;
#else
	D2( D("IRCgate * Oh, driver does not provide net_connect()\n"); )
	return -9;
#endif
}

#endif /* EXAMPLE */