How to Connect Internal and External Networks at the same time : Windows

Delete Default Route

route delete 0.0.0.0

Add Gateway : Internal

route add 192.168.10.0 mask 255.255.255.0 192.168.10.1 -p

Add Gateway : External

route add 0.0.0.0 mask 0.0.0.0 192.168.20.1 -p

Check It!

route print
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.20.254 192.168.20.151 55
0.0.0.0 0.0.0.0 192.168.1.1 192.168.1.103 45

===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
192.168.1.0 255.255.255.0 192.168.1.1 1
192.168.3.0 255.255.255.0 192.168.3.1 1

Routes stream to specified buffer

Developer Command Prompt for VS 2019

  1. cl basic_ios_rdbuf.cpp /EHsc

MSDN Source Code

  1. #include <ios>
  2. #include <iostream>
  3. #include <fstream>
  4.  
  5. int main( ) 
  6. {
  7.    using namespace std;
  8.    ofstream file( "rdbuf.txt" );
  9.    streambuf *x = cout.rdbuf( file.rdbuf( ) );
  10.    cout << "test" << endl; // Goes to file
  11.    cout.rdbuf(x);
  12.    cout << "test2" << endl; //normal
  13. }

How to expose a local server behind a NAT or firewall to the internet

Download FRP Server & Client

Modify frps.ini

  1. [root@VM_0_5_centos frp_0.25.3_linux_amd64]# cat frps.ini
  2. [common]
  3. bind_port = xxxxxx
  4. dashboard_port = xxxxxx
  5. dashboard_user = xxxxxxxxxxxxxxxx
  6. dashboard_pwd = xxxxxxxxxxxxxxxx
  7. allow_ports = xxxxx-xxxxx
  8. token = xxxxxxxxxxxxxxxx
  9. max_pool_count = 10
  10. pool_count = 3

Start frps

  1. [root@VM_0_5_centos frp_0.25.3_linux_amd64]# ./frps -c ./frps.ini

Modify frpc.ini

  1. root@imx6ul7d:~/frp# cat frpc.ini 
  2. [common]
  3. server_addr = qinuu.com
  4. server_port = xxxxxx
  5. token = xxxxxxxxxxxxxxxx
  6. [ssh]
  7. type = tcp
  8. local_ip = 127.0.0.1
  9. local_port = 22
  10. remote_port = xxxxxx

Start frpc

root@imx6ul7d:~/frp# ./frpc -c ./frpc.ini

Start a systemd service

[root@VM_0_5_centos frp_0.25.3_linux_amd64]# cat /lib/systemd/system/frps.service
[Unit]
Description=Frp Server Service
After=network.target
 
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/frp/frp_0.25.3_linux_amd64/frps -c /usr/local/frp/frp_0.25.3_linux_amd64/frps.ini
 
[Install]
WantedBy=multi-user.targethis
 
[root@VM_0_5_centos frp_0.25.3_linux_amd64]# systemctl start frps
[root@VM_0_5_centos frp_0.25.3_linux_amd64]# systemctl enable frps
[root@VM_0_5_centos frp_0.25.3_linux_amd64]# systemctl status frps

Some built-in macros inside CMakeSettings.json:

  • ${workspaceRoot} – provides the full path to the workspace folder
  • ${workspaceHash} – hash of workspace location; useful for creating a unique identifier for the current workspace (e.g. to use in folder paths)
  • ${projectFile} – the full path for the root CMakeLists.txt
  • ${projectDir} – the full path to the folder of the root CMakeLists.txt file
  • ${thisFile} – the full path to the CMakeSettings.json file
  • ${name} – the name of the configuration
  • ${generator} – the name of the CMake generator used in this configuration

How to Build Qt From Source Codes (QT 5.12 + Visual Studio 2017)

msvc-desktop.conf

  1. C:\Qt\5.12.0\Src\qtbase\mkspecs\common\msvc-desktop.conf
  2.  
  3. QMAKE_CFLAGS_RELEASE    = $QMAKE_CFLAGS_OPTIMIZE -MT
  4. QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += $QMAKE_CFLAGS_OPTIMIZE -Zi -MT
  5. QMAKE_CFLAGS_DEBUG      = -Zi -MTd

qt5vars.cmd

  1. REM Set up \Microsoft Visual Studio 2017, where arch is \c amd64, \c x86, etc.
  2. CALL "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86
  3. SET _ROOT=C:\Qt\5.12.0\Src
  4. SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
  5. REM Uncomment the below line when using a git checkout of the source repository
  6. REM SET PATH=%_ROOT%\qtrepotools\bin;%PATH%
  7. SET _ROOT=

