aboutsummaryrefslogtreecommitdiffstats
path: root/fetchmail.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1998-08-02 18:43:17 +0000
committerEric S. Raymond <esr@thyrsus.com>1998-08-02 18:43:17 +0000
commit56f2f5e7a800ec59ae8d027a6c551ebf84fbda94 (patch)
tree5ad8b388e06b8fee5d73de1f7573e2418a92b8a0 /fetchmail.c
parent1587e4153763fab493acf2deee9028e24e1da57f (diff)
downloadfetchmail-56f2f5e7a800ec59ae8d027a6c551ebf84fbda94.tar.gz
fetchmail-56f2f5e7a800ec59ae8d027a6c551ebf84fbda94.tar.bz2
fetchmail-56f2f5e7a800ec59ae8d027a6c551ebf84fbda94.zip
Eliminate agethostbyname call in non-ETRN modes.
svn path=/trunk/; revision=2033
Diffstat (limited to 'fetchmail.c')
-rw-r--r--fetchmail.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/fetchmail.c b/fetchmail.c
index bc841b28..912fdb7b 100644
--- a/fetchmail.c
+++ b/fetchmail.c
@@ -67,7 +67,6 @@ flag check_only; /* if --probe was set */
flag versioninfo; /* emit only version info */
char *user; /* the name of the invoking user */
char *home; /* invoking user's home directory */
-char *fetchmailhost; /* the name of the host running fetchmail */
char *program_name; /* the name to prefix error messages with */
flag configdump; /* dump control blocks for configurator */
@@ -839,13 +838,48 @@ static int load_params(int argc, char **argv, int optind)
/* make sure we have a nonempty host list to forward to */
if (!ctl->smtphunt)
{
- save_str(&ctl->smtphunt, fetchmailhost, FALSE);
- /* for non ETRN try to deliver mails to localhost if
- * fetchmailhost fails
+ char tmpbuf[HOSTLEN+1];
+ /*
+ * If we're using ETRN, the smtp hunt list is the list of
+ * systems we're polling on behalf of; these have to be
+ * fully-qualified domain names. The default for this list
+ * should be the FQDN of localhost.
*/
- if (ctl->server.protocol != P_ETRN) {
- save_str(&ctl->smtphunt, "localhost", FALSE);
+ if (ctl->server.protocol == P_ETRN)
+ {
+ char *fetchmailhost;
+
+ if (gethostname(tmpbuf, sizeof(tmpbuf)))
+ {
+ fprintf(stderr, "%s: can't determine your host!",
+ program_name);
+ exit(PS_DNS);
+ }
+#ifdef HAVE_GETHOSTBYNAME
+ /* if we got a . in the hostname assume it is a FQDN */
+ if (strchr(tmpbuf, '.') == NULL)
+ {
+ struct hostent *hp;
+
+ /* if we got a basename (as we do in Linux) make a FQDN of it */
+ hp = gethostbyname(tmpbuf);
+ if (hp == (struct hostent *) NULL)
+ {
+ /* exit with error message */
+ fprintf(stderr,
+ "gethostbyname failed for %s\n", tmpbuf);
+ exit(PS_DNS);
+ }
+ fetchmailhost = xstrdup(hp->h_name);
+ }
+ else
+#endif /* HAVE_GETHOSTBYNAME */
+ fetchmailhost = xstrdup(tmpbuf);
+
+ save_str(&ctl->smtphunt, fetchmailhost, FALSE);
}
+ else
+ save_str(&ctl->smtphunt, "localhost", FALSE);
}
/* keep lusers from shooting themselves in the foot :-) */