Platform.cpp
Go to the documentation of this file.
1 #include "Platform.hpp"
2 
3 // Platform specific
4 #if defined(_WIN32) || defined(__USE_W32_SOCKETS)
5  #include <ws2tcpip.h>
6  #ifdef _MSC_VER
7  #pragma comment(lib, "Ws2_32.lib")
8  #endif
9 #else
10  #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__)
11  #include <netinet/in.h>
12  #endif
13  #include <arpa/inet.h>
14 #endif
15 
16 #if defined(_WIN32) || defined(__USE_W32_SOCKETS)
17  #include <windows.h>
18 #endif
19 
20 #ifndef _WIN32
21  #include <unistd.h>
22 #endif
23 
24 namespace dai {
25 namespace platform {
26 
27 uint32_t getIPv4AddressAsBinary(std::string address) {
28  uint32_t binary = 0;
29  if(address == "") {
30  // inet_addr returns 0xFFFFFFFF if addr is ""
31  return 0;
32  }
33 
34 #if defined(_WIN32) || defined(__USE_W32_SOCKETS)
35  #if(_WIN32_WINNT <= 0x0501)
36  binary = inet_addr(address.c_str()); // for XP
37  #else
38  inet_pton(AF_INET, address.c_str(), &binary); // for Vista or higher
39  #endif
40 #else
41  inet_pton(AF_INET, address.c_str(), &binary);
42 #endif
43 
44  return binary;
45 }
46 
47 std::string getIPv4AddressAsString(std::uint32_t binary) {
48  char address[INET_ADDRSTRLEN] = {0};
49 
50 #if defined(_WIN32) || defined(__USE_W32_SOCKETS)
51  InetNtopA(AF_INET, &binary, address, sizeof(address));
52 #else
53  inet_ntop(AF_INET, &binary, address, sizeof(address));
54 #endif
55 
56  return {address};
57 }
58 
59 std::string getTempPath() {
60  std::string tmpPath;
61 #if defined(_WIN32) || defined(__USE_W32_SOCKETS)
62  char tmpPathBuffer[MAX_PATH];
63  GetTempPathA(MAX_PATH, tmpPathBuffer);
64  tmpPath = tmpPathBuffer;
65 #else
66  char tmpTemplate[] = "/tmp/depthai_XXXXXX";
67  char* tmpName = mkdtemp(tmpTemplate);
68  if(tmpName == nullptr) {
69  tmpPath = "/tmp";
70  } else {
71  tmpPath = tmpName;
72  tmpPath += '/';
73  }
74 #endif
75  return tmpPath;
76 }
77 
78 } // namespace platform
79 } // namespace dai
dai::platform::getIPv4AddressAsBinary
uint32_t getIPv4AddressAsBinary(std::string address)
Definition: Platform.cpp:27
dai::platform::getTempPath
std::string getTempPath()
Definition: Platform.cpp:59
Platform.hpp
dai::platform::getIPv4AddressAsString
std::string getIPv4AddressAsString(std::uint32_t binary)
Definition: Platform.cpp:47
dai
Definition: CameraExposureOffset.hpp:6


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19