nss-myhostname.c revision 9d485985338a46b8cb1acdf1af6c1eb2e88acfee
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer This file is part of systemd.
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek Copyright 2008-2011 Lennart Poettering
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier systemd is free software; you can redistribute it and/or modify it
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer under the terms of the GNU Lesser General Public License as published by
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer the Free Software Foundation; either version 2.1 of the License, or
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer (at your option) any later version.
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier systemd is distributed in the hope that it will be useful, but
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier WITHOUT ANY WARRANTY; without even the implied warranty of
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier Lesser General Public License for more details.
32d965851d8cbb39f8ee0eeaf76a89e8f5fc174fLennart Poettering You should have received a copy of the GNU Lesser General Public License
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer along with systemd; If not, see <http://www.gnu.org/licenses/>.
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier/* Ensure that glibc's assert is used. We cannot use assert from macro.h, as
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * libnss_myhostname will be linked into arbitrary programs which will, in turn
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * attempt to write to the journal via log_dispatch() */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer/* We use 127.0.0.2 as IPv4 address. This has the advantage over
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer * 127.0.0.1 that it can be translated back to the local hostname. For
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer * IPv6 we use ::1 which unfortunately will not translate back to the
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer * hostname but instead something like "localhost6" or so. */
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyerenum nss_status _nss_myhostname_gethostbyname4_r(
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier struct gaih_addrtuple *r_tuple, *r_tuple_prev = NULL;
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer _cleanup_free_ struct local_address *addresses = NULL;
if (!hn) {
return NSS_STATUS_TRYAGAIN;
return NSS_STATUS_NOTFOUND;
if (n_addresses < 0)
n_addresses = 0;
return NSS_STATUS_TRYAGAIN;
if (n_addresses <= 0) {
if (*pat)
if (ttlp)
*ttlp = 0;
return NSS_STATUS_SUCCESS;
int af,
char **canonp) {
struct local_address *a;
(additional ? sizeof(char*) : 0) +
return NSS_STATUS_TRYAGAIN;
if (additional) {
if (additional) {
idx += sizeof(char*);
assert(i == c);
if (ttlp)
*ttlp = 0;
if (canonp)
return NSS_STATUS_SUCCESS;
const char *name,
int af,
char **canonp) {
int n_addresses = 0;
return NSS_STATUS_UNAVAIL;
if (!hn) {
return NSS_STATUS_TRYAGAIN;
return NSS_STATUS_NOTFOUND;
if (n_addresses < 0)
n_addresses = 0;
return fill_in_hostent(
af,
host,
ttlp,
canonp);
int af,
int n_addresses = 0;
struct local_address *a;
return NSS_STATUS_UNAVAIL;
return NSS_STATUS_UNAVAIL;
goto found;
goto found;
goto found;
if (n_addresses < 0)
n_addresses = 0;
goto found;
return NSS_STATUS_NOTFOUND;
if (!canonical) {
if (!hn) {
return NSS_STATUS_TRYAGAIN;
return fill_in_hostent(
af,
host,
ttlp,
NULL);