Index: erq.c
===================================================================
--- erq.c	(revision 2308)
+++ erq.c	(working copy)
@@ -108,6 +108,7 @@
 #endif
 
 #include "erq.h"
+#include "srv.c"
 
 #define randomize_tickets(n) srandom(n)
 #define get_ticket()         random()
@@ -1172,7 +1173,75 @@
                 break;
               }
 #endif /* ERQ_RLOOKUPV6 */
+#ifdef ERQ_LOOKUP_SRV
+	case ERQ_LOOKUP_SRV:
+	      {
+		/* lookup list of srv records */
+		struct srvhost * r;
+		struct srvhost * s;
+		char service[50], proto[20], hostname[200];
+		int counter;
+		char srvbuf[MAX_REPLY];
+		
+		header[8] = CHILD_FREE;
+		counter = 0;
+		srvbuf[0] = '\0';
+		// TODO: sscanf this from req string
+		// format: <service>.<proto>.<hostname>
+		// example: _psyc._tcp.ve.symlynX.com
+		// getsrv(hostname, service, proto)
+		memcpy(header + 9, buf, msglen);
+		buf[msglen] = '\0';
+		sscanf(buf, "%49[^.].%19[^.].%199s", service, proto, hostname);
+#if ERQ_DEBUG > 0
+		fprintf(stderr, "%s: ERQ_LOOKUP_SRV '%s', %s,%s,%s\n", time_stamp(), buf, service, proto, hostname);
+#endif
+		r = getsrv(hostname, service, proto);
+		if (!r) {
+		    /* lookup failed, send empty message*/
+		    write_32(header, 8);
+		    write1(header, 9);
+#if ERQ_DEBUG > 0
+		    fprintf(stderr, "%s: ERQ_LOOKUP_SRV could not srv_resolve '%s'\n", time_stamp(), buf);
+#endif
+		    break;
+		} else {
+		    s = r;
+		    while (s) {
+			/* walk list of structures */
+		        /* important members: name, port, pref, weight */
+			if (strlen(srvbuf) < MAX_REPLY - 1) {
+			    strncat(srvbuf, s -> name, MAX_REPLY - strlen(srvbuf));
+			    strncat(srvbuf, "\n", MAX_REPLY - strlen(srvbuf));
+			    
+			    
+			   if (strlen(srvbuf) < MAX_REPLY - 1) {
+			       snprintf(hostname, MAX_REPLY - 1, "%d%c", s -> port, '\n');
+			       strncat(srvbuf, hostname, MAX_REPLY - strlen(srvbuf));
+			       
+				if (strlen(srvbuf) < MAX_REPLY - 1) {
+				    snprintf(hostname, MAX_REPLY - 1, "%d%c", s -> pref, '\n');
+				    strncat(srvbuf, hostname, MAX_REPLY - strlen(srvbuf));
+				    if (strlen(srvbuf) < MAX_REPLY - 1) {
+					snprintf(hostname, MAX_REPLY - 1, "%d%c", s -> weight, '\n');
+					strncat(srvbuf, hostname, MAX_REPLY - strlen(srvbuf));
+				    } else s = NULL;
+				} else s = NULL;
+			   } else s = NULL;
+			} else s = NULL;
+			
+			s = s -> next;
+			counter++;
+		    }
+		    freesrvhost(r);
+		}
+		write_32(header, strlen(srvbuf) + 9);
+		write1(header, 9);
+		write1(srvbuf, strlen(srvbuf) + 1);
 
+		break;
+	      }
+#endif /* ERQ_LOOKUP_SRV */
         case ERQ_EXECUTE:
           {
             /* Execute a program, wait for its termination and
Index: erq.h
===================================================================
--- erq.h	(revision 2308)
+++ erq.h	(working copy)
@@ -21,6 +21,7 @@
 #ifdef __IPV6__
 #define ERQ_RLOOKUPV6  12  /* Lookup name/ip6 */
 #endif
+#define ERQ_LOOKUP_SRV 13
 
 /* Additional service request type flags evaluated by efun send_erq().
  * The ERQ itself won't get to see it.

