From fe89ea7e351d304ca379125329018f5b96a2aded Mon Sep 17 00:00:00 2001 From: "eroman@chromium.org" Date: Thu, 12 May 2011 02:02:40 +0000 Subject: Miscelaneous cleanups to AddressList to make it harder to mis-use. - Removed all destructive non-const member functions -- these were dangerous since if you called them without first making a copy of the AddressList, it could mutate earlier copies. - Made AddressList::Data::head const, so new code added to AddressList cannot inadvertently introduce such dangerous mutations (won't compile). - Moved the non-trivial constructors and assign methods into factory methods (for added readability) - Removed the bool parameter from Copy (for added readability). Review URL: http://codereview.chromium.org/6880302 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85090 0039d316-1c4b-4281-b951-d872f2087c98 --- net/base/net_util.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'net/base/net_util.cc') diff --git a/net/base/net_util.cc b/net/base/net_util.cc index e97cb7f..059184a 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -2143,7 +2143,7 @@ const uint16* GetPortFieldFromAddrinfo(const struct addrinfo* info) { return GetPortFieldFromSockaddr(address, info->ai_addrlen); } -int GetPortFromAddrinfo(const struct addrinfo* info) { +uint16 GetPortFromAddrinfo(const struct addrinfo* info) { const uint16* port_field = GetPortFieldFromAddrinfo(info); if (!port_field) return -1; @@ -2175,6 +2175,16 @@ int GetPortFromSockaddr(const struct sockaddr* address, socklen_t address_len) { return ntohs(*port_field); } +// Assign |port| to each address in the linked list starting from |head|. +void SetPortForAllAddrinfos(struct addrinfo* head, uint16 port) { + DCHECK(head); + for (struct addrinfo* ai = head; ai; ai = ai->ai_next) { + uint16* port_field = GetPortFieldFromAddrinfo(ai); + if (port_field) + *port_field = htons(port); + } +} + bool IsLocalhost(const std::string& host) { if (host == "localhost" || host == "localhost.localdomain" || -- cgit v1.1