X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=scripts%2Fexample%2Ffgfsclient.cxx;h=27e8d83975d82456d8c29d0d03bdcf0e23150bc7;hb=68b275cfe98de2e563af610f4adb0f40074e7ebf;hp=382a41dedc0a8372d3a84c7e49a590e43be4d5d7;hpb=f29a6dbf33bffa3f67bbb59a7f7fce41bcf72393;p=flightgear.git diff --git a/scripts/example/fgfsclient.cxx b/scripts/example/fgfsclient.cxx index 382a41ded..27e8d8397 100644 --- a/scripts/example/fgfsclient.cxx +++ b/scripts/example/fgfsclient.cxx @@ -1,5 +1,6 @@ // $Id$ // g++ -O2 -g -pedantic -Wall fgfsclient.cxx -o fgfsclient -lstdc++ +// USAGE: ./fgfsclient [hostname [port]] // Public Domain #include @@ -16,12 +17,14 @@ #include -const int MAXLEN = 256; +const char *HOST = "localhost"; +const unsigned PORT = 5501; +const int BUFLEN = 256; class FGFSSocket { public: - FGFSSocket(const char *name, const unsigned port); + FGFSSocket(const char *name, unsigned port); ~FGFSSocket(); int write(const char *msg, ...); @@ -35,11 +38,11 @@ private: int _sock; bool _connected; unsigned _timeout; - char _buffer[MAXLEN]; + char _buffer[BUFLEN]; }; -FGFSSocket::FGFSSocket(const char *hostname = "localhost", const unsigned port = 5501) : +FGFSSocket::FGFSSocket(const char *hostname = HOST, unsigned port = PORT) : _sock(-1), _connected(false), _timeout(1) @@ -96,7 +99,7 @@ int FGFSSocket::write(const char *msg, ...) { va_list va; ssize_t len; - char buf[MAXLEN]; + char buf[BUFLEN]; fd_set fd; struct timeval tv; @@ -108,7 +111,7 @@ int FGFSSocket::write(const char *msg, ...) throw("FGFSSocket::write/select: timeout exceeded"); va_start(va, msg); - vsprintf(buf, msg, va); + vsnprintf(buf, BUFLEN - 2, msg, va); va_end(va); std::cout << "SEND: " << buf << std::endl; strcat(buf, "\015\012"); @@ -138,7 +141,7 @@ const char *FGFSSocket::read(void) throw("FGFSSocket::read/select: timeout exceeded"); } - len = ::read(_sock, _buffer, MAXLEN - 1); + len = ::read(_sock, _buffer, BUFLEN - 1); if (len < 0) throw("FGFSSocket::read/read"); if (len == 0)