DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15899>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=15899

SocketServer won't use IP address if server has not hostname

           Summary: SocketServer won't use IP address if server has not
                    hostname
           Product: Log4j
           Version: 1.2
          Platform: Sun
        OS/Version: Linux
            Status: NEW
          Severity: Minor
          Priority: Other
         Component: Other
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


General:

In using org.apache.log4j.net.SocketServer on internal machines that don't have 
DNS or host entries, I realized that I won't be able to set the remote 
configuration files with a IP based name (ie. 192.168.1.10.lcf).  I assume that 
most name resolution will return an IP if a host name does not exist.  So 
currently SocketServer attempts to look for a configuration file named ".lcf" 
if no host name is found for the remote host writing to it.

Tested environment:

SuSE Linux 8.0 Pro
Sun's JDK 1.4.1-rc-b19, Client VM, mixed mode
Log4j 1.2.7

Command:

java -cp .:log4j.jar org.apache.log4j.SocketServer 3000 conf .

Investigation:

SocketServer current assumes that java.net.InetAddress.toString() will always 
return a host/ip string in the format "host.name.net/D1.D2.D3.D4" .  If 
java.net.InetAddress.toString() returns "/D1.D2.D3.D4", then the file name is 
set to empty string.

Proposed solution/patch:

The following patch will have SocketServer check for an empty sting and if 
true, return the other portion of that string without the trailing leading 
slash ultimatly setting the configuration file name to the IP address with 
a .lcf extention:

--- SocketServerorig.java       Fri Jan  3 19:42:08 2003
+++ SocketServer.java   Fri Jan  3 19:42:08 2003
@@ -70,7 +70,7 @@
 
  @since 1.0 */
 
-public class SocketServerorig {
+public class SocketServer {
 
     static String GENERIC = "generic";
     static String CONFIG_FILE_EXT = ".lcf";
@@ -143,7 +143,7 @@
 
 
     public
-            SocketServerorig(File directory) {
+            SocketServer(File directory) {
         this.dir = directory;
         hierarchyMap = new Hashtable(11);
     }
@@ -161,7 +161,16 @@
                     "]. Using default hierarchy.");
             return genericHierarchy();
         } else {
-            String key = s.substring(0, i);
+
+            String key = null;
+
+            //  This will return the IP string if there is no host
+ name.
+
+            if (i == 0) {
+                key = s.substring(1);
+            } else {
+                key = s.substring(0, i);
+            }
 
             File configFile = new File(dir, key + CONFIG_FILE_EXT);
             if (configFile.exists()) {

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to