Index: dlls/winsock/socket.c
===================================================================
RCS file: /home/wine/wine/dlls/winsock/socket.c,v
retrieving revision 1.203
diff -b -B -c -r1.203 socket.c
*** dlls/winsock/socket.c	12 Dec 2005 12:49:05 -0000	1.203
--- dlls/winsock/socket.c	13 Dec 2005 12:26:18 -0000
***************
*** 2927,2932 ****
--- 2927,2991 ----
      return retval;
  }
  
+ 
+ /***********************************************************************
+  *		getpublicIP		(Internal)
+  *
+  *   Tries to guess the public IP-Adress by enumerating the available Interfaces
+  *   target needs to be a buffer with the maximum size given in "size"
+  */
+ 
+ 
+ BOOL getpublicIP(char* target,int size)
+ {
+     char buff[1024];
+     char buffer[1024];
+     struct ifconf ifc;
+     struct ifreq *ifr;
+     int skfd;
+     int i;
+ 
+     skfd = socket(AF_INET, SOCK_DGRAM, 0);
+     if (skfd < 0)
+     {
+         WARN("A socket could not be created");
+         return FALSE;
+     }
+ 
+     ifc.ifc_len = sizeof(buff);
+     ifc.ifc_buf = buff;
+     if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0)
+     {
+         WARN("ioctl(SIOCGIFCONF) failed");
+         close(skfd);
+         return FALSE;
+     }
+     
+     close(skfd);
+ 
+     ifr = ifc.ifc_req;
+ 
+     for (i = 0; i < ifc.ifc_len / sizeof(struct ifreq); i++)
+     {
+         struct sockaddr_in* addr=(struct sockaddr_in*)&ifr[i].ifr_addr;
+         unsigned char* ip = ((unsigned char*)&addr->sin_addr);
+ 		
+         if(strcmp(ifr[i].ifr_name,"lo")==0)continue;   /*Exclude loopback-device by Name "lo"*/
+ 		
+         if(ip[0]==127&&ip[1]==0&&ip[2]==0&&ip[3]==0)continue; /*Exclude 127.0.0.1*/
+ 		
+         sprintf(buffer,"%i.%i.%i.%i", (int)ip[0],(int)ip[1],(int)ip[2],(int)ip[3]);
+ 
+         if(size>strlen(buffer))strcpy(target,buffer);
+ 		
+         return TRUE;
+     }
+ 
+     return FALSE;
+ }
+ 
+ 
+ 
  /***********************************************************************
   *		gethostbyname		(WS2_32.52)
   */
***************
*** 2930,2937 ****
--- 2989,3000 ----
  /***********************************************************************
   *		gethostbyname		(WS2_32.52)
   */
+ 
  struct WS_hostent* WINAPI WS_gethostbyname(const char* name)
  {
+     char myname[1000];
+     struct in_addr newaddr;
+ 
      struct WS_hostent *retval = NULL;
      struct hostent*     host;
  #ifdef  HAVE_LINUX_GETHOSTBYNAME_R_6
***************
*** 2941,2946 ****
--- 3004,3012 ----
      int locerr = ENOBUFS;
  #endif
      char buf[100];
+ 
+     gethostname(myname,(size_t)1000);
+ 
      if( !name) {
          name = buf;
          if( gethostname( buf, 100) == -1) {
***************
*** 2961,2969 ****
  #else
      EnterCriticalSection( &csWSgetXXXbyYYY );
      host = gethostbyname(name);
      if (!host) SetLastError((h_errno < 0) ? wsaErrno() : wsaHerrno(h_errno));
  #endif
!     if (host) retval = WS_dup_he(host);
  #ifdef  HAVE_LINUX_GETHOSTBYNAME_R_6
      HeapFree(GetProcessHeap(),0,extrabuf);
  #else
--- 3029,3055 ----
  #else
      EnterCriticalSection( &csWSgetXXXbyYYY );
      host = gethostbyname(name);
+     
      if (!host) SetLastError((h_errno < 0) ? wsaErrno() : wsaHerrno(h_errno));
  #endif
!     if (host){
!         if(strcmp(myname,name)==0){
!             /*Replace the gotten Adress*/
!             char buffer[400];
!             if(getpublicIP(buffer,400)&&host->h_length==4)  /*Make sure that it really is an IPv4 Adress by checking h_length==4*/
!             {
!                 inet_aton(buffer,&newaddr);
!                     
!                 memcpy(((struct in_addr *)host->h_addr_list[0]),&newaddr,4);
!                     
!                 TRACE("Using %s as public Adress for local Host %s\n",inet_ntoa(*((struct in_addr *)host->h_addr_list[0])),name);
!             }else{
!                 WARN("Public IP-Adress of local Host could not be recognized");
!             }
!         }
!         
!         retval = WS_dup_he(host);
!     }
  #ifdef  HAVE_LINUX_GETHOSTBYNAME_R_6
      HeapFree(GetProcessHeap(),0,extrabuf);
  #else
