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

Function proxy_match_ipaddr

modules/proxy/proxy_util.c:587–672  ·  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

585
586/* Return TRUE if addr represents an IP address (or an IP network address) */
587static int proxy_match_ipaddr(struct dirconn_entry *This, request_rec *r)
588{
589 int i, ip_addr[4];
590 struct in_addr addr, *ip;
591 const char *host = proxy_get_host_of_request(r);
592
593 if (host == NULL) { /* oops! */
594 return 0;
595 }
596
597 memset(&addr, '\0', sizeof addr);
598 memset(ip_addr, '\0', sizeof ip_addr);
599
600 if (4 == sscanf(host, "%d.%d.%d.%d", &ip_addr[0], &ip_addr[1], &ip_addr[2], &ip_addr[3])) {
601 for (addr.s_addr = 0, i = 0; i < 4; ++i) {
602 /* ap_proxy_is_ipaddr() already confirmed that we have
603 * a valid octet in ip_addr[i]
604 */
605 addr.s_addr |= htonl(ip_addr[i] << (24 - 8 * i));
606 }
607
608 if (This->addr.s_addr == (addr.s_addr & This->mask.s_addr)) {
609#if DEBUGGING
610 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00903)
611 "1)IP-Match: %s[%s] <-> ", host, inet_ntoa(addr));
612 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00904)
613 "%s/", inet_ntoa(This->addr));
614 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00905)
615 "%s", inet_ntoa(This->mask));
616#endif
617 return 1;
618 }
619#if DEBUGGING
620 else {
621 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00906)
622 "1)IP-NoMatch: %s[%s] <-> ", host, inet_ntoa(addr));
623 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00907)
624 "%s/", inet_ntoa(This->addr));
625 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00908)
626 "%s", inet_ntoa(This->mask));
627 }
628#endif
629 }
630 else {
631 struct apr_sockaddr_t *reqaddr;
632
633 if (apr_sockaddr_info_get(&reqaddr, host, APR_UNSPEC, 0, 0, r->pool)
634 != APR_SUCCESS) {
635#if DEBUGGING
636 ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, APLOGNO(00909)
637 "2)IP-NoMatch: hostname=%s msg=Host not found", host);
638#endif
639 return 0;
640 }
641
642 /* Try to deal with multiple IP addr's for a host */
643 /* FIXME: This needs to be able to deal with IPv6 */
644 while (reqaddr) {

Callers

nothing calls this directly

Calls 2

ap_log_errorFunction · 0.50

Tested by

no test coverage detected