MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / GetIPAddress

Method GetIPAddress

src/core/unixfsservices.cpp:482–522  ·  view source on GitHub ↗

returns IP address in network byte order

Source from the content-addressed store, hash-verified

480
481// returns IP address in network byte order
482bool cUnixFSServices::GetIPAddress(uint32& uiIPAddress)
483{
484 bool fGotAddress = false;
485 cDebug d(_T("cUnixFSServices::GetIPAddress"));
486
487#if SUPPORTS_NETWORKING && HAVE_SYS_UTSNAME_H
488 struct utsname utsnameBuf;
489 if (EFAULT != uname(&utsnameBuf))
490 {
491 d.TraceDetail("uname returned nodename: %s\n", utsnameBuf.nodename);
492
493 struct hostent* phostent = gethostbyname(utsnameBuf.nodename);
494
495 if (phostent)
496 {
497 ASSERT(AF_INET == phostent->h_addrtype);
498 ASSERT(sizeof(int32) == phostent->h_length);
499
500 if (phostent->h_length)
501 {
502 if (phostent->h_addr_list[0])
503 {
504 int32* pAddress = reinterpret_cast<int32*>(phostent->h_addr_list[0]);
505 uiIPAddress = *pAddress;
506 fGotAddress = true;
507 }
508 else
509 d.TraceError(_T("phostent->h_addr_list[0] was zero"));
510 }
511 else
512 d.TraceError(_T("phostent->h_length was zero"));
513 }
514 else
515 d.TraceError(_T("gethostbyname failed"));
516 }
517 else
518 d.TraceError(_T("uname failed"));
519#endif
520
521 return (fGotAddress);
522}
523
524bool cUnixFSServices::IsCaseSensitive() const
525{

Callers

nothing calls this directly

Calls 2

TraceDetailMethod · 0.60
TraceErrorMethod · 0.60

Tested by

no test coverage detected