Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c
32288 views
/*1* Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include <stdio.h>26#include <stdlib.h>27#include <unistd.h>28#include <errno.h>2930#ifdef __solaris__31#include <sys/systeminfo.h>32#include <strings.h>33#endif3435#if defined(__linux__) || defined(_ALLBSD_SOURCE)36#include <string.h>37#endif3839#include "jni.h"4041#ifndef MAXDNAME42#define MAXDNAME 102543#endif444546/*47* Class: sun_net_dns_ResolverConfgurationImpl48* Method: localDomain049* Signature: ()Ljava/lang/String;50*/51JNIEXPORT jstring JNICALL52Java_sun_net_dns_ResolverConfigurationImpl_localDomain0(JNIEnv *env, jclass cls)53{54/*55* On Solaris the LOCALDOMAIN environment variable has absolute56* priority.57*/58#ifdef __solaris__59{60char *cp = getenv("LOCALDOMAIN");61if (cp != NULL) {62jstring s = (*env)->NewStringUTF(env, cp);63return s;64}65}66#endif67return (jstring)NULL;68}6970/*71* Class: sun_net_dns_ResolverConfgurationImpl72* Method: loadConfig073* Signature: ()Ljava/lang/String;74*/75JNIEXPORT jstring JNICALL76Java_sun_net_dns_ResolverConfigurationImpl_fallbackDomain0(JNIEnv *env, jclass cls)77{78char buf[MAXDNAME];7980/*81* On Solaris if domain or search directives aren't specified82* in /etc/resolv.conf then sysinfo or gethostname is used to83* determine the domain name.84*85* On Linux if domain or search directives aren't specified86* then gethostname is used.87*/8889#ifdef __solaris__90{91int ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf));9293if ((ret > 0) && (ret<sizeof(buf))) {94char *cp;95jstring s;9697if (buf[0] == '+') {98buf[0] = '.';99}100cp = strchr(buf, '.');101if (cp == NULL) {102s = (*env)->NewStringUTF(env, buf);103} else {104s = (*env)->NewStringUTF(env, cp+1);105}106return s;107}108}109#endif110111if (gethostname(buf, sizeof(buf)) == 0) {112char *cp;113114/* gethostname doesn't null terminate if insufficient space */115buf[sizeof(buf)-1] = '\0';116117cp = strchr(buf, '.');118if (cp != NULL) {119jstring s = (*env)->NewStringUTF(env, cp+1);120return s;121}122}123124return (jstring)NULL;125}126127128