On Fri, 16 Jun 2006, Don Russell wrote:
DR>
DR> Maybe I can suggest a change to host/dig people to include a return
DR> code.... but I suspect that won't be well received...
DR>
DR>
DR> Cheers,
DR> Don
DR>
A wrapper around gethostbyname might do. Here is one I've cobbled
together:
<--------------- cut here ------------------->
#include <stdio.h>
#include <netdb.h>
/*
usage: gethostname hostname.domain.tld
returns 0 if the host found
*/
extern int h_errno;
int main (int argc, char ** argv) {
struct hostent *answer_p;
int answer = 1;
if (argc < 2 ) {
fprintf(stderr, "%s\n",
"usage: gethostname hostname.domain.tld");
}
else {
answer_p = gethostbyname(argv[1]);
if (NULL == answer_p) answer = 1; /* error */
else answer = 0; /* host found */
fprintf(stderr, "answer = %d\n", answer);
}
return answer;
}
<--------------- cut here ------------------->
Save as: gethostname.c
compile on linux with: gcc -o gethostname gethostname.c (or whatever makes
the executable smaller)
check my laptop: ./gethostname pomade.clifford.ac
result:
alan(_at_)nard:~/temp$ ./gethostname pomade.clifford.ac
answer = 0
You might want to comment out the fprintf's but, if I remember, stderr
output will go into the procmail log.
gethostbyname returns various stuff that might be useful to return as
error codes instead of just 0 or 1: see man gethostbyname
--
Alan
( Please do not email me AS WELL as replying to the list. Please
address personal email to alan+1@ as lists@ is not read. A
password autoresponder may be invoked if this email is very old. )
____________________________________________________________
procmail mailing list Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail