X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=src%2FgdcmUtil.cxx;h=948fd2cc461bbe11a73c1807014395adacb339b1;hb=74e3bc05fade5a18f193e7d1122c74756c0e689e;hp=dc335e9c7c4c83056bd872a1dadda48866a1b5ef;hpb=4fa46bd01372e9022b80d2a69ff93a9dc8e70348;p=gdcm.git diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index dc335e9c..948fd2cc 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2004/12/05 21:46:44 $ - Version: $Revision: 1.69 $ + Date: $Date: 2005/01/05 15:19:42 $ + Version: $Revision: 1.71 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,7 +27,7 @@ #include //only included in implementation file #include //only included in implementation file -#if defined _MSC_VER +#if defined(_MSC_VER) #include // for gethostname & gethostbyname #undef GetCurrentTime #else @@ -290,6 +290,25 @@ bool Util::DicomStringEqual(const std::string& s1, const char *s2) return s1_even == s2_even; } + + +/** + * \ingroup Util + * \brief tells us if the processor we are working with is BigEndian or not + */ +bool Util::IsCurrentProcessorBigEndian() +{ + uint16_t intVal = 1; + uint8_t bigEndianRepr[4] = { 0x00, 0x00, 0x00, 0x01 }; + int res = memcmp(reinterpret_cast(&intVal), + reinterpret_cast(bigEndianRepr), 4); + if (res == 0) + return true; + else + return false; +} + + /** * \ingroup Util * \brief Return the IP adress of the machine writting the DICOM image @@ -304,6 +323,19 @@ std::string Util::GetIPAddress() # define HOST_NAME_MAX 255 // In this case we should maybe check the string was not truncated. // But I don't known how to check that... +#if defined(_MSC_VER) || defined(__BORLANDC__) + // with WinSock DLL we need to initialise the WinSock before using gethostname + WORD wVersionRequested = MAKEWORD(1,0); + WSADATA WSAData; + int err = WSAStartup(wVersionRequested,&WSAData); + if (err != 0) { + /* Tell the user that we could not find a usable */ + /* WinSock DLL. */ + WSACleanup(); + return "127.0.0.1"; + } +#endif + #endif //HOST_NAME_MAX std::string str; @@ -325,6 +357,11 @@ std::string Util::GetIPAddress() (unsigned int)((unsigned char*)pHost->h_addr_list[i])[j]); } // str now contains one local IP address + +#if defined(_MSC_VER) || defined(__BORLANDC__) + WSACleanup(); +#endif + } } // If an error occur r == -1