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