NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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.

Functions

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

Detailed Description

DNS lookups.

Authors
  • Mehdi Abaakouk
  • Richard Russon
  • Ihor Antonov
  • Pietro Cerutti

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 http://www.gnu.org/licenses/.

Definition in file getdomain.c.

Function Documentation

◆ mutt_getaddrinfo()

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

Lookup the host's name using getaddrinfo()

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

Definition at line 103 of file getdomain.c.

104{
105 assert(node);
106 assert(hints);
107 struct addrinfo *result = NULL;
108 mutt_debug(LL_DEBUG3, "before getaddrinfo\n");
109 int rc = getaddrinfo(node, NULL, hints, &result);
110 mutt_debug(LL_DEBUG3, "after getaddrinfo\n");
111
112 if (rc != 0)
113 result = NULL;
114
115 return result;
116}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG3
Log at debug level 3.
Definition: logging2.h:45
+ Here is the caller graph for this function:

◆ getdnsdomainname()

int getdnsdomainname ( struct Buffer result)

Lookup the host's name using DNS.

Parameters
resultBuffer were result of the domain name lookup will be stored
Return values
0Success
-1Error

Definition at line 125 of file getdomain.c.

126{
127 assert(result);
128 int rc = -1;
129
130#if defined(HAVE_GETADDRINFO) || defined(HAVE_GETADDRINFO_A)
131 char node[256] = { 0 };
132 if (gethostname(node, sizeof(node)) != 0)
133 return rc;
134
135 struct addrinfo *lookup_result = NULL;
136 struct addrinfo hints = { 0 };
137
138 buf_reset(result);
139 hints.ai_flags = AI_CANONNAME;
140 hints.ai_family = AF_UNSPEC;
141
142#ifdef HAVE_GETADDRINFO_A
143 lookup_result = mutt_getaddrinfo_a(node, &hints);
144#else
145 lookup_result = mutt_getaddrinfo(node, &hints);
146#endif
147
148 if (lookup_result && lookup_result->ai_canonname)
149 {
150 const char *hostname = strchr(lookup_result->ai_canonname, '.');
151 if (hostname && hostname[1] != '\0')
152 {
153 buf_strcpy(result, ++hostname);
154 rc = 0;
155 }
156 }
157
158 if (lookup_result)
159 freeaddrinfo(lookup_result);
160#endif
161
162 return rc;
163}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:75
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:394
static struct addrinfo * mutt_getaddrinfo(const char *node, const struct addrinfo *hints)
Lookup the host's name using getaddrinfo()
Definition: getdomain.c:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function: