MCPcopy Create free account
hub / github.com/acl-dev/acl / getRemoteAddr

Method getRemoteAddr

lib_acl_cpp/src/http/HttpServletRequest.cpp:408–439  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406}
407
408const char* HttpServletRequest::getRemoteAddr(void) const
409{
410 if (cgi_mode_) {
411 const char* ptr = acl_getenv("REMOTE_ADDR");
412 if (ptr && *ptr) {
413 return ptr;
414 }
415 logger_warn("no REMOTE_ADDR from acl_getenv");
416 return NULL;
417 }
418 if (client_ == NULL) {
419 return NULL;
420 }
421 const char* ptr = client_->get_stream().get_peer();
422 if (*ptr == 0) {
423 logger_warn("get_peer return empty string");
424 return NULL;
425 }
426
427 if (remoteAddr_ == NULL) {
428 const_cast<HttpServletRequest*>(this)->remoteAddr_ = (char*)
429 dbuf_->dbuf_alloc(ADDR_LEN);
430 }
431
432 safe_snprintf(const_cast<HttpServletRequest*>(this)->remoteAddr_,
433 ADDR_LEN, "%s", ptr);
434 char* p = (char*) strchr(remoteAddr_, ':');
435 if (p) {
436 *p = 0;
437 }
438 return remoteAddr_;
439}
440
441unsigned short HttpServletRequest::getRemotePort(void) const
442{

Callers

nothing calls this directly

Calls 5

acl_getenvFunction · 0.85
safe_snprintfFunction · 0.85
dbuf_allocMethod · 0.80
get_peerMethod · 0.45
get_streamMethod · 0.45

Tested by

no test coverage detected