- /* To equate the two host names for the purposes of persistent
- connections, they need to share all the IP addresses in the
- list. */
- success = address_list_match_all (pc_last_host_ip, this_host_ip);
- address_list_release (this_host_ip);
- if (!success)
- return 0;
+ /* If the host is the same, we're in business. If not, there is
+ still hope -- read below. */
+ if (0 != strcasecmp (host, pconn.host))
+ {
+ /* This is somewhat evil, but works in practice: if the address
+ that pconn.socket is connected to is one of the IP addresses
+ HOST resolves to, we don't need to reconnect. #### Is it
+ correct to do this by default? */
+ int found;
+ ip_address ip;
+ struct address_list *al;
+
+ if (!socket_ip_address (pconn.socket, &ip, 0))
+ {
+ /* Can't get the peer's address -- something must be wrong
+ with the connection. */
+ invalidate_persistent ();
+ return 0;
+ }
+ al = lookup_host (host, 0);
+ if (!al)
+ {
+ *host_lookup_failed = 1;
+ return 0;
+ }
+
+ found = address_list_find (al, &ip);
+ address_list_release (al);
+
+ if (!found)
+ return 0;
+
+ /* HOST resolves to an address pconn.sock is connected to -- no
+ need to reconnect. */
+ }