Skip to content

Commit

Permalink
Initial work on OS/2 port
Browse files Browse the repository at this point in the history
  • Loading branch information
wwiv committed Apr 30, 2021
1 parent 4a52402 commit a173ac3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Expand Up @@ -38,7 +38,7 @@ add_subdirectory(deps/cl345)
# FMT
add_subdirectory(deps/fmt EXCLUDE_FROM_ALL)

if(WIN32)
if(WIN32 OR OS2)
# We only use pdcurses on Win32
add_definitions(-DPDC_WIDE)
add_subdirectory(deps/pdcurses EXCLUDE_FROM_ALL)
Expand Down
9 changes: 9 additions & 0 deletions cconfig.cmd
@@ -0,0 +1,9 @@
rem WWIV Version 5.x
set CXX=C:\usr\bin\g++
set CC=C:\usr\bin\gcc
set EMXOMFLD_LINKER=wl.exe
set EMXOMFLD_TYPE=WLINK

echo: Runing cmake on "%1"
cmake --debug-output --debug-trycompile -v %1
pause
2 changes: 1 addition & 1 deletion cmake/FindWWIVCurses.cmake
Expand Up @@ -8,7 +8,7 @@ if(UNIX)
set(CURSES_NEED_NCURSES TRUE)
set(CURSES_NEED_WIDE TRUE)
find_package(Curses REQUIRED)
elseif(WIN32)
elseif(WIN32 OR OS2)
# message("FindWWIVCurses: Using PDCurses")
include_directories(${PDCURSES_INCLUDE_DIRS})
# message("FindWWIVCurses: PDCURSES_INCLUDE_DIRS: ${PDCURSES_INCLUDE_DIRS}")
Expand Down
18 changes: 16 additions & 2 deletions core/ip_address.cpp
Expand Up @@ -29,6 +29,9 @@
#pragma comment(lib, "Ws2_32.lib")
#include "WS2tcpip.h"
#include <ws2def.h>
#elif defined (__OS2__)
#include <sys/socket.h>
#include <arpa/inet.h>
#else
#include <arpa/inet.h>
#include <sys/types.h>
Expand Down Expand Up @@ -59,7 +62,12 @@ ip_address::ip_address(char* data) {

std::string ip_address::to_string() const {
char buf[255];
std::string s = inet_ntop(AF_INET6, &data_, buf, sizeof(buf));
#ifdef __OS2__
auto af = AF_INET;
#else
auto af = AF_INET6;
#endif
std::string s = inet_ntop(af, &data_, buf, sizeof(buf));
if (starts_with(s, "::ffff:") && s.find('.') != std::string::npos) {
// Even though we store it IPv6 internally, display as IPv4
return s.substr(7);
Expand All @@ -86,12 +94,18 @@ std::optional<ip_address> ip_address::from_string(const std::string& s) {
//make this into a ipv6 address for an ipv4 address
addr = wwiv::strings::StrCat("0:0:0:0:0:FFFF:", s);
}
#ifdef __OS2__
memset(&d, 0x00, 10);
memset(&d[10], 0x01, 2);
const auto ret = inet_pton(AF_INET, addr.c_str(), &d[12]);
#else
const auto ret = inet_pton(AF_INET6, addr.c_str(), &d);
#endif
if (ret != 1) {
LOG(INFO) << "result code: " << ret;
return std::nullopt;
}
return {ip_address(d)};
}

} // namespace wwiv::core
} // namespace wwiv::core
4 changes: 4 additions & 0 deletions core/net.cpp
Expand Up @@ -34,6 +34,10 @@

#endif // _WIN32

#ifdef __OS2__
#include <libcx/net.h>
#endif // __OS2__

#include "core/log.h"
#include "core/scope_exit.h"
#include "core/socket_exceptions.h"
Expand Down
4 changes: 4 additions & 0 deletions core/socket_connection.cpp
Expand Up @@ -37,6 +37,10 @@
#include <unistd.h>
#endif // _WIN32

#ifdef __OS2__
#include <libcx/net.h>
#endif // __OS2__

#include "scope_exit.h"
#include "stl.h"
#include "core/log.h"
Expand Down

0 comments on commit a173ac3

Please sign in to comment.