2
2
* General purpose functions.
4
* Copyright 2000-2007 Willy Tarreau <w@1wt.eu>
4
* Copyright 2000-2009 Willy Tarreau <w@1wt.eu>
6
6
* This program is free software; you can redistribute it and/or
7
7
* modify it under the terms of the GNU General Public License
244
* converts <str> to a struct sockaddr_in* which is locally allocated, and a
245
* port range consisting in two integers. The low and high end are always set
246
* even if the port is unspecified, in which case (0,0) is returned. The low
247
* port is set in the sockaddr_in. Thus, it is enough to check the size of the
248
* returned range to know if an array must be allocated or not. The format is
249
* "addr[:port[-port]]", where "addr" can be a dotted IPv4 address, a host
250
* name, or empty or "*" to indicate INADDR_ANY.
252
struct sockaddr_in *str2sa_range(char *str, int *low, int *high)
254
static struct sockaddr_in sa;
258
memset(&sa, 0, sizeof(sa));
263
if ((c = strrchr(str,':')) != NULL) {
266
sep = strchr(c, '-');
279
if (*str == '*' || *str == '\0') { /* INADDR_ANY */
280
sa.sin_addr.s_addr = INADDR_ANY;
282
else if (!inet_pton(AF_INET, str, &sa.sin_addr)) {
285
if ((he = gethostbyname(str)) == NULL) {
286
Alert("Invalid server name: '%s'\n", str);
289
sa.sin_addr = *(struct in_addr *) *(he->h_addr_list);
291
sa.sin_port = htons(portl);
292
sa.sin_family = AF_INET;
244
303
* converts <str> to two struct in_addr* which must be pre-allocated.
245
304
* The format is "addr[/mask]", where "addr" cannot be empty, and mask
246
305
* is optionnal and either in the dotted or CIDR notation.
305
364
* Parse IP address found in url.
307
static int url2ip(const char *addr, struct in_addr *dst)
366
int url2ip(const char *addr, struct in_addr *dst)
309
368
int saw_digit, octets, ch;
310
369
u_char tmp[4], *tp;