gethostbyname(my_name) and IL2-Sturmovik
David Nolden
david.nolden.wine at art-master.de
Tue Dec 13 10:12:13 CST 2005
@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,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gethostbyname_nolden_2.diff
Type: text/x-diff
Size: 4089 bytes
Desc: not available
Url : http://www.winehq.org/pipermail/wine-devel/attachments/20051213/525372f4/gethostbyname_nolden_2-0001.diff
More information about the wine-devel
mailing list