diff options
author | Thomas Roessler <roessler@does-not-exist.org> | 1998-06-08 09:16:03 +0000 |
---|---|---|
committer | Thomas Roessler <roessler@does-not-exist.org> | 1998-06-08 09:16:03 +0000 |
commit | 1a5381e07e97fe482c2b3a7c75f99938f0b105d4 (patch) | |
tree | b4fa4088bbbf5fc9217ee6f87ab60034175e6899 /getdomain.c |
Initial revision
Diffstat (limited to 'getdomain.c')
-rw-r--r-- | getdomain.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/getdomain.c b/getdomain.c new file mode 100644 index 00000000..70c8e88f --- /dev/null +++ b/getdomain.c @@ -0,0 +1,54 @@ +#include <stdio.h> +#include <ctype.h> +#include <string.h> + +#include "mutt.h" + +#ifndef STDC_HEADERS +int fclose (); +#endif + +/* poor man's version of getdomainname() for systems where it does not return + * return the DNS domain, but the NIS domain. + */ + +int getdnsdomainname (char *s, size_t l) +{ + FILE *f; + char tmp[1024]; + char *p = NULL; + + if ((f = fopen ("/etc/resolv.conf", "r")) == NULL) return (-1); + + tmp[sizeof (tmp) - 1] = 0; + + l--; /* save room for the terminal \0 */ + + while (fgets (tmp, sizeof (tmp) - 1, f) != NULL) + { + p = tmp; + while (ISSPACE (*p)) p++; + if (strncmp ("domain", p, 6) == 0 || strncmp ("search", p, 6) == 0) + { + p += 6; + while (ISSPACE (*p)) p++; + + if (*p) + { + while (*p && !ISSPACE (*p) && l > 0) + { + *s++ = *p++; + l--; + } + if (*(s-1) == '.') s--; + *s = 0; + + fclose (f); + return (0); + } + } + } + + fclose (f); + return (-1); +} |