mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ee1aa50315 | ||
|
de0c75694a |
@@ -21,10 +21,24 @@
|
|||||||
#include <Standard_NullObject.hxx>
|
#include <Standard_NullObject.hxx>
|
||||||
#include <TCollection_AsciiString.hxx>
|
#include <TCollection_AsciiString.hxx>
|
||||||
|
|
||||||
const OSD_WhoAmI Iam = OSD_WHost;
|
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
#ifndef HAVE_IFADDRS
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#include <android/api-level.h>
|
||||||
|
#if (__ANDROID_API__ >= 24)
|
||||||
|
#define HAVE_IFADDRS
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define HAVE_IFADDRS
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#ifdef HAVE_IFADDRS
|
||||||
|
#include <ifaddrs.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/utsname.h> // For 'uname'
|
#include <sys/utsname.h> // For 'uname'
|
||||||
#include <netdb.h> // This is for 'gethostbyname'
|
#include <netdb.h> // This is for 'gethostbyname'
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -89,7 +103,7 @@ char value[65];
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
status = gethostname(value, 64);
|
status = gethostname(value, 64);
|
||||||
if (status == -1) myError.SetValue(errno, Iam, "Host Name");
|
if (status == -1) myError.SetValue(errno, OSD_WHost, "Host Name");
|
||||||
|
|
||||||
result = value;
|
result = value;
|
||||||
return(result);
|
return(result);
|
||||||
@@ -116,25 +130,67 @@ Standard_Integer OSD_Host::AvailableMemory(){
|
|||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
|
||||||
TCollection_AsciiString OSD_Host::InternetAddress(){
|
TCollection_AsciiString OSD_Host::InternetAddress()
|
||||||
struct hostent internet_address;
|
{
|
||||||
int a,b,c,d;
|
TCollection_AsciiString aResult;
|
||||||
char buffer[16];
|
#ifdef HAVE_IFADDRS
|
||||||
TCollection_AsciiString result,host;
|
struct ifaddrs* anAddrFullInfo = NULL;
|
||||||
|
getifaddrs (&anAddrFullInfo);
|
||||||
|
for (struct ifaddrs* anAddrIter = anAddrFullInfo; anAddrIter != NULL; anAddrIter = anAddrIter->ifa_next)
|
||||||
|
{
|
||||||
|
if (!anAddrIter->ifa_addr)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
host = HostName();
|
if (anAddrIter->ifa_addr->sa_family == AF_INET)
|
||||||
memcpy(&internet_address,
|
{
|
||||||
gethostbyname(host.ToCString()),
|
// IP4 Address
|
||||||
sizeof(struct hostent));
|
char aBuffer[INET_ADDRSTRLEN];
|
||||||
|
void* aTmpAddrPtr = &((struct sockaddr_in* )anAddrIter->ifa_addr)->sin_addr;
|
||||||
// Gets each bytes into integers
|
inet_ntop (AF_INET, aTmpAddrPtr, aBuffer, sizeof(aBuffer));
|
||||||
a = (unsigned char)internet_address.h_addr_list[0][0];
|
if (strcmp (aBuffer, "127.0.0.1") != 0) // skip localhost address
|
||||||
b = (unsigned char)internet_address.h_addr_list[0][1];
|
{
|
||||||
c = (unsigned char)internet_address.h_addr_list[0][2];
|
aResult = aBuffer;
|
||||||
d = (unsigned char)internet_address.h_addr_list[0][3];
|
break;
|
||||||
sprintf(buffer,"%d.%d.%d.%d",a,b,c,d);
|
}
|
||||||
result = buffer;
|
}
|
||||||
return(result);
|
else if (anAddrIter->ifa_addr->sa_family == AF_INET6)
|
||||||
|
{
|
||||||
|
// IP6 Address
|
||||||
|
char aBuffer[INET6_ADDRSTRLEN];
|
||||||
|
void* aTmpAddrPtr = &((struct sockaddr_in6 *)anAddrIter->ifa_addr)->sin6_addr;
|
||||||
|
inet_ntop (AF_INET6, aTmpAddrPtr, aBuffer, sizeof(aBuffer));
|
||||||
|
if (strcmp (aBuffer, "::1") != 0) // skip localhost address
|
||||||
|
{
|
||||||
|
aResult = aBuffer;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (anAddrFullInfo != NULL)
|
||||||
|
{
|
||||||
|
freeifaddrs (anAddrFullInfo);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// fallback for ancient systems
|
||||||
|
const TCollection_AsciiString aHost = HostName();
|
||||||
|
if (struct hostent* anAddr = gethostbyname (aHost.ToCString()))
|
||||||
|
{
|
||||||
|
char aBuffer[16];
|
||||||
|
const int a = (unsigned char)anAddr->h_addr_list[0][0];
|
||||||
|
const int b = (unsigned char)anAddr->h_addr_list[0][1];
|
||||||
|
const int c = (unsigned char)anAddr->h_addr_list[0][2];
|
||||||
|
const int d = (unsigned char)anAddr->h_addr_list[0][3];
|
||||||
|
sprintf (aBuffer, "%d.%d.%d.%d", a, b, c, d);
|
||||||
|
aResult = aBuffer;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
if (aResult.IsEmpty())
|
||||||
|
{
|
||||||
|
return "127.0.0.1";
|
||||||
|
}
|
||||||
|
return aResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =========================================================================
|
// =========================================================================
|
||||||
|
@@ -164,12 +164,20 @@ Handle(StepBasic_PersonAndOrganization) STEPConstruct_AP203Context::DefaultPerso
|
|||||||
OSD_Host aHost;
|
OSD_Host aHost;
|
||||||
TCollection_AsciiString anIP = aHost.InternetAddress();
|
TCollection_AsciiString anIP = aHost.InternetAddress();
|
||||||
// cut off last number
|
// cut off last number
|
||||||
Standard_Integer aLastDotIndex = anIP.SearchFromEnd (".");
|
const Standard_Integer aLastDotIndex = anIP.SearchFromEnd (".");
|
||||||
if (aLastDotIndex >0)
|
if (aLastDotIndex > 0)
|
||||||
{
|
{
|
||||||
|
// IPv4
|
||||||
anIP.Trunc (aLastDotIndex - 1);
|
anIP.Trunc (aLastDotIndex - 1);
|
||||||
orgId->AssignCat (anIP.ToCString());
|
orgId->AssignCat (anIP.ToCString());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// IPv6
|
||||||
|
const Standard_Integer aLastColonIndex = anIP.SearchFromEnd (":");
|
||||||
|
anIP.Trunc (aLastColonIndex - 1);
|
||||||
|
orgId->AssignCat (anIP.ToCString());
|
||||||
|
}
|
||||||
|
|
||||||
// create organization
|
// create organization
|
||||||
Handle(StepBasic_Organization) aOrg = new StepBasic_Organization;
|
Handle(StepBasic_Organization) aOrg = new StepBasic_Organization;
|
||||||
|
Reference in New Issue
Block a user