MCPcopy Create free account
hub / github.com/apache/httpd / ap_proxy_is_ipaddr

Function ap_proxy_is_ipaddr

modules/proxy/proxy_util.c:466–584  ·  view source on GitHub ↗

Return TRUE if addr represents an IP address (or an IP network address) */

Source from the content-addressed store, hash-verified

464
465/* Return TRUE if addr represents an IP address (or an IP network address) */
466PROXY_DECLARE(int) ap_proxy_is_ipaddr(struct dirconn_entry *This, apr_pool_t *p)
467{
468 const char *addr = This->name;
469 long ip_addr[4];
470 int i, quads;
471 long bits;
472
473 /*
474 * if the address is given with an explicit netmask, use that
475 * Due to a deficiency in apr_inet_addr(), it is impossible to parse
476 * "partial" addresses (with less than 4 quads) correctly, i.e.
477 * 192.168.123 is parsed as 192.168.0.123, which is not what I want.
478 * I therefore have to parse the IP address manually:
479 * if (proxy_readmask(This->name, &This->addr.s_addr, &This->mask.s_addr) == 0)
480 * addr and mask were set by proxy_readmask()
481 * return 1;
482 */
483
484 /*
485 * Parse IP addr manually, optionally allowing
486 * abbreviated net addresses like 192.168.
487 */
488
489 /* Iterate over up to 4 (dotted) quads. */
490 for (quads = 0; quads < 4 && *addr != '\0'; ++quads) {
491 char *tmp;
492
493 if (*addr == '/' && quads > 0) { /* netmask starts here. */
494 break;
495 }
496
497 if (!apr_isdigit(*addr)) {
498 return 0; /* no digit at start of quad */
499 }
500
501 ip_addr[quads] = strtol(addr, &tmp, 0);
502
503 if (tmp == addr) { /* expected a digit, found something else */
504 return 0;
505 }
506
507 if (ip_addr[quads] < 0 || ip_addr[quads] > 255) {
508 /* invalid octet */
509 return 0;
510 }
511
512 addr = tmp;
513
514 if (*addr == '.' && quads != 3) {
515 ++addr; /* after the 4th quad, a dot would be illegal */
516 }
517 }
518
519 for (This->addr.s_addr = 0, i = 0; i < quads; ++i) {
520 This->addr.s_addr |= htonl(ip_addr[i] << (24 - 8 * i));
521 }
522
523 if (addr[0] == '/' && apr_isdigit(addr[1])) { /* net mask follows: */

Callers 1

set_proxy_dirconnFunction · 0.85

Calls 1

ap_log_errorFunction · 0.50

Tested by

no test coverage detected