bool isShutdown() const {return isShutdown_;}
// information about this end of the socket
- virtual char* getMyAddress() = 0; // a string e.g. "192.168.0.1"
virtual int getMyPort() = 0;
- virtual char* getMyEndpoint() = 0; // <address>::<port>
// information about the remote end of the socket
virtual char* getPeerAddress() = 0; // a string e.g. "192.168.0.1"
closesocket(getFd());
}
-char* TcpSocket::getMyAddress() {
- struct sockaddr_in info;
- struct in_addr addr;
- socklen_t info_size = sizeof(info);
-
- getsockname(getFd(), (struct sockaddr *)&info, &info_size);
- memcpy(&addr, &info.sin_addr, sizeof(addr));
-
- char* name = inet_ntoa(addr);
- if (name) {
- return rfb::strDup(name);
- } else {
- return rfb::strDup("");
- }
-}
-
int TcpSocket::getMyPort() {
return getSockPort(getFd());
}
-char* TcpSocket::getMyEndpoint() {
- rfb::CharArray address; address.buf = getMyAddress();
- int port = getMyPort();
-
- int buflen = strlen(address.buf) + 32;
- char* buffer = new char[buflen];
- sprintf(buffer, "%s::%d", address.buf, port);
- return buffer;
-}
-
char* TcpSocket::getPeerAddress() {
struct sockaddr_in info;
struct in_addr addr;
TcpSocket(const char *name, int port);
virtual ~TcpSocket();
- virtual char* getMyAddress();
virtual int getMyPort();
- virtual char* getMyEndpoint();
virtual char* getPeerAddress();
virtual int getPeerPort();