--------------------- PatchSet 10184 Date: 2007/11/30 16:42:26 Author: adri Branch: store_copy Tag: (none) Log: revert dodgy change! Members: src/tools.c:1.62.2.2->1.62.2.3 Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.62.2.2 retrieving revision 1.62.2.3 diff -u -r1.62.2.2 -r1.62.2.3 --- squid/src/tools.c 30 Nov 2007 16:37:01 -0000 1.62.2.2 +++ squid/src/tools.c 30 Nov 2007 16:42:26 -0000 1.62.2.3 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.62.2.2 2007/11/30 16:37:01 adri Exp $ + * $Id: tools.c,v 1.62.2.3 2007/11/30 16:42:26 adri Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -1403,5 +1403,45 @@ const char * xinet_ntoa(const struct in_addr addr) { - return inet_ntoa(addr); + return inet_ntoa(addr); +} + +/** + * Parse a socket address (host:port), fill the given sockaddr_in structure + * Returns FALSE on failure, TRUE on success + * Destroys s + */ +int +parse_sockaddr(char *s, struct sockaddr_in *addr) +{ + char *host, *tmp, *colon; + unsigned short port = 0; + const struct hostent *hp; + + host = NULL; + port = 0; + if ((colon = strchr(s, ':'))) { + /* host:port */ + host = s; + *colon = '\0'; + port = xatos(colon + 1); + if (0 == port) + return FALSE; + } else if ((port = strtol(s, &tmp, 10)), !*tmp) { + /* port */ + } else { + host = s; + port = 0; + } + addr->sin_port = htons(port); + if (NULL == host) + addr->sin_addr = any_addr; + else if (1 == safe_inet_addr(host, &addr->sin_addr)) + (void) 0; + else if ((hp = gethostbyname(host))) /* dont use ipcache */ + addr->sin_addr = inaddrFromHostent(hp); + else + return FALSE; + addr->sin_family = AF_INET; + return TRUE; }