1
0
Fork 0

convert bindaddr from const char * to std::string

ycs232-kbc
Jason D. McCormick 5 years ago
parent c214bbfd89
commit 0a9ce3e450

@ -44,10 +44,10 @@ CNetwork::~CNetwork()
delete[] m_status; delete[] m_status;
} }
bool CNetwork::open(const char* bindaddr) bool CNetwork::open(const std::string& bindaddr)
{ {
if (strlen(bindaddr) > 0) if (bindaddr.length() > 0)
::fprintf(stdout, "Opening YSF network connection on address %s\n", bindaddr); ::fprintf(stdout, "Opening YSF network connection on address %s\n", bindaddr.c_str());
else else
::fprintf(stdout, "Opening YSF network connection on all interfaces\n"); ::fprintf(stdout, "Opening YSF network connection on all interfaces\n");

@ -31,7 +31,7 @@ public:
CNetwork(unsigned int port, unsigned int id, const std::string& name, const std::string& description, bool debug); CNetwork(unsigned int port, unsigned int id, const std::string& name, const std::string& description, bool debug);
~CNetwork(); ~CNetwork();
bool open(const char* bindaddr); bool open(const std::string& bindaddr);
bool writeData(const unsigned char* data, const in_addr& address, unsigned int port); bool writeData(const unsigned char* data, const in_addr& address, unsigned int port);
bool writePoll(const in_addr& address, unsigned int port); bool writePoll(const in_addr& address, unsigned int port);

@ -102,7 +102,7 @@ in_addr CUDPSocket::lookup(const std::string& hostname)
#endif #endif
} }
bool CUDPSocket::open(const char* bindaddr) bool CUDPSocket::open(const std::string& bindaddr)
{ {
m_fd = ::socket(PF_INET, SOCK_DGRAM, 0); m_fd = ::socket(PF_INET, SOCK_DGRAM, 0);
if (m_fd < 0) { if (m_fd < 0) {
@ -120,10 +120,10 @@ bool CUDPSocket::open(const char* bindaddr)
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addr.sin_port = htons(m_port); addr.sin_port = htons(m_port);
if ( strlen(bindaddr) > 0){ if ( bindaddr.length() > 0){
int validaddr = inet_pton(AF_INET, bindaddr, &(addr.sin_addr)); int validaddr = inet_pton(AF_INET, bindaddr.c_str(), &(addr.sin_addr));
if (validaddr != 1){ if (validaddr != 1){
LogError("The BindAddress in the .ini is invalid - %s", bindaddr); LogError("The BindAddress in the .ini is invalid - %s", bindaddr.c_str());
return false; return false;
} }
} else { } else {

@ -40,7 +40,7 @@ public:
CUDPSocket(unsigned int port = 0U); CUDPSocket(unsigned int port = 0U);
~CUDPSocket(); ~CUDPSocket();
bool open(const char* bindaddr); bool open(const std::string& bindaddr);
int read(unsigned char* buffer, unsigned int length, in_addr& address, unsigned int& port); int read(unsigned char* buffer, unsigned int length, in_addr& address, unsigned int& port);
bool write(const unsigned char* buffer, unsigned int length, const in_addr& address, unsigned int port); bool write(const unsigned char* buffer, unsigned int length, const in_addr& address, unsigned int port);

@ -164,7 +164,7 @@ void CYSFReflector::run()
CNetwork network(m_conf.getNetworkPort(), m_conf.getId(), m_conf.getName(), m_conf.getDescription(), m_conf.getNetworkDebug()); CNetwork network(m_conf.getNetworkPort(), m_conf.getId(), m_conf.getName(), m_conf.getDescription(), m_conf.getNetworkDebug());
ret = network.open(m_conf.getNetworkBindAddr().c_str()); ret = network.open(m_conf.getNetworkBindAddr());
if (!ret) { if (!ret) {
::LogFinalise(); ::LogFinalise();
return; return;

Loading…
Cancel
Save