From 299cfa9449aa90a2ac9639a583ec4b13cba1a85a Mon Sep 17 00:00:00 2001 From: bellard Date: Wed, 3 May 2006 19:58:17 +0000 Subject: separate alias_addr (10.0.2.2) from our_addr (Ed Swierk) git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1895 c046a42c-6fe2-441c-8c8c-71466251a162 --- ip_icmp.c | 7 +++---- main.h | 1 + misc.c | 6 ++---- slirp.c | 3 +++ socket.c | 2 +- tcp_subr.c | 4 ++-- udp.c | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ip_icmp.c b/ip_icmp.c index c8aaf4f..0e97af9 100644 --- a/ip_icmp.c +++ b/ip_icmp.c @@ -113,8 +113,7 @@ int hlen; case ICMP_ECHO: icp->icmp_type = ICMP_ECHOREPLY; ip->ip_len += hlen; /* since ip_input subtracts this */ - if (ip->ip_dst.s_addr == our_addr.s_addr || - (ip->ip_dst.s_addr == (special_addr.s_addr | htonl(CTL_ALIAS)))) { + if (ip->ip_dst.s_addr == alias_addr.s_addr) { icmp_reflect(m); } else { struct socket *so; @@ -163,7 +162,7 @@ int hlen; strerror(errno)); udp_detach(so); } - } /* if ip->ip_dst.s_addr == our_addr.s_addr */ + } /* if ip->ip_dst.s_addr == alias_addr.s_addr */ break; case ICMP_UNREACH: /* XXX? report error? close socket? */ @@ -321,7 +320,7 @@ char *message; ip->ip_ttl = MAXTTL; ip->ip_p = IPPROTO_ICMP; ip->ip_dst = ip->ip_src; /* ip adresses */ - ip->ip_src = our_addr; + ip->ip_src = alias_addr; (void)ip_output((struct socket *)NULL, m); diff --git a/main.h b/main.h index 354ec24..97062f1 100644 --- a/main.h +++ b/main.h @@ -34,6 +34,7 @@ extern u_int curtime; extern fd_set *global_readfds, *global_writefds, *global_xfds; extern struct in_addr ctl_addr; extern struct in_addr special_addr; +extern struct in_addr alias_addr; extern struct in_addr our_addr; extern struct in_addr loopback_addr; extern struct in_addr dns_addr; diff --git a/misc.c b/misc.c index 3f467ab..299653c 100644 --- a/misc.c +++ b/misc.c @@ -91,10 +91,8 @@ void getouraddr() he = gethostbyname(buff); if (he) our_addr = *(struct in_addr *)he->h_addr; - /* If the host doesn't have a useful IP address then use the - guest side address. */ - if (our_addr.s_addr == 0 || our_addr.s_addr == loopback_addr.s_addr) - our_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS); + if (our_addr.s_addr == 0) + our_addr.s_addr = loopback_addr.s_addr; } #if SIZEOF_CHAR_P == 8 diff --git a/slirp.c b/slirp.c index 651487e..cf02ec3 100644 --- a/slirp.c +++ b/slirp.c @@ -9,6 +9,8 @@ struct in_addr loopback_addr; /* address for slirp virtual addresses */ struct in_addr special_addr; +/* virtual address alias for host */ +struct in_addr alias_addr; const uint8_t special_ethaddr[6] = { 0x52, 0x54, 0x00, 0x12, 0x35, 0x00 }; @@ -152,6 +154,7 @@ void slirp_init(void) } inet_aton(CTL_SPECIAL, &special_addr); + alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS); getouraddr(); } diff --git a/socket.c b/socket.c index 9c7cbc8..c7b381d 100644 --- a/socket.c +++ b/socket.c @@ -595,7 +595,7 @@ int flags; so->so_fport = addr.sin_port; if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr) - so->so_faddr = our_addr; + so->so_faddr = alias_addr; else so->so_faddr = addr.sin_addr; diff --git a/tcp_subr.c b/tcp_subr.c index 32f1d94..91df6b6 100644 --- a/tcp_subr.c +++ b/tcp_subr.c @@ -493,7 +493,7 @@ void tcp_connect(inso) struct socket *inso; so->so_faddr = addr.sin_addr; /* Translate connections from localhost to the real hostname */ if (so->so_faddr.s_addr == 0 || so->so_faddr.s_addr == loopback_addr.s_addr) - so->so_faddr = our_addr; + so->so_faddr = alias_addr; /* Close the accept() socket, set right state */ if (inso->so_state & SS_FACCEPTONCE) { @@ -826,7 +826,7 @@ struct mbuf *m; if (ns->so_faddr.s_addr == 0 || ns->so_faddr.s_addr == loopback_addr.s_addr) - ns->so_faddr = our_addr; + ns->so_faddr = alias_addr; ns->so_iptos = tcp_tos(ns); tp = sototcpcb(ns); diff --git a/udp.c b/udp.c index 96a3960..fe70970 100644 --- a/udp.c +++ b/udp.c @@ -645,7 +645,7 @@ int flags; so->so_fport = addr.sin_port; if (addr.sin_addr.s_addr == 0 || addr.sin_addr.s_addr == loopback_addr.s_addr) - so->so_faddr = our_addr; + so->so_faddr = alias_addr; else so->so_faddr = addr.sin_addr; -- cgit v1.1