Home >> All >> ClassLib >> Common >> java >> [ net Javadoc ] |
Source code: ClassLib/Common/java/net/Inet4AddressImpl.java
1 // Inet4AddressImpl.java, created Fri Mar 7 11:01:56 2003 by joewhaley 2 // Copyright (C) 2001-3 John Whaley <jwhaley@alum.mit.edu> 3 // Licensed under the terms of the GNU LGPL; see COPYING for details. 4 package ClassLib.Common.java.net; 5 6 import Bootstrap.MethodInvocation; 7 import Bootstrap.PrimordialClassLoader; 8 import Clazz.jq_Class; 9 import Clazz.jq_Method; 10 import Clazz.jq_NameAndDesc; 11 import Main.jq; 12 import Memory.Address; 13 import Memory.CodeAddress; 14 import Memory.HeapAddress; 15 import Run_Time.SystemInterface; 16 import Run_Time.Unsafe; 17 import Run_Time.SystemInterface.ExternalLink; 18 import Run_Time.SystemInterface.Library; 19 import Util.Assert; 20 21 /** 22 * Inet4AddressImpl 23 * 24 * @author John Whaley <jwhaley@alum.mit.edu> 25 * @version $Id: Inet4AddressImpl.java,v 1.3 2003/05/12 10:04:53 joewhaley Exp $ 26 */ 27 public class Inet4AddressImpl { 28 29 static class hostent { 30 String h_name; /* official name of host */ 31 String[] h_aliases; /* alias list */ 32 int h_addrtype; /* host address type */ 33 int h_length; /* length of address */ 34 String[] h_addr_list; /* list of addresses */ 35 } 36 37 public static hostent get_host_by_name(String name) { 38 try { 39 CodeAddress a = gethostbyname.resolve(); 40 byte[] b = SystemInterface.toCString(name); 41 HeapAddress c = HeapAddress.addressOf(b); 42 Unsafe.pushArgA(c); 43 Unsafe.getThreadBlock().disableThreadSwitch(); 44 Address p = Unsafe.invokeA(a); 45 Unsafe.getThreadBlock().enableThreadSwitch(); 46 hostent r = new hostent(); 47 r.h_name = SystemInterface.fromCString(p.peek()); 48 int count = 0; 49 Address q = p.offset(HeapAddress.size()).peek(); 50 while (!q.peek().isNull()) { 51 ++count; 52 q = q.offset(HeapAddress.size()); 53 } 54 r.h_aliases = new String[count]; 55 count = 0; 56 q = p.offset(HeapAddress.size()).peek(); 57 while (!q.peek().isNull()) { 58 r.h_aliases[count] = SystemInterface.fromCString(q.peek()); 59 ++count; 60 q = q.offset(HeapAddress.size()); 61 } 62 r.h_addrtype = p.offset(HeapAddress.size()*2).peek4(); 63 r.h_length = p.offset(HeapAddress.size()*2+4).peek4(); 64 count = 0; 65 q = p.offset(HeapAddress.size()*2+8).peek(); 66 while (!q.peek().isNull()) { 67 ++count; 68 q = q.offset(HeapAddress.size()); 69 } 70 count = 0; 71 q = p.offset(HeapAddress.size()*2+8).peek(); 72 while (!q.peek().isNull()) { 73 r.h_addr_list[count] = SystemInterface.fromCString(q.peek()); 74 ++count; 75 q = q.offset(HeapAddress.size()); 76 } 77 return r; 78 } catch (Throwable x) { Assert.UNREACHABLE(); } 79 return null; 80 } 81 82 public static /*final*/ ExternalLink gethostbyname; 83 84 static { 85 if (jq.RunningNative) boot(); 86 else if (jq.on_vm_startup != null) { 87 jq_Class c = (jq_Class) PrimordialClassLoader.loader.getOrCreateBSType("Ljava/net/Inet4AddressImpl;"); 88 jq_Method m = c.getDeclaredStaticMethod(new jq_NameAndDesc("boot", "()V")); 89 MethodInvocation mi = new MethodInvocation(m, null); 90 jq.on_vm_startup.add(mi); 91 } 92 } 93 94 public static void boot() { 95 Library winsock = SystemInterface.registerLibrary("ws2_32"); 96 97 if (winsock != null) { 98 gethostbyname = winsock.resolve("gethostbyname"); 99 } else { 100 gethostbyname = null; 101 } 102 103 } 104 105 public java.lang.String getLocalHostName() throws java.net.UnknownHostException { 106 return null; 107 } 108 public byte[][] lookupAllHostAddr(java.lang.String hostname) throws java.net.UnknownHostException { 109 return null; 110 } 111 public java.lang.String getHostByAddr(byte[] addr) throws java.net.UnknownHostException { 112 return null; 113 } 114 }