Subversion Repositories tpanel

Rev

Rev 446 | Rev 465 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 446 Rev 464
Line 37... Line 37...
37
#include <openssl/err.h>
37
#include <openssl/err.h>
38
#include <sys/socket.h>
38
#include <sys/socket.h>
39
#include <arpa/inet.h>
39
#include <arpa/inet.h>
40
#include <signal.h>
40
#include <signal.h>
41
#include <poll.h>
41
#include <poll.h>
-
 
42
#include <sys/ioctl.h>
-
 
43
#include <net/if.h>
42
 
44
 
43
using std::string;
45
using std::string;
44
 
46
 
45
int _cert_callback(int preverify_ok, X509_STORE_CTX *ctx);
47
int _cert_callback(int preverify_ok, X509_STORE_CTX *ctx);
46
 
48
 
47
TSocket::TSocket()
49
TSocket::TSocket()
48
{
50
{
49
    DECL_TRACER("TSocket::TSocket()")
51
    DECL_TRACER("TSocket::TSocket()")
-
 
52
 
-
 
53
    getHost();
50
}
54
}
51
 
55
 
52
TSocket::TSocket(const string& host, int port)
56
TSocket::TSocket(const string& host, int port)
53
{
57
{
54
    DECL_TRACER("TSocket::TSocket(const std::string& host, int port)");
58
    DECL_TRACER("TSocket::TSocket(const std::string& host, int port)");
55
 
59
 
56
    mHost = host;
60
    mHost = host;
57
    mPort = port;
61
    mPort = port;
-
 
62
    getHost();
58
}
63
}
59
 
64
 
60
TSocket::~TSocket()
65
TSocket::~TSocket()
61
{
66
{
62
    DECL_TRACER("TSocket::~TSocket()");
67
    DECL_TRACER("TSocket::~TSocket()");
63
 
68
 
64
    close();
69
    close();
65
}
70
}
66
 
71
 
-
 
72
bool TSocket::getHost()
-
 
73
{
-
 
74
    DECL_TRACER("TSocket::getHost()");
-
 
75
 
-
 
76
    char host[4096];
-
 
77
 
-
 
78
    if (gethostname(host, sizeof(host)))
-
 
79
    {
-
 
80
        MSG_ERROR("Error getting host name!");
-
 
81
        return false;
-
 
82
    }
-
 
83
 
-
 
84
    mMyHostName.assign(host);
-
 
85
    return true;
-
 
86
}
67
 
87
 
68
bool TSocket::connect(bool encrypt)
88
bool TSocket::connect(bool encrypt)
69
{
89
{
70
    DECL_TRACER("TSocket::connect(bool encrypt)");
90
    DECL_TRACER("TSocket::connect(bool encrypt)");
71
 
91
 
Line 141... Line 161...
141
            mConnected = true;
161
            mConnected = true;
142
            break;
162
            break;
143
        }
163
        }
144
    }
164
    }
145
 
165
 
-
 
166
 
146
    if (ainfo && ainfo->ai_family == AF_INET)
167
    if (ainfo && ainfo->ai_family == AF_INET)
147
    {
168
    {
148
        char str[INET_ADDRSTRLEN];
169
        char str[INET_ADDRSTRLEN];
149
        struct sockaddr_in addr;
170
        struct sockaddr_in addr;
-
 
171
        struct ifreq ninfo;
150
        socklen_t len = sizeof(addr);
172
        socklen_t len = sizeof(addr);
151
        getsockname(sock, (struct sockaddr *)&addr, &len);
173
        getsockname(sock, (struct sockaddr *)&addr, &len);
152
        mMyIP.assign(inet_ntop(AF_INET, &(addr.sin_addr), str, INET_ADDRSTRLEN));
174
        mMyIP.assign(inet_ntop(AF_INET, &(addr.sin_addr), str, INET_ADDRSTRLEN));
-
 
175
 
-
 
176
        if (ioctl(sock, SIOCGIFNETMASK, &ninfo))
-
 
177
        {
-
 
178
            MSG_ERROR("Error getting netmask: " << strerror(errno));
-
 
179
        }
-
 
180
        else
-
 
181
            mMyNetmask.assign(inet_ntop(AF_INET, &(ninfo.ifr_ifru.ifru_netmask), str, INET_ADDRSTRLEN));
153
    }
182
    }
154
    else
183
    else
155
    {
184
    {
156
        char str[INET6_ADDRSTRLEN];
185
        char str[INET6_ADDRSTRLEN];
157
        struct sockaddr_in6 addr;
186
        struct sockaddr_in6 addr;
-
 
187
        struct ifreq ninfo;
158
        socklen_t len = sizeof(addr);
188
        socklen_t len = sizeof(addr);
159
        getsockname(sock, (struct sockaddr *)&addr, &len);
189
        getsockname(sock, (struct sockaddr *)&addr, &len);
160
        mMyIP.assign(inet_ntop(AF_INET6, &(addr.sin6_addr), str, INET6_ADDRSTRLEN));
190
        mMyIP.assign(inet_ntop(AF_INET6, &(addr.sin6_addr), str, INET6_ADDRSTRLEN));
-
 
191
 
-
 
192
        if (ioctl(sock, SIOCGIFNETMASK, &ninfo))
-
 
193
        {
-
 
194
            MSG_ERROR("Error getting netmask: " << strerror(errno));
-
 
195
        }
-
 
196
        else
-
 
197
            mMyNetmask.assign(inet_ntop(AF_INET6, &(ninfo.ifr_ifru.ifru_netmask), str, INET6_ADDRSTRLEN));
161
    }
198
    }
162
 
199
 
163
    MSG_DEBUG("Client IP: " << mMyIP);
200
    MSG_DEBUG("Client IP: " << mMyIP);
164
 
201
 
165
    if (ainfo == nullptr)
202
    if (ainfo == nullptr)