Commit d99cbe08 authored by jan.koester's avatar jan.koester
Browse files

Use netplus::isIPAddr instead of raw inet_pton

validAddress() in serverconfig.cpp and editorconfig.cpp called
inet_pton(AF_INET/AF_INET6) directly, which needs platform socket
headers (broke the FreeBSD build, and <arpa/inet.h> does not exist on
Windows). libnetplus already provides isIPAddr() with POSIX and Windows
implementations, and both targets link netplus, so use it.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 67cebc81
Loading
Loading
Loading
Loading
+2 −6
Changes for editor/src/editorconfig.cpp: 2 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -10,10 +10,7 @@
#include <json-c/json.h>

#include <algorithm>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netplus/socket.h>
#include <cctype>
#include <sstream>
#include <sys/stat.h>
@@ -123,8 +120,7 @@ struct Apply {
};

bool validAddress(const std::string &a) {
    unsigned char buf[16];
    if (inet_pton(AF_INET, a.c_str(), buf) == 1 || inet_pton(AF_INET6, a.c_str(), buf) == 1) return true;
    if (netplus::isIPAddr(a)) return true;
    if (a.empty()) return false;
    for (char c : a)
        if (!(std::isalnum(static_cast<unsigned char>(c)) || c == '.' || c == '-')) return false;
+2 −6
Changes for src/serverconfig.cpp: 2 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -18,10 +18,7 @@
#include <set>
#include <sstream>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netplus/socket.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -379,8 +376,7 @@ bool validHost(const std::string &h) {
    return true;
}
bool validAddress(const std::string &a) {
    unsigned char buf[16];
    return inet_pton(AF_INET, a.c_str(), buf) == 1 || inet_pton(AF_INET6, a.c_str(), buf) == 1 || validHost(a);
    return netplus::isIPAddr(a) || validHost(a);
}

bool writeRaw(const std::string &path, const std::string &content, mode_t mode, std::string &err) {