make & make install

  1. C:\Qt\5.12.0\Src>qt5vars.cmd
  2. C:\Qt\5.12.0\Src>configure -opensource -confirm-license
  3. C:\Qt\5.12.0\Src>jom -j 8
  4. C:\Qt\5.12.0\Src>jom install

CMake & Arm Cross compilation based Windows systems (Visual Studio)

CMakeLists.txt

  1. cmake_minimum_required(VERSION 3.12)
  2. project(network_information)
  3.  
  4. SET(CMAKE_SYSTEM_NAME Linux)
  5.  
  6. add_definitions("-std=c++17")
  7.  
  8. # specify the cross compiler
  9. SET(CMAKE_C_COMPILER   arm-linux-gnueabihf-gcc)
  10. SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
  11.  
  12. if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
  13.     set(BOOST_ROOT "C:/MinGW/msys/1.0/home/d/boost_1_68_0")
  14. else()
  15.     set(BOOST_ROOT /root/Downloads/boost_1_68_0)
  16. endif()
  17.  
  18. set(Boost_USE_STATIC_LIBS ON)
  19. set(Boost_USE_MULTITHREADED ON)
  20.  
  21. include_directories(sdk/inc)
  22. link_directories("sdk/lib")
  23.  
  24. add_executable(network_information
  25. 		network_information.cpp
  26. 		)
  27. TARGET_LINK_LIBRARIES(network_information "-lpthread" "-ldl" "-lpos" "-lrt" "-lpng" "-liconv" "-lfreetype" "-lz")

GNUlinux_config.cmake

  1. set(GNULINUX_PLATFORM ON)
  2. set(CMAKE_SYSTEM_NAME "Linux")
  3. set(CMAKE_SYSTEM_PROCESSOR "arm")
  4.  
  5. if(NOT DEFINED ENV{NE10_LINUX_TARGET_ARCH})
  6.    set(NE10_LINUX_TARGET_ARCH "armv7")
  7. else()
  8.    set(NE10_LINUX_TARGET_ARCH $ENV{NE10_LINUX_TARGET_ARCH})
  9. endif()
  10.  
  11. if(NE10_LINUX_TARGET_ARCH STREQUAL "armv7")
  12.    set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
  13.    set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
  14.    set(CMAKE_ASM_COMPILER arm-linux-gnueabihf-as)
  15.    find_program(CMAKE_AR NAMES "arm-linux-gnueabihf-ar")
  16.    find_program(CMAKE_RANLIB NAMES "arm-linux-gnueabihf-ranlib")
  17. elseif(NE10_LINUX_TARGET_ARCH STREQUAL "aarch64")
  18.    set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
  19.    set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
  20.    set(CMAKE_ASM_COMPILER aarch64-linux-gnu-as)
  21.    find_program(CMAKE_AR NAMES "aarch64-linux-gnu-ar")
  22.    find_program(CMAKE_RANLIB NAMES "aarch64-linux-gnu-ranlib")
  23. endif()
  24.  
  25. mark_as_advanced(CMAKE_AR)
  26. mark_as_advanced(CMAKE_RANLIB)

CMakeSettings.json

  1. {
  2.   "configurations": [
  3.     {
  4.       "environments": [
  5.         {
  6.           "MINGW64_ROOT": "C:\\MinGW\\msys\\1.0\\home\\d\\gcc-linaro-7.3.1-2018.05-i686-mingw32_arm-linux-gnueabihf",
  7.           "BIN_ROOT": "${env.MINGW64_ROOT}\\bin",
  8.           "FLAVOR": "x86_64-w64-mingw32",
  9.           "TOOLSET_VERSION": "7.3.0",
  10.           "PATH": "${env.MINGW64_ROOT}\\bin;${env.MINGW64_ROOT}\\..\\usr\\local\\bin;${env.MINGW64_ROOT}\\..\\usr\\bin;${env.MINGW64_ROOT}\\..\\bin;${env.PATH}",
  11.           "INCLUDE": "${env.INCLUDE};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION};${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\tr1;${env.MINGW64_ROOT}\\include\\c++\\${env.TOOLSET_VERSION}\\${env.FLAVOR}",
  12.           "environment": "mingw_64"
  13.         }
  14.       ],
  15.       "name": "Mingw64-Release",
  16.       "generator": "Ninja",
  17.       "configurationType": "Release",
  18.       "inheritEnvironments": [
  19.         "mingw_64"
  20.       ],
  21.       "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}",
  22.       "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}",
  23.       "cmakeCommandArgs": "",
  24.       "buildCommandArgs": "-v",
  25.       "ctestCommandArgs": "",
  26.       "intelliSenseMode": "linux-gcc-x64",
  27.       "variables": [
  28.         {
  29.           "name": "CMAKE_TOOLCHAIN_FILE",
  30.           "value": "GNUlinux_config.cmake"
  31.         },
  32.         {
  33.           "name": "CMAKE_C_COMPILER",
  34.           "value": "${env.BIN_ROOT}\\arm-linux-gnueabihf-gcc.exe"
  35.         },
  36.         {
  37.           "name": "CMAKE_CXX_COMPILER",
  38.           "value": "${env.BIN_ROOT}\\arm-linux-gnueabihf-g++.exe"
  39.         }
  40.       ]
  41.     }
  42.   ]
  43. }

