Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Fix djbdns-1.05 to run correctly under inetd/skd/socat instead of daemontools
diff --git a/axfrdns.c b/axfrdns.c
index 7079850..b63cb58 100644
--- a/axfrdns.c
+++ b/axfrdns.c
@@ -1,3 +1,5 @@
+#include <sys/socket.h>
+#include <netinet/in.h>
#include <unistd.h>
#include "droproot.h"
#include "exit.h"
@@ -320,22 +322,22 @@ int main()
char header[12];
char qtype[2];
char qclass[2];
- const char *x;
+ struct sockaddr_in ra;
+ size_t rasize = sizeof(ra);
droproot(FATAL);
dns_random_init(seed);
axfr = env_get("AXFR");
-
- x = env_get("TCPREMOTEIP");
- if (x && ip4_scan(x,ip))
- ;
- else
- byte_zero(ip,4);
- x = env_get("TCPREMOTEPORT");
- if (!x) x = "0";
- scan_ulong(x,&port);
+ if ((getpeername(0, (struct sockaddr *) &ra, &rasize) == 0)
+ && (ra.sin_family == AF_INET)) {
+ byte_copy(ip, 4, (char *) &ra.sin_addr);
+ port = ra.sin_port;
+ } else {
+ byte_zero(ip, 4);
+ port = 0;
+ }
for (;;) {
netread(tcpheader,2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment