File: getdomain.c

package info (click to toggle)
mutt 0.91.2-2
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 2,056 kB
  • ctags: 2,189
  • sloc: ansic: 34,582; sh: 203; makefile: 197; perl: 21; awk: 2
file content (55 lines) | stat: -rw-r--r-- 927 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>
#include <ctype.h>
#include <string.h>

#include "mutt.h"
#include "protos.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);
}