diff --git a/src/ebusd/main.cpp b/src/ebusd/main.cpp index 10f04419..202c2396 100644 --- a/src/ebusd/main.cpp +++ b/src/ebusd/main.cpp @@ -256,7 +256,7 @@ int main(int argc, char* argv[], char* envp[]) { } if (s_opt.logAreas != -1 || s_opt.logLevel != ll_COUNT) { - setFacilitiesLogLevel(1<& args, ostringstream* ostr } else if (dstAddress == SYN) { dstAddress = master ? m_address : getSlaveAddress(m_address); } - if (!m_protocol->setAnswer(srcAddress, dstAddress, id[0], id[1], id.data()+2 - , id.size()-2, answer)) { + if (!m_protocol->setAnswer(srcAddress, dstAddress, id[0], id[1], id.data()+2, id.size()-2, answer)) { return RESULT_ERR_INVALID_ARG; } return RESULT_OK; diff --git a/src/lib/ebus/protocol.cpp b/src/lib/ebus/protocol.cpp index 376be810..1d80aee4 100644 --- a/src/lib/ebus/protocol.cpp +++ b/src/lib/ebus/protocol.cpp @@ -70,27 +70,28 @@ ProtocolHandler* ProtocolHandler::create(const ebus_protocol_config_t config, } } Transport* transport; - if (strchr(name, '/') == nullptr && strchr(name, ':') != nullptr) { + if (strchr(name, '/') == nullptr || strchr(name, ':') != nullptr) { char* in = strdup(name); bool udp = false; char* addrpos = in; char* portpos = strchr(addrpos, ':'); - // support tcp:: and udp:: + // support tcp:[:] and udp:[:] if (portpos == addrpos+3 && (strncmp(addrpos, "tcp", 3) == 0 || (udp=(strncmp(addrpos, "udp", 3) == 0)))) { addrpos += 4; portpos = strchr(addrpos, ':'); } + uint16_t port; if (portpos == nullptr) { - free(in); - return nullptr; // invalid protocol or missing port + port = 9999; + } else { + result_t result = RESULT_OK; + port = (uint16_t)parseInt(portpos+1, 10, 1, 65535, &result); + if (result != RESULT_OK) { + free(in); + return nullptr; // invalid port + } + *portpos = 0; } - result_t result = RESULT_OK; - uint16_t port = (uint16_t)parseInt(portpos+1, 10, 1, 65535, &result); - if (result != RESULT_OK) { - free(in); - return nullptr; // invalid port - } - *portpos = 0; char* hostOrIp = strdup(addrpos); free(in); transport = new NetworkTransport(name, config.extraLatency, hostOrIp, port, udp); diff --git a/src/lib/ebus/protocol.h b/src/lib/ebus/protocol.h index f5fbdcec..85ddb101 100755 --- a/src/lib/ebus/protocol.h +++ b/src/lib/ebus/protocol.h @@ -56,7 +56,7 @@ namespace ebusd { /** settings for the eBUS protocol handler. */ typedef struct ebus_protocol_config { - /** eBUS device string (serial device or [udp:]ip:port) with optional protocol prefix (enh: or ens:). */ + /** eBUS device string (serial device or [udp:]ip[:port]) with optional protocol prefix (enh: or ens:). */ const char* device; /** whether to skip serial eBUS device test. */ bool noDeviceCheck;