Commit f4e15b4b4b0b8dcecf056ea817aae967de401b45
1 parent
bbeb7b5c
Fix slirp redirection on systems without a useful host IP address.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1837 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
11 additions
and
10 deletions
slirp/misc.c
... | ... | @@ -88,15 +88,16 @@ void |
88 | 88 | getouraddr() |
89 | 89 | { |
90 | 90 | char buff[256]; |
91 | - struct hostent *he; | |
92 | - | |
93 | - if (gethostname(buff,256) < 0) | |
94 | - return; | |
95 | - | |
96 | - if ((he = gethostbyname(buff)) == NULL) | |
97 | - return; | |
98 | - | |
99 | - our_addr = *(struct in_addr *)he->h_addr; | |
91 | + struct hostent *he = NULL; | |
92 | + | |
93 | + if (gethostname(buff,256) == 0) | |
94 | + he = gethostbyname(buff); | |
95 | + if (he) | |
96 | + our_addr = *(struct in_addr *)he->h_addr; | |
97 | + /* If the host doesn't have a useful IP address then use the | |
98 | + guest side address. */ | |
99 | + if (our_addr.s_addr == 0 || our_addr.s_addr == loopback_addr.s_addr) | |
100 | + our_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS); | |
100 | 101 | } |
101 | 102 | |
102 | 103 | #if SIZEOF_CHAR_P == 8 | ... | ... |
slirp/slirp.c
... | ... | @@ -146,7 +146,6 @@ void slirp_init(void) |
146 | 146 | m_init(); |
147 | 147 | |
148 | 148 | /* set default addresses */ |
149 | - getouraddr(); | |
150 | 149 | inet_aton("127.0.0.1", &loopback_addr); |
151 | 150 | |
152 | 151 | if (get_dns_addr(&dns_addr) < 0) { |
... | ... | @@ -155,6 +154,7 @@ void slirp_init(void) |
155 | 154 | } |
156 | 155 | |
157 | 156 | inet_aton(CTL_SPECIAL, &special_addr); |
157 | + getouraddr(); | |
158 | 158 | } |
159 | 159 | |
160 | 160 | #define CONN_CANFSEND(so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED) | ... | ... |