nss-myhostname.c revision 8041b5bada31db152de80e45b3047ed32cef6880
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of nss-myhostname.
Copyright 2008-2011 Lennart Poettering
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1 of
the License, or (at your option) any later version.
nss-myhostname 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with nss-myhostname; If not, see
***/
#include <limits.h>
#include <nss.h>
#include <netdb.h>
#include <errno.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <stdlib.h>
#include "netlink.h"
/* We use 127.0.0.2 as IPv4 address. This has the advantage over
* 127.0.0.1 that it can be translated back to the local hostname. For
* IPv6 we use ::1 which unfortunately will not translate back to the
* hostname but instead something like "localhost6" or so. */
#define LOCALADDRESS_IPV6 &in6addr_loopback
#define LOOPBACK_INTERFACE "lo"
#define ALIGN(a) (((a+sizeof(void*)-1)/sizeof(void*))*sizeof(void*))
const char *name,
struct gaih_addrtuple **pat,
const char *name,
int af,
char **canonp);
const char *name,
int af,
const char *name,
int af,
int af,
const char *name,
struct gaih_addrtuple **pat,
unsigned lo_ifi;
char *r_name;
unsigned n_addresses = 0, n;
*h_errnop = NO_RECOVERY;
return NSS_STATUS_UNAVAIL;
}
return NSS_STATUS_NOTFOUND;
}
/* If this fails, n_addresses is 0. Which is fine */
/* If this call fails we fill in 0 as scope. Which is fine */
*h_errnop = NO_RECOVERY;
return NSS_STATUS_TRYAGAIN;
}
/* First, fill in hostname */
if (n_addresses <= 0) {
/* Second, fill in IPv6 tuple */
/* Third, fill in IPv4 tuple */
}
/* Fourth, fill actual addresses in, but in backwards order */
}
/* Verify the size matches */
*pat = r_tuple_prev;
if (ttlp)
*ttlp = 0;
return NSS_STATUS_SUCCESS;
}
static enum nss_status fill_in_hostent(
const char *hn,
int af,
char **canonp) {
unsigned n_addresses = 0, n, c;
for (a = addresses, n = 0, c = 0; n < n_addresses; a++, n++)
c++;
sizeof(char*)+
(c > 0 ? c+1 : 2)*sizeof(char*);
*h_errnop = NO_RECOVERY;
return NSS_STATUS_TRYAGAIN;
}
/* First, fill in hostname */
/* Second, create (empty) aliases array */
idx += sizeof(char*);
/* Third, add addresses */
if (c > 0) {
unsigned i = 0;
for (a = addresses, n = 0; n < n_addresses; a++, n++) {
continue;
i++;
}
assert(i == c);
} else {
else
}
/* Fourth, add address pointer array */
if (c > 0) {
unsigned i = 0;
for (a = addresses, n = 0; n < n_addresses; a++, n++) {
continue;
i++;
}
assert(i == c);
((char**) r_addr_list)[c] = NULL;
idx += (c+1)*sizeof(char*);
} else {
((char**) r_addr_list)[0] = r_addr;
idx += 2*sizeof(char*);
}
/* Verify the size matches */
if (ttlp)
*ttlp = 0;
if (canonp)
return NSS_STATUS_SUCCESS;
}
const char *name,
int af,
char **canonp) {
*errnop = EAFNOSUPPORT;
return NSS_STATUS_UNAVAIL;
}
*h_errnop = NO_RECOVERY;
return NSS_STATUS_UNAVAIL;
}
return NSS_STATUS_NOTFOUND;
}
}
const char *name,
int af,
return _nss_myhostname_gethostbyname3_r(
name,
af,
host,
NULL,
NULL);
}
const char *name,
return _nss_myhostname_gethostbyname3_r(
name,
host,
NULL,
NULL);
}
int af,
unsigned n_addresses = 0, n;
*h_errnop = NO_RECOVERY;
return NSS_STATUS_UNAVAIL;
}
goto found;
goto found;
} else {
*errnop = EAFNOSUPPORT;
return NSS_STATUS_UNAVAIL;
}
for (a = addresses, n = 0; n < n_addresses; n++, a++) {
continue;
goto found;
}
return NSS_STATUS_NOTFOUND;
*h_errnop = NO_RECOVERY;
return NSS_STATUS_UNAVAIL;
}
}
int af,
return _nss_myhostname_gethostbyaddr2_r(
af,
host,
NULL);
}