diff -Naur distcc-2.18.3/Makefile.in distcc-2.18.3-new/Makefile.in
--- distcc-2.18.3/Makefile.in	2004-10-23 22:05:48.000000000 -0700
+++ distcc-2.18.3-new/Makefile.in	2005-09-16 14:24:35.000000000 -0700
@@ -189,6 +189,8 @@
 	src/serve.o src/setuid.o src/srvnet.o src/srvrpc.o src/state.o	\
 	$(common_obj) @BUILD_POPT@
 
+lsdistcc_obj = src/lsdistcc.o
+
 # Objects that need to be linked in to build monitors
 mon_obj =								\
 	src/cleanup.o							\
@@ -228,7 +230,7 @@
 	src/h_sa2str.c src/h_scanargs.c src/h_strip.c			\
 	src/help.c src/history.c src/hosts.c src/hostfile.c		\
 	src/implicit.c src/io.c						\
-	src/loadfile.c src/lock.c 					\
+	src/loadfile.c src/lock.c src/lsdistcc.c			\
 	src/mon.c src/mon-notify.c src/mon-text.c			\
 	src/mon-gnome.c							\
 	src/ncpus.c src/netutil.c					\
@@ -291,6 +293,7 @@
 	distcc@EXEEXT@ \
 	distccd@EXEEXT@ \
 	distccmon-text@EXEEXT@ \
+	lsdistcc@EXEEXT@ \
 	@GNOME_BIN@ 
 
 check_PROGRAMS = \
@@ -339,6 +342,9 @@
 distccmon-text@EXEEXT@: $(mon_obj) src/mon-text.o
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(mon_obj) src/mon-text.o $(LIBS)
 
+lsdistcc@EXEEXT@: $(lsdistcc_obj)
+	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(lsdistcc_obj)
+
 h_exten@EXEEXT@: $(h_exten_obj)
 	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(h_exten_obj) $(LIBS)
 
