--- old/src/share/classes/sun/security/ssl/HelloExtensions.java	2009-03-05 10:53:37.000000000 +0000
+++ new/src/share/classes/sun/security/ssl/HelloExtensions.java	2009-03-05 10:53:36.000000000 +0000
@@ -33,6 +33,7 @@
 
 import javax.net.ssl.SSLProtocolException;
 
+
 /**
  * This file contains all the classes relevant to TLS Extensions for the
  * ClientHello and ServerHello messages. The extension mechanism and
@@ -147,7 +148,6 @@
         }
     }
 }
-
 final class ExtensionType {
 
     final int id;
@@ -260,6 +260,14 @@
             throw new SSLProtocolException("Invalid server_name extension");
         }
     }
+    
+    ServerNameExtension(String serverName) {
+        super(ExtensionType.EXT_SERVER_NAME);
+        names = new ArrayList<ServerName>(1);
+        if ((serverName != null)&&(serverName.length()>0)) {
+            names.add(new ServerName(serverName));
+        }
+    }
 
     static class ServerName {
         final int length;
@@ -277,6 +285,20 @@
                 hostname = null;
             }
         }
+        
+        ServerName(String hostname) {
+            this.hostname = hostname;
+            byte[] hostnameAsUTF8 = null;
+            try {
+                hostnameAsUTF8 = hostname.getBytes("UTF-8");
+            } catch (java.io.UnsupportedEncodingException ex) {
+                // UTF-8 encoding should reliably be present.
+                throw new RuntimeException(ex);
+            }
+            this.data = hostnameAsUTF8;
+            this.type = NAME_HOST_NAME;
+            this.length = this.data.length + 3;
+        }
 
         public String toString() {
             if (type == NAME_HOST_NAME) {
@@ -286,17 +308,40 @@
             }
         }
     }
-
+    
     int length() {
-        throw new RuntimeException("not yet supported");
+        if (names.size() == 0)
+            return 0;
+        int serverNameListLength = 0;
+        for (ServerName sn : names) {
+            serverNameListLength += sn.length + 2;
+        }
+        return serverNameListLength + 4;
     }
 
     void send(HandshakeOutStream s) throws IOException {
-        throw new RuntimeException("not yet supported");
+        if (names.size() == 0)
+            return;
+        s.putInt16(type.id);
+        int serverNameListLength = 0;
+        for (ServerName sn : names) {
+            serverNameListLength += sn.length + 2;
+        }
+        s.putInt16(serverNameListLength);
+        for (ServerName sn : names) {
+            s.putInt16(sn.length);
+            s.putInt8(sn.type);
+            s.putBytes16(sn.data);
+        }
     }
 
     public String toString() {
-        return "Unsupported extension " + type + ", " + names.toString();
+        StringBuilder sb = new StringBuilder();
+        sb.append("Extension " + type + ", host names:\n");
+        for (ServerName sn : names) {
+            sb.append("  " + sn + "\n");
+        }
+        return sb.toString();
     }
 }
 
