< prev index next >

src/java.base/unix/classes/sun/net/dns/ResolverConfigurationImpl.java

Print this page




 114     private LinkedList<String> searchlist;
 115     private LinkedList<String> nameservers;
 116 
 117 
 118     // Load DNS configuration from OS
 119 
 120     private void loadConfig() {
 121         assert Thread.holdsLock(lock);
 122 
 123         // check if cached settings have expired.
 124         if (lastRefresh >= 0) {
 125             long currTime = System.currentTimeMillis();
 126             if ((currTime - lastRefresh) < TIMEOUT) {
 127                 return;
 128             }
 129         }
 130 
 131         // get the name servers from /etc/resolv.conf
 132         nameservers =
 133             java.security.AccessController.doPrivileged(
 134                 new java.security.PrivilegedAction<LinkedList<String>>() {
 135                     public LinkedList<String> run() {
 136                         // typically MAXNS is 3 but we've picked 5 here
 137                         // to allow for additional servers if required.
 138                         return resolvconf("nameserver", 1, 5);
 139                     } /* run */
 140                 });
 141 
 142         // get the search list (or domain)
 143         searchlist = getSearchList();
 144 
 145         // update the timestamp on the configuration
 146         lastRefresh = System.currentTimeMillis();
 147     }
 148 
 149 
 150     // obtain search list or local domain
 151 
 152     private LinkedList<String> getSearchList() {
 153 
 154         LinkedList<String> sl;
 155 
 156         // first try the search keyword in /etc/resolv.conf
 157 
 158         sl = java.security.AccessController.doPrivileged(
 159                  new java.security.PrivilegedAction<LinkedList<String>>() {
 160                     public LinkedList<String> run() {
 161                         LinkedList<String> ll;
 162 
 163                         // first try search keyword (max 6 domains)
 164                         ll = resolvconf("search", 6, 1);
 165                         if (ll.size() > 0) {
 166                             return ll;
 167                         }
 168 
 169                         return null;
 170 
 171                     } /* run */
 172 
 173                 });
 174         if (sl != null) {
 175             return sl;
 176         }
 177 
 178         // No search keyword so use local domain
 179 
 180 
 181         // LOCALDOMAIN has absolute priority on Solaris
 182 
 183         String localDomain = localDomain0();
 184         if (localDomain != null && localDomain.length() > 0) {
 185             sl = new LinkedList<String>();
 186             sl.add(localDomain);
 187             return sl;
 188         }
 189 
 190         // try domain keyword in /etc/resolv.conf
 191 
 192         sl = java.security.AccessController.doPrivileged(
 193                  new java.security.PrivilegedAction<LinkedList<String>>() {
 194                     public LinkedList<String> run() {
 195                         LinkedList<String> ll;
 196 
 197                         ll = resolvconf("domain", 1, 1);
 198                         if (ll.size() > 0) {
 199                             return ll;
 200                         }
 201                         return null;
 202 
 203                     } /* run */
 204                 });
 205         if (sl != null) {
 206             return sl;
 207         }
 208 
 209         // no local domain so try fallback (RPC) domain or
 210         // hostName
 211 
 212         sl = new LinkedList<>();
 213         String domain = fallbackDomain0();


 243             // List is mutable so return a shallow copy
 244 
 245           return (List<String>)nameservers.clone();
 246 
 247         }
 248     }
 249 
 250     public Options options() {
 251         return opts;
 252     }
 253 
 254 
 255     // --- Native methods --
 256 
 257     static native String localDomain0();
 258 
 259     static native String fallbackDomain0();
 260 
 261     static {
 262         java.security.AccessController.doPrivileged(
 263             new java.security.PrivilegedAction<Void>() {
 264                 public Void run() {
 265                     System.loadLibrary("net");
 266                     return null;
 267                 }
 268             });
 269     }
 270 
 271 }
 272 
 273 /**
 274  * Implementation of {@link ResolverConfiguration.Options}
 275  */
 276 class OptionsImpl extends ResolverConfiguration.Options {
 277 }


 114     private LinkedList<String> searchlist;
 115     private LinkedList<String> nameservers;
 116 
 117 
 118     // Load DNS configuration from OS
 119 
 120     private void loadConfig() {
 121         assert Thread.holdsLock(lock);
 122 
 123         // check if cached settings have expired.
 124         if (lastRefresh >= 0) {
 125             long currTime = System.currentTimeMillis();
 126             if ((currTime - lastRefresh) < TIMEOUT) {
 127                 return;
 128             }
 129         }
 130 
 131         // get the name servers from /etc/resolv.conf
 132         nameservers =
 133             java.security.AccessController.doPrivileged(
 134                 new java.security.PrivilegedAction<>() {
 135                     public LinkedList<String> run() {
 136                         // typically MAXNS is 3 but we've picked 5 here
 137                         // to allow for additional servers if required.
 138                         return resolvconf("nameserver", 1, 5);
 139                     } /* run */
 140                 });
 141 
 142         // get the search list (or domain)
 143         searchlist = getSearchList();
 144 
 145         // update the timestamp on the configuration
 146         lastRefresh = System.currentTimeMillis();
 147     }
 148 
 149 
 150     // obtain search list or local domain
 151 
 152     private LinkedList<String> getSearchList() {
 153 
 154         LinkedList<String> sl;
 155 
 156         // first try the search keyword in /etc/resolv.conf
 157 
 158         sl = java.security.AccessController.doPrivileged(
 159                  new java.security.PrivilegedAction<>() {
 160                     public LinkedList<String> run() {
 161                         LinkedList<String> ll;
 162 
 163                         // first try search keyword (max 6 domains)
 164                         ll = resolvconf("search", 6, 1);
 165                         if (ll.size() > 0) {
 166                             return ll;
 167                         }
 168 
 169                         return null;
 170 
 171                     } /* run */
 172 
 173                 });
 174         if (sl != null) {
 175             return sl;
 176         }
 177 
 178         // No search keyword so use local domain
 179 
 180 
 181         // LOCALDOMAIN has absolute priority on Solaris
 182 
 183         String localDomain = localDomain0();
 184         if (localDomain != null && localDomain.length() > 0) {
 185             sl = new LinkedList<>();
 186             sl.add(localDomain);
 187             return sl;
 188         }
 189 
 190         // try domain keyword in /etc/resolv.conf
 191 
 192         sl = java.security.AccessController.doPrivileged(
 193                  new java.security.PrivilegedAction<>() {
 194                     public LinkedList<String> run() {
 195                         LinkedList<String> ll;
 196 
 197                         ll = resolvconf("domain", 1, 1);
 198                         if (ll.size() > 0) {
 199                             return ll;
 200                         }
 201                         return null;
 202 
 203                     } /* run */
 204                 });
 205         if (sl != null) {
 206             return sl;
 207         }
 208 
 209         // no local domain so try fallback (RPC) domain or
 210         // hostName
 211 
 212         sl = new LinkedList<>();
 213         String domain = fallbackDomain0();


 243             // List is mutable so return a shallow copy
 244 
 245           return (List<String>)nameservers.clone();
 246 
 247         }
 248     }
 249 
 250     public Options options() {
 251         return opts;
 252     }
 253 
 254 
 255     // --- Native methods --
 256 
 257     static native String localDomain0();
 258 
 259     static native String fallbackDomain0();
 260 
 261     static {
 262         java.security.AccessController.doPrivileged(
 263             new java.security.PrivilegedAction<>() {
 264                 public Void run() {
 265                     System.loadLibrary("net");
 266                     return null;
 267                 }
 268             });
 269     }
 270 
 271 }
 272 
 273 /**
 274  * Implementation of {@link ResolverConfiguration.Options}
 275  */
 276 class OptionsImpl extends ResolverConfiguration.Options {
 277 }
< prev index next >