src/java.base/unix/native/libnet/ResolverConfigurationImpl.c
author prappo
Tue, 13 Nov 2018 12:24:34 +0000
changeset 52499 768b1c612100
parent 47216 71c04702a3d5
permissions -rw-r--r--
8213490: Networking area typos and inconsistencies cleanup Reviewed-by: alanb, chegar, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14342
8435a30053c1 7197491: update copyright year to match last edit in jdk8 jdk repository
alanb
parents: 12047
diff changeset
     2
 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <stdio.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <stdlib.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <unistd.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include <sys/systeminfo.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#ifndef MAXDNAME
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define MAXDNAME                1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/*
52499
768b1c612100 8213490: Networking area typos and inconsistencies cleanup
prappo
parents: 47216
diff changeset
    45
 * Class:     sun_net_dns_ResolverConfigurationImpl
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * Method:    localDomain0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Signature: ()Ljava/lang/String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
Java_sun_net_dns_ResolverConfigurationImpl_localDomain0(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * On Solaris the LOCALDOMAIN environment variable has absolute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * priority.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        char *cp = getenv("LOCALDOMAIN");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        if (cp != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            jstring s = (*env)->NewStringUTF(env, cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    return (jstring)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
52499
768b1c612100 8213490: Networking area typos and inconsistencies cleanup
prappo
parents: 47216
diff changeset
    69
 * Class:     sun_net_dns_ResolverConfigurationImpl
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * Method:    loadConfig0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Signature: ()Ljava/lang/String;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
JNIEXPORT jstring JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
Java_sun_net_dns_ResolverConfigurationImpl_fallbackDomain0(JNIEnv *env, jclass cls)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    char buf[MAXDNAME];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * On Solaris if domain or search directives aren't specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * in /etc/resolv.conf then sysinfo or gethostname is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * determine the domain name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * On Linux if domain or search directives aren't specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * then gethostname is used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#ifdef __solaris__
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        int ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if ((ret > 0) && (ret<sizeof(buf))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            char *cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            jstring s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            if (buf[0] == '+') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                buf[0] = '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            cp = strchr(buf, '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            if (cp == NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                s = (*env)->NewStringUTF(env, buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                s = (*env)->NewStringUTF(env, cp+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    if (gethostname(buf, sizeof(buf)) == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        char *cp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        /* gethostname doesn't null terminate if insufficient space */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        buf[sizeof(buf)-1] = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        cp = strchr(buf, '.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (cp != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            jstring s = (*env)->NewStringUTF(env, cp+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            return s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    return (jstring)NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
}