NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
getdomain.c File Reference

DNS lookups. More...

#include "config.h"
#include <assert.h>
#include <netdb.h>
#include <string.h>
#include <sys/socket.h>
#include <time.h>
#include <unistd.h>
#include "mutt/lib.h"
#include "lib.h"
+ Include dependency graph for getdomain.c:

Go to the source code of this file.


static struct addrinfo * mutt_getaddrinfo (const char *node, const struct addrinfo *hints)
 Lookup the host's name using getaddrinfo() More...
int getdnsdomainname (struct Buffer *result)
 Lookup the host's name using DNS. More...

Detailed Description

DNS lookups.

  • Derek Martin

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see

Definition in file getdomain.c.

Function Documentation

◆ mutt_getaddrinfo()

static struct addrinfo* mutt_getaddrinfo ( const char *  node,
const struct addrinfo *  hints 

Lookup the host's name using getaddrinfo()

nodeHostname, got by gethostname()
hintsFlags to pass to getaddrinfo()
Return values
ptrAddress info
Caller must free result

Definition at line 96 of file getdomain.c.

97 {
98  assert(node);
99  assert(hints);
100  struct addrinfo *result = NULL;
101  mutt_debug(LL_DEBUG3, "before getaddrinfo\n");
102  int rc = getaddrinfo(node, NULL, hints, &result);
103  mutt_debug(LL_DEBUG3, "after getaddrinfo\n");
105  if (rc != 0)
106  result = NULL;
108  return result;
109 }
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
Log at debug level 3.
Definition: logging.h:42
+ Here is the caller graph for this function:

◆ getdnsdomainname()

int getdnsdomainname ( struct Buffer result)

Lookup the host's name using DNS.

resultBuffer were result of the domain name lookup will be stored
Return values

Definition at line 118 of file getdomain.c.

119 {
120  assert(result);
121  int rc = -1;
123 #if defined(HAVE_GETADDRINFO) || defined(HAVE_GETADDRINFO_A)
124  char node[256];
125  if (gethostname(node, sizeof(node)) != 0)
126  return rc;
128  struct addrinfo *lookup_result = NULL;
129  struct addrinfo hints;
131  mutt_buffer_reset(result);
132  memset(&hints, 0, sizeof(struct addrinfo));
133  hints.ai_flags = AI_CANONNAME;
134  hints.ai_family = AF_UNSPEC;
137  lookup_result = mutt_getaddrinfo_a(node, &hints);
138 #else
139  lookup_result = mutt_getaddrinfo(node, &hints);
140 #endif
142  char *hostname = NULL;
143  if (lookup_result && lookup_result->ai_canonname)
144  hostname = strchr(lookup_result->ai_canonname, '.');
146  if (hostname)
147  {
148  mutt_buffer_strcpy(result, ++hostname);
149  rc = 0;
150  mutt_debug(LL_DEBUG1, "Hostname: %s\n", mutt_buffer_string(result));
151  }
152  freeaddrinfo(lookup_result);
153 #endif
155  return rc;
156 }
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
#define mutt_debug(LEVEL,...)
Definition: logging.h:85
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Log at debug level 1.
Definition: logging.h:40
static struct addrinfo * mutt_getaddrinfo(const char *node, const struct addrinfo *hints)
Lookup the host&#39;s name using getaddrinfo()
Definition: getdomain.c:96
+ Here is the call graph for this function:
+ Here is the caller graph for this function: