* mts.c -- definitions for the mail transport system
*
* $Id$
+ *
+ * This code is Copyright (c) 2002, by the authors of nmh. See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
*/
#include <h/mh.h> /* for snprintf() */
#include <h/nmh.h>
+#include <h/utils.h>
#define nmhetcdir(file) NMHETCDIR#file
#define NOTOK (-1)
#define OK 0
-extern int errno;
-
/*
* static prototypes
*/
-static char *tailor_value (char *);
+static char *tailor_value (unsigned char *);
static void getuserinfo (void);
/*
void
mts_init (char *name)
{
- char *bp, *cp, buffer[BUFSIZ];
+ unsigned char *bp;
+ char *cp, buffer[BUFSIZ];
struct bind *b;
FILE *fp;
static int inited = 0;
*/
static char *
-tailor_value (char *s)
+tailor_value (unsigned char *s)
{
int i, r;
char *bp;
*bp = 0;
len = strlen (buffer) + 1;
- if ((bp = malloc (len)))
- memcpy (bp, buffer, len);
+ bp = mh_xmalloc (len);
+ memcpy (bp, buffer, len);
return bp;
}
LocalName (void)
{
static char buffer[BUFSIZ] = "";
- struct hostent *hp;
-
+ struct addrinfo hints, *res;
#ifdef HAVE_UNAME
struct utsname name;
#endif
if (*localname) {
strncpy (buffer, localname, sizeof(buffer));
} else {
+ memset(buffer, 0, sizeof(buffer));
#ifdef HAVE_UNAME
/* first get our local name */
uname (&name);
- strncpy (buffer, name.nodename, sizeof(buffer));
+ strncpy (buffer, name.nodename, sizeof(buffer) - 1);
#else
/* first get our local name */
- gethostname (buffer, sizeof(buffer));
+ gethostname (buffer, sizeof(buffer) - 1);
#endif
-#ifdef HAVE_SETHOSTENT
- sethostent (1);
-#endif
/* now fully qualify our name */
- if ((hp = gethostbyname (buffer)))
- strncpy (buffer, hp->h_name, sizeof(buffer));
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = AI_CANONNAME;
+ hints.ai_family = PF_UNSPEC;
+ if (getaddrinfo(buffer, NULL, &hints, &res) == 0) {
+ strncpy(buffer, res->ai_canonname, sizeof(buffer) - 1);
+ freeaddrinfo(res);
+ }
}
/*
static void
getuserinfo (void)
{
- register char *cp, *np;
+ register unsigned char *cp;
+ register char *np;
register struct passwd *pw;
#ifdef KPOP