Daniel Stenberg <[EMAIL PROTECTED]> writes: > On Tue, 15 Jan 2002, Hrvoje Niksic wrote: > >> > I'd suggest that you instead pass around a 'struct hostent *' on >> > IPv4 only platforms >> >> Why? The rest of the code never needs anything from `struct hostent' >> except the list of addresses, and this is what my code extracts. > > Well, why extract the addresses when you can just leave them in the > struct and pass a pointer to that?
Because I'm caching the result of the lookup, and making a deep copy of `struct hostent' is not exactly easy. (Yes, I know libcurl does it, but the code is not exactly pretty, and I'd like to avoid doing that.) > I am only suggesting this as it makes things a lot easier. No that's fine, but I just don't see why things are any easier that way. One way or the other, the caller will want to deal with the address -- providing it through struct hostent or through an API call to `struct address_list' should not make a difference. > connect()ing on machines that support getaddrinfo() should be a matter of > running through the addrinfo-list and perform something in this style: > > struct addrinfo *ai; > > sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); > rc = connect(sockfd, ai->ai_addr, ai->ai_addrlen); Except the port number can be different for each connection. And it won't work in IPv4 where I don't have `struct addrinfo' handy.
