Subject: error reports and DNS lookups

From: Eugene Crosser <[email-masked]>
Date: 27 Nov 2002 18:01:47 +0300

Following up my previous mail.  The culprit was sfmail_open() that calls
getmyhostname() which in turn calles getaddrinfo() every time.  I wonder
if it is OK to store canonic host name in a static buffer?

Index: libc/myhostname.c
===================================================================
RCS file: /cvsroot/zmailer/libc/myhostname.c,v
retrieving revision 1.6
diff -u -r1.6 myhostname.c
--- libc/myhostname.c	2000/11/16 16:58:41	1.6
+++ libc/myhostname.c	2002/11/27 14:57:31
@@ -23,8 +23,8 @@
 #endif
 #include "libc.h"
 
-int
-getmyhostname(namebuf, len)
+static int
+_getmyhostname(namebuf, len)
 	char *namebuf;
 	int len;
 {
@@ -130,4 +130,25 @@
 #endif
 	return 0;
 #endif
+}
+
+int
+getmyhostname(namebuf, len)
+	char *namebuf;
+	int len;
+{
+	int rc;
+	static char *savedname=NULL;
+
+	if (savedname) {
+		strncpy(namebuf, savedname, len);
+		namebuf[len - 1] = 0;
+		return 0;
+	}
+	rc = _getmyhostname(namebuf, len);
+	if (rc == 0) {
+		savedname=(char*)malloc(strlen(namebuf)+1);
+		strcpy(savedname, namebuf);
+	}
+	return rc;
 }

-- 
Eugene Crosser, head of Internet Applications section, +7 501 787 1000
ROL, Teleross, Golden Telecom, http://user.rol.ru/~crosser/

-
To unsubscribe from this list: send the line "unsubscribe zmailer" in
the body of a message to [email-masked]