From 416c71e5541e04f7134f5f79b9c1ee42e0355100 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Wed, 15 Jan 2020 22:56:16 -0400 Subject: [PATCH] Fix json api bind IP Only the port was being used, the IP was being ignored and it was always binding to localhost. --- llarp/rpc/rpc.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/llarp/rpc/rpc.cpp b/llarp/rpc/rpc.cpp index 91f558e82..c218f4f1d 100644 --- a/llarp/rpc/rpc.cpp +++ b/llarp/rpc/rpc.cpp @@ -423,18 +423,18 @@ namespace llarp bool Start(const std::string& addr) { - uint16_t port = 0; - auto idx = addr.find_first_of(':'); - Addr netaddr; - if(idx != std::string::npos) - { - port = std::stoi(addr.substr(1 + idx)); - netaddr = Addr(addr.substr(0, idx)); - } sockaddr_in saddr; saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); saddr.sin_family = AF_INET; - saddr.sin_port = htons(port); + saddr.sin_port = 0; + + auto idx = addr.find_first_of(':'); + if(idx != std::string::npos) + { + Addr netaddr{addr.substr(0, idx), addr.substr(1 + idx)}; + saddr.sin_addr.s_addr = netaddr.ton(); + saddr.sin_port = htons(netaddr.port()); + } return _handler.ServeAsync(router->netloop(), router->logic(), (const sockaddr*)&saddr); }