<<< Date Index >>>     <<< Thread Index >>>

Re: [Mutt] #3298: Mutt's way to get the FQDN is broken



It looks to me like Mutt is setting the Hostname var using uname(2)
in init.c (if the user doesn't set it), and mutt_gen_msgid() is using
that.  This is highly likely to NOT generate a fully qualified domain
name:  It's common practice to set the host name to the short host
name, and (especially on mobile computing devices) leave the system
configured such that the domain name is either localdomain or
indeterminate.  Yuck.

Probably the best way to determine the FQDN, given current standards,
is with code similar to the following:

-=-=-=-=-=-=-=-

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

#define SIZE 1024

int main()
{
    char node[SIZE];
    struct addrinfo *h;

    /* 
     * Posix apparently does not specify whether the result from
     * gethostname should be null-terminated or not... It only
     * guarantees that it will be truncated to fit in a buffer of the
     * specified size.
     */
    gethostname(&node, SIZE);
    node[SIZE-1] = '\0';
    if (getaddrinfo(node, NULL, NULL, &h))
        perror("getaddrinfo");
    if (getnameinfo(h->ai_addr, h->ai_addrlen, &node, SIZE, NULL, 0, 0))
        perror("getnameinfo");
    printf("hostname from getnameinfo(): %s\n", node);
    return 0;
}

-=-=-=-=-=-

All of the above functions are specified by POSIX.  However, this
probably requires a fairly recent implementation.  getaddrinfo() and
getnameinfo() replace gethostbyfoo(), as they are reentrant and allow
easy use of both IPv4 and IPv6.  You may need to use gethostbyfoo()
instead on older systems.  According to the man pages on my system,
POSIX declares those functions obsolete.  Naturally, I have not
handled error cases...

Attachment: pgpS11reNFOgM.pgp
Description: PGP signature