diff -Naur distcc-2.18.3/src/lsdistcc.c distcc-2.18.3-new/src/lsdistcc.c
--- distcc-2.18.3/src/lsdistcc.c	1969-12-31 16:00:00.000000000 -0800
+++ distcc-2.18.3-new/src/lsdistcc.c	2005-09-16 17:13:38.000000000 -0700
@@ -0,0 +1,220 @@
+/* -*- c-file-style: "java"; indent-tabs-mode: nil -*-
+ * 
+ * lsdistcc -- A simple distcc server discovery program
+ *
+ * Copyright (C) 2005 by Google
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ *
+ * Program to autodetect listening distcc servers by looking in DNS
+ * for hosts named according to a given format.
+ * hosts are considered good servers based solely on whether their
+ * name fits the format and whether they are listening on the right port. 
+ * Stops looking for servers after the first one it doesn't find in DNS.
+ * Prints results to stdout.
+ * Terminates with error status if no servers found.
+ * 
+ * Examples:
+ * 
+ * In your build script, add the lines
+ *   DISTCC_HOSTS=`lsdistcc`
+ *   export DISTCC_HOSTS
+ * before the line that invokes make.
+ *  
+ * Or, in your Makefile, add the lines
+ *   export DISTCC_HOSTS = $(shell lsdistcc) 
+ *
+ * Changelog:
+ * Fri Sep 16 2005 - Dan Kegel, Google 
+ *  Created
+ *  Added -v option
+--------------------------------------------------------------------------*/
+
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <signal.h>
+
+/* Types */
+enum check_result { CHECK_FAIL, CHECK_NONAME, CHECK_NOLISTEN, CHECK_OK };
+
+/* Forward declarations (solely to prevent compiler warnings) */
+void usage(void);
+enum check_result check_name(const char *name, int port, unsigned char ipaddr[4], int verbose);
+void timeout_handler(int x);
+int detect_distcc_servers(const char *sformat, int port, int numeric, int timeout, int verbose);
+
+int g_verbose = 0;
+
+void usage(void) {
+	printf("Usage: lsdistcc [-ttimeout] [-n] [-v] [format]\n\
+Uses 'for i=1... sprintf(format, i)' to construct names of servers,\n\
+stops after 5 seconds or at first server that doesn't resolve,\n\
+prints the names of all such servers listening on distcc's port.\n\
+Default format is distcc%%d.\n\
+Options:\n\
+-n        Print IP address rather than name\n\
+-ttimeout Set number of seconds to stop searching after [5]\n\
+-v        verbose\n\
+");
+	exit(1);
+}
+
+enum check_result check_name(const char *name, int port, unsigned char ipaddr[4], int verbose)
+{
+    int err;
+    int s;
+    struct sockaddr_in sa;
+    struct hostent *he;
+
+    if ((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
+	perror("socket");
+	return CHECK_FAIL;
+    }
+
+    memset(&sa, 0, sizeof sa);
+
+    sa.sin_family = AF_INET;
+    sa.sin_port = htons(port);
+
+    if (verbose > 0)
+	fprintf(stderr, "Calling gethostbyname(%s)\n", name);
+    if ((he = gethostbyname(name)) == NULL) {
+        if (verbose > 0)
+	    fprintf(stderr, "gethostbyname(%s) failed\n", name);
+	close(s);
+	return CHECK_NONAME;
+    }
+
+    memcpy(&sa.sin_addr, he->h_addr_list[0], (size_t) he->h_length);
+    memcpy(ipaddr, he->h_addr_list[0], (size_t) he->h_length);
+
+    if (verbose > 0)
+	fprintf(stderr, "Connecting to %s\n", name);
+    err = connect(s, (struct sockaddr *) &sa, sizeof sa);
+    if ((verbose > 0) && err)
+	fprintf(stderr, "Connecting to %s failed\n", name);
+
+    close(s);
+
+    return err ? CHECK_NOLISTEN : CHECK_OK;
+}
+
+/* On timeout, silently terminate program  */
+void timeout_handler(int x)
+{
+	(void) x;
+
+	if (g_verbose > 0)
+		fprintf(stderr, "Timeout!\n");
+
+	/* FIXME: is it legal to call exit here? */
+	exit(0);
+}
+
+/* Detect all listening distcc servers and print their names to stdout.
+ * Looks for servers numbered 1 through infinity, stops at
+ * first server that doesn't resolve in DNS, or after 'timeout' seconds,
+ * whichever comes first.
+ * On entry:
+ *  sformat: format of names of distcc servers to check
+ *  port:    port number distcc servers listen on
+ *  numeric: whether to print the IP address instead of the hostname
+ *  timeout: how many seconds to terminate slow run after 
+ *  verbose: whether to print verbose log
+ * On exit:
+ *  returns number of servers found.
+ */
+int detect_distcc_servers(const char *sformat, int port, int numeric, int timeout, int verbose)
+{
+    int i;
+    int nfound;
+
+    if (verbose > 0)
+	fprintf(stderr, "Setting timeout to %d seconds\n", timeout);
+
+    /* Don't run longer than timeout seconds */
+    signal(SIGALRM, timeout_handler);
+    alarm((unsigned) timeout);
+
+    /* use TCP for DNS lookups */
+    sethostent(1);
+
+    for (i=1, nfound=0;; i++) {
+	char name[1024];
+        unsigned char ipaddr[4];
+	enum check_result res;
+	sprintf(name, sformat, i);
+	res = check_name(name, port, ipaddr, verbose);
+	if (res == CHECK_OK) {
+            nfound++;
+            if (numeric)
+		printf("%u.%u.%u.%u\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]);
+	    else
+	        puts(name);
+        }
+	if (res == CHECK_NONAME)
+	    break;
+	if (res == CHECK_FAIL) {
+	    fprintf(stderr, "Out of resources?!\n");
+	    break;
+	}
+    }
+
+    endhostent();
+
+    return nfound;
+}
+
+int main(int argc, char **argv)
+{
+    const char *sformat;
+    int opt_numeric = 0;
+    int opt_port = 3632;
+    int opt_timeout = 5;
+    int opt_verbose = 0;
+    int opti;
+    int nfound;
+
+    for (opti = 1; opti < argc && argv[opti][0] == '-'; opti++) {
+	switch (argv[opti][1]) {
+	case 't':
+	    opt_timeout = atoi(argv[opti]+2);
+	    break;
+	case 'n':
+	    opt_numeric = 1;
+	    break;
+	case 'v':
+	    opt_verbose++;
+	    break;
+	default:
+	    usage();
+	}
+    }
+    g_verbose = opt_verbose;
+
+    if (opti < argc)
+	sformat = argv[opti++];
+    else
+	sformat = "distcc%d";
+
+    nfound = detect_distcc_servers(sformat, opt_port, opt_numeric, opt_timeout, opt_verbose);
+
+    /* return failure if no servers found */
+    return (nfound > 0) ? 0 : 1;
+}
