Read the PORT environment variable to find out what port dnscache/tinydns
should use for incoming requests.  Defaults to 53.

For example:
echo 5300 > /etc/dnscache/env/PORT
echo 5300 > /etc/tinydns/env/PORT

--- server.c.orig	2001-02-11 21:11:45.000000000 +0000
+++ server.c	2006-11-01 15:32:42.000000000 +0000
@@ -82,6 +82,7 @@
 int main()
 {
   char *x;
+  unsigned long p;
   int udp53;
 
   x = env_get("IP");
@@ -90,10 +91,21 @@
   if (!ip4_scan(x,ip))
     strerr_die3x(111,fatal,"unable to parse IP address ",x);
 
+  x = env_get("PORT");
+  p = 0;
+  if (x)
+  {
+    if (!scan_ulong(x,&p))
+      strerr_die3x(111,fatal,"unable to parse port number ",x);
+    if (p>65535)
+      strerr_die3x(111,fatal,"invalid port number ",x);
+  }
+  if (!p) p = 53;
+
   udp53 = socket_udp();
   if (udp53 == -1)
     strerr_die2sys(111,fatal,"unable to create UDP socket: ");
-  if (socket_bind4_reuse(udp53,ip,53) == -1)
+  if (socket_bind4_reuse(udp53,ip,p) == -1)
     strerr_die2sys(111,fatal,"unable to bind UDP socket: ");
 
   droproot(fatal);
--- dnscache.c.orig	2001-02-11 21:11:45.000000000 +0000
+++ dnscache.c	2006-11-01 15:31:51.000000000 +0000
@@ -389,6 +389,7 @@
 int main()
 {
   char *x;
+  unsigned long p;
   unsigned long cachesize;
 
   x = env_get("IP");
@@ -397,16 +398,27 @@
   if (!ip4_scan(x,myipincoming))
     strerr_die3x(111,FATAL,"unable to parse IP address ",x);
 
+  x = env_get("PORT");
+  p = 0;
+  if (x)
+  {
+    if (!scan_ulong(x,&p))
+      strerr_die3x(111,FATAL,"unable to parse port number ",x);
+    if (p>65535)
+      strerr_die3x(111,FATAL,"invalid port number ",x);
+  }
+  if (!p) p = 53;
+
   udp53 = socket_udp();
   if (udp53 == -1)
     strerr_die2sys(111,FATAL,"unable to create UDP socket: ");
-  if (socket_bind4_reuse(udp53,myipincoming,53) == -1)
+  if (socket_bind4_reuse(udp53,myipincoming,p) == -1)
     strerr_die2sys(111,FATAL,"unable to bind UDP socket: ");
 
   tcp53 = socket_tcp();
   if (tcp53 == -1)
     strerr_die2sys(111,FATAL,"unable to create TCP socket: ");
-  if (socket_bind4_reuse(tcp53,myipincoming,53) == -1)
+  if (socket_bind4_reuse(tcp53,myipincoming,p) == -1)
     strerr_die2sys(111,FATAL,"unable to bind TCP socket: ");
 
   droproot(FATAL);
