@Pavel Troller I've checkt the /etc/hosts now. You were right, it says
127.0.0.1 localhost.localdomain localhost Zwirch
(With Zwirch the Name of this Computer)
But I can't just statically rewrite it, because I use DHCP. Also this is a fresh Ubuntu-Install, so I'm surely not the only Wine-User with such an /etc/hosts..
@Juan You're right, I've checked the patch and it indeed was ugly! But when I sent it I hadn't done the check under Windows, so I didn't know if the patch was generally useful, so I mainly ment it as a piece for discussion.(Also I didn't notice how ugly it really was ;)
I've cleaned it up a bit, closed the leak, and did a few other small tweaks so now the patch itself might be acceptable.
greetings, David
Am Dienstag, 13. Dezember 2005 07:04 schrieb Pavel Troller:
Ok, I've just checked doing the same thing under windows.
The test(ripdaveno is the name of the Computer I tested on):
{ ... hostent* h = gethostbyname("ripdaveno"); char* str = inet_ntoa(*((in_addr*)h->h_addr_list[0])); ... }
The string in str was "192.168.2.75" which is my Network IP-Adress. With wine(under Linux), as far as I've tested it, exactly the same code always generates "127.0.0.1".
Since Wine tries to simulate Windows as exactly as possible, this is wrong. So, in my opinion this Patch is necessary. :-)
Hi! It's strange but there is no patch in this mail I can look at... However, even more strange is that wine returns localhost address to you... Why ? I just tested Your testing code (just slightly modified to get it to compile) on both plain linux as well as in wine and in both cases it returns my real public IP. Isn't your Linux networking setup (/etc/hosts table) a bit wrong ? My one contains (arcus is my machine name)
127.0.0.1 localhost 195.39.17.7 arcus.sinus.cz arcus
I have already seen broken setups containing things like
127.0.0.1 localhost arcus
which is of course wrong.
Regards, Pavel Troller
@Pavel Troller I've checkt the /etc/hosts now. You were right, it says
127.0.0.1 localhost.localdomain localhost Zwirch
(With Zwirch the Name of this Computer)
But I can't just statically rewrite it, because I use DHCP. Also this is a fresh Ubuntu-Install, so I'm surely not the only Wine-User with such an /etc/hosts..
Hi ! Yes, I know that *MANY* well-known distros are wrong with /etc/hosts and similar files.. The trick is that specifying your hostname for localhost interface improves Linux functionality in the case that there isn't other network interface active. Otherwise, a plenty of services would not work locally. However, when a real network interface comes up, it should be changed and moved to the line with a real IP address, which is not so obvious in the real world... I think that it is NOT GOOD to patch wine to fix this case; it behaves absolutely correctly and all the problem should be solved by correctly configuring your Linux networking. Please see any good document about naming principles of network interfaces. With regards, Pavel Troller
On Tue, 13 Dec 2005, Pavel Troller wrote:
127.0.0.1 localhost.localdomain localhost Zwirch
Yes, I know that *MANY* well-known distros are wrong with /etc/hosts and similar files..
I think that it is NOT GOOD to patch wine to fix this case; it behaves absolutely correctly and all the problem should be solved by correctly configuring your Linux networking. Please see any good document about naming principles of network interfaces.
I haven't followed the whole thread, so sorry if I've missed something obvious, but:
I think you are wrong. POSIX does not say that it's wrong to have the computer name associated with 127.0.0.1 in /etc/hosts, and it doesn't say that gethostbyname(my_name) should return a "real" IP. If I remember correctly, though, Microsoft, specifies that gethostbyname(my_name) *should* return real IP.
This subtle difference means that Wine must take extra care. Fetching a real IP on a UNIX host is not trivial, but doable.
Instead of just fetching the IP by looking up the hostname, I suggest using the approach below instead. It will fail if there is no route to 192.168.1.1 (typically this means that you don't have a default gateway). When this happens, you can resolv the hostname as a fallback.
#include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h>
int main() { int s, c, got_sockname = 0; struct sockaddr_in serv_addr; struct sockaddr_in my_addr; char *my_ip;
serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(1); /* Even better: Use the server you will connect to */ inet_aton("192.168.1.1", &serv_addr.sin_addr);
s = socket (PF_INET, SOCK_DGRAM, 0); if (s < 0) { perror("socket"); exit(EXIT_FAILURE); }
/* connect fails if if server is unreachable, for example */ if ((c = connect(s, (struct sockaddr*) &serv_addr, sizeof(serv_addr))) >= 0) { socklen_t my_addrlen; my_addrlen = sizeof(my_addr); if (getsockname(s, (struct sockaddr*)&my_addr, &my_addrlen) >= 0) { got_sockname = 1; } }
if (!got_sockname) /* Use 127.0.0.1 as a fallback. Even better: Resolv the hostname. */ inet_aton("127.0.0.1", &my_addr.sin_addr);
my_ip = inet_ntoa(my_addr.sin_addr); printf("%s\n", my_ip);
return 0; }
Regards,
@Peter I'm attaching the patch I've written again, so everyone can find it. It tries to find out the public IP by walkind the Interfaces available through the Kernel.
@Pavel I think that such a patch should be applied, Peter just said what I wanted to hear :-)
Windows just acts different in this, and wine should act exactly the same. You can't expect every Linux-user to specially hand-write his /etc/hosts so that his windows-programs/games work. :)
greetings
Am Dienstag, 13. Dezember 2005 16:57 schrieb Peter Åstrand:
On Tue, 13 Dec 2005, Pavel Troller wrote:
127.0.0.1 localhost.localdomain localhost Zwirch
Yes, I know that *MANY* well-known distros are wrong with /etc/hosts and similar files..
I think that it is NOT GOOD to patch wine to fix this case; it behaves absolutely correctly and all the problem should be solved by correctly configuring your Linux networking. Please see any good document about naming principles of network interfaces.
I haven't followed the whole thread, so sorry if I've missed something obvious, but:
I think you are wrong. POSIX does not say that it's wrong to have the computer name associated with 127.0.0.1 in /etc/hosts, and it doesn't say that gethostbyname(my_name) should return a "real" IP. If I remember correctly, though, Microsoft, specifies that gethostbyname(my_name) *should* return real IP.
This subtle difference means that Wine must take extra care. Fetching a real IP on a UNIX host is not trivial, but doable.
Instead of just fetching the IP by looking up the hostname, I suggest using the approach below instead. It will fail if there is no route to 192.168.1.1 (typically this means that you don't have a default gateway). When this happens, you can resolv the hostname as a fallback.
#include <stdio.h> #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h>
int main() { int s, c, got_sockname = 0; struct sockaddr_in serv_addr; struct sockaddr_in my_addr; char *my_ip;
serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(1); /* Even better: Use the server you will connect to */ inet_aton("192.168.1.1", &serv_addr.sin_addr); s = socket (PF_INET, SOCK_DGRAM, 0); if (s < 0) { perror("socket"); exit(EXIT_FAILURE); } /* connect fails if if server is unreachable, for example */ if ((c = connect(s, (struct sockaddr*) &serv_addr, sizeof(serv_addr)))
= 0) { socklen_t my_addrlen;
my_addrlen = sizeof(my_addr); if (getsockname(s, (struct sockaddr*)&my_addr, &my_addrlen) >= 0)
{ got_sockname = 1; } }
if (!got_sockname) /* Use 127.0.0.1 as a fallback. Even better: Resolv the hostname. */ inet_aton("127.0.0.1", &my_addr.sin_addr); my_ip = inet_ntoa(my_addr.sin_addr); printf("%s\n", my_ip); return 0;
}
Regards,
Hi!
I think you are wrong. POSIX does not say that it's wrong to have the computer name associated with 127.0.0.1 in /etc/hosts, and it doesn't say that gethostbyname(my_name) should return a "real" IP.
OK, but it also doesn't explicitly state that gethostbyname(my_name) may return 127.0.0.1, so it's just neutral :-).
If I remember correctly, though, Microsoft, specifies that gethostbyname(my_name) *should* return real IP.
I don't know M$ standards, sorry, cannot comment on this.
This subtle difference means that Wine must take extra care. Fetching a real IP on a UNIX host is not trivial, but doable.
Yes, it is.
BUT: man 5 hosts tells that:
"The Berkeley Internet Name Domain (BIND) Server implements the Internet name server for UNIX systems. It aug ments or replaces the /etc/hosts file or host name lookup, and frees a host from relying on /etc/hosts being up to date and complete."
So it seems to imply that the DNS info is currently an authoritative source for host name queries. Of course everybody knows it, I'm just making note of it to support my following question: Did you ever see in the real world that a DNS server would return 127.0.0.1 as a response to a regular host name query ? I think not. And on the other side, try to query a DNS server for "localhost". Every DNS server should immediately return 127.0.0.1, it's RFC compliance requirement. Isn't it logical to keep the host table coherent with DNS ? Or are you happy that in case your DNS server fails you get totally different results ?
Of course I cannot argue more. It's just about the administrator's personal style and knowledge. I'm maintaining and administering Unix systems from 1985, long before Linux was born, and I would never allow such a thing in my host table. But if the current distro maintainers are of another view, I will not do anything against it. It's just about Open Source freedom: I will remove that patch from wine for me, and that's it :-).
With regards, Pavel Troller
On 12/13/05, David Nolden david.nolden.wine@art-master.de wrote:
@Pavel Troller I've checkt the /etc/hosts now. You were right, it says
127.0.0.1 localhost.localdomain localhost Zwirch
(With Zwirch the Name of this Computer)
But I can't just statically rewrite it, because I use DHCP. Also this is a fresh Ubuntu-Install, so I'm surely not the only Wine-User with such an /etc/hosts..
This link may be of interest: http://lists.debian.org/debian-devel/2005/10/msg00387.html
Tom
On 12/13/05, David Nolden david.nolden.wine@art-master.de wrote:
@Pavel Troller I've checkt the /etc/hosts now. You were right, it says
127.0.0.1 localhost.localdomain localhost Zwirch
(With Zwirch the Name of this Computer)
But I can't just statically rewrite it, because I use DHCP. Also this is a fresh Ubuntu-Install, so I'm surely not the only Wine-User with such an /etc/hosts..
This link may be of interest: http://lists.debian.org/debian-devel/2005/10/msg00387.html
Tom
Hi! Yes, it uncovers even more problems with the /etc/hosts file on many distributions (hey, I'm sooooo happy that I'm maintaining my own private distro, independently of all the "big players" on the market :-) ). However, your link talks mainly about localhost.localdomain. I am even more strict and I'm saying that the host name also should not be there. And because I know that the host name should be assigned to EXACTLY ONE network interface, it is a reason that in my distro, when there are no public if's active, a dummy0 comes up and the host name is assigned to it. This if holds an address DIFFERENT from localhost (192.168.0.1 is used as a preconfigured default on a fresh install). Once more, please don't patch wine, it's evidently not its problem at all!
With regards, Pavel Troller