CMake & Arm Cross compilation based Windows systems (CLion)

CMakeLists.txt

  1. cmake_minimum_required(VERSION 3.12)
  2. project(untitled1)
  3.  
  4. SET(CMAKE_SYSTEM_NAME Linux)
  5.  
  6. add_definitions("-std=c++17")
  7.  
  8. SET(CMAKE_C_COMPILER   arm-linux-gnueabihf-gcc)
  9. SET(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
  10.  
  11. if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
  12.     set(BOOST_ROOT "C:/MinGW/msys/1.0/home/d/boost_1_68_0")
  13. else()
  14.     set(BOOST_ROOT /root/Downloads/boost_1_68_0)
  15. endif()
  16.  
  17. set(Boost_USE_STATIC_LIBS ON)
  18. set(Boost_USE_MULTITHREADED ON)
  19.  
  20. find_package(Boost COMPONENTS regex system date_time timer REQUIRED)
  21. if(Boost_FOUND)
  22.     include_directories(${Boost_INCLUDE_DIRS})
  23.     link_directories("${Boost_INCLUDE_DIRS}/stage/lib")
  24.     include_directories(sdk/inc)
  25.     link_directories("sdk/lib")
  26.     MESSAGE( STATUS "Boost_INCLUDE_DIRS = ${Boost_INCLUDE_DIRS}.")
  27.     MESSAGE( STATUS "Boost_LIBRARIES = ${Boost_LIBRARIES}.")
  28.     MESSAGE( STATUS "Boost_LIB_VERSION = ${Boost_LIB_VERSION}.")
  29.  
  30.     add_executable(untitled1 main.cpp)
  31.  
  32.     TARGET_LINK_LIBRARIES(untitled1 ${Boost_LIBRARIES} "-lpthread" "-lpos" "-lrt" "-lpng" "-liconv" "-lfreetype" "-lz" "-l:libboost_system.a")
  33. endif()

GNUlinux_config.cmake

  1. set(GNULINUX_PLATFORM ON)
  2. set(CMAKE_SYSTEM_NAME "Linux")
  3. set(CMAKE_SYSTEM_PROCESSOR "arm")
  4.  
  5. if(NOT DEFINED ENV{NE10_LINUX_TARGET_ARCH})
  6.    set(NE10_LINUX_TARGET_ARCH "armv7")
  7. else()
  8.    set(NE10_LINUX_TARGET_ARCH $ENV{NE10_LINUX_TARGET_ARCH})
  9. endif()
  10.  
  11. if(NE10_LINUX_TARGET_ARCH STREQUAL "armv7")
  12.    set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
  13.    set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
  14.    set(CMAKE_ASM_COMPILER arm-linux-gnueabihf-as)
  15.    find_program(CMAKE_AR NAMES "arm-linux-gnueabihf-ar")
  16.    find_program(CMAKE_RANLIB NAMES "arm-linux-gnueabihf-ranlib")
  17. elseif(NE10_LINUX_TARGET_ARCH STREQUAL "aarch64")
  18.    set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
  19.    set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
  20.    set(CMAKE_ASM_COMPILER aarch64-linux-gnu-as)
  21.    find_program(CMAKE_AR NAMES "aarch64-linux-gnu-ar")
  22.    find_program(CMAKE_RANLIB NAMES "aarch64-linux-gnu-ranlib")
  23. endif()
  24.  
  25. mark_as_advanced(CMAKE_AR)
  26. mark_as_advanced(CMAKE_RANLIB)

The Most Important Thing on Windows

cmake -DCMAKE_TOOLCHAIN_FILE=GNUlinux_config.cmake ..