本文整理汇总了C++中VSocket类的典型用法代码示例。如果您正苦于以下问题:C++ VSocket类的具体用法?C++ VSocket怎么用?C++ VSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VSocket类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: VNCLOG
// Code to be executed by the thread
void *vncHTTPConnectThread::run_undetached(void * arg)
{
vnclog.Print(LL_INTINFO, VNCLOG("started HTTP server thread\n"));
// Go into a loop, listening for connections on the given socket
while (!m_shutdown)
{
// Accept an incoming connection
VSocket *new_socket = m_socket->Accept();
if (new_socket == NULL)
break;
vnclog.Print(LL_CLIENTS, VNCLOG("HTTP client connected\n"));
// Successful accept - perform the transaction
new_socket->SetTimeout(15000);
DoHTTP(new_socket);
// And close the client
new_socket->Shutdown();
new_socket->Close();
delete new_socket;
}
vnclog.Print(LL_INTINFO, VNCLOG("quitting HTTP server thread\n"));
return NULL;
}
开发者ID:OS2World,项目名称:APP-INTERNET-PMVNC-Server,代码行数:29,代码来源:vncHTTPConnect.cpp
示例2: vsocketDispatcher
qint64 vsocketDispatcher( char * _buf, const qint64 _len,
const SocketOpCodes _op_code, void * _user )
{
VSocket * sock = static_cast<VSocket *>( _user );
switch( _op_code )
{
case SocketRead: return( sock->ReadExact( _buf, _len ) ?
_len : 0 );
case SocketWrite: return( sock->SendExact( _buf, _len ) ?
_len : 0 );
case SocketGetPeerAddress:
strncpy( _buf, sock->GetPeerName(), _len );
return( 0 );
}
return( 0 );
}
开发者ID:00farts,项目名称:italc-1,代码行数:17,代码来源:ultravnc.cpp
示例3:
vncSockConnect::~vncSockConnect()
{
m_socket.Shutdown();
// Join with our lovely thread
if (m_thread != NULL)
{
// *** This is a hack to force the listen thread out of the accept call,
// because Winsock accept semantics are broken
((vncSockConnectThread *)m_thread)->m_shutdown = TRUE;
VSocket socket;
socket.Create();
socket.Bind(0);
socket.Connect("localhost", m_port);
socket.Close();
void *returnval;
m_thread->join(&returnval);
m_thread = NULL;
m_socket.Close();
}
}
开发者ID:zhiwenuil,项目名称:msf3,代码行数:24,代码来源:vncsockconnect.cpp
示例4: VNCLOG
// Code to be executed by the thread
void *vncSockConnectThread::run_undetached(void * arg)
{
vnclog.Print(LL_STATE, VNCLOG("started socket connection thread\n"));
// Go into a loop, listening for connections on the given socket
while (!m_shutdown) {
// Accept an incoming connection
VSocket *new_socket;
if (!m_socket->TryAccept(&new_socket, 100))
break;
if (new_socket != NULL) {
vnclog.Print(LL_CLIENTS, VNCLOG("accepted connection from %s\n"),
new_socket->GetPeerName());
// Successful accept - start the client unauthenticated
m_server->AddClient(new_socket, FALSE, FALSE);
}
}
vnclog.Print(LL_STATE, VNCLOG("quitting socket connection thread\n"));
return NULL;
}
开发者ID:tmbx,项目名称:vnc,代码行数:22,代码来源:vncSockConnect.cpp
示例5: switch
//.........这里部分代码省略.........
if (modulo == 0) {
strcpy(actualhostname, szToken);
break;
}
modulo--;
szToken = strtok(NULL, ";");
}
}
}
// Calculate the Display and Port offset.
port = INCOMING_PORT_OFFSET;
portp = strchr(actualhostname, ':');
if (portp)
{
*portp++ = '\0';
if (*portp == ':') // Tight127 method
{
port = atoi(++portp); // Port number after "::"
}
else // RealVNC method
{
if (atoi(portp) < 100) // If < 100 after ":" -> display number
port += atoi(portp);
else
port = atoi(portp); // If > 100 after ":" -> Port number
}
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (!tmpsock) {
return TRUE;
}
// Connect out to the specified host on the VNCviewer listen port
// To be really good, we should allow a display number here but
// for now we'll just assume we're connecting to display zero
tmpsock->Create();
if (tmpsock->Connect(actualhostname, port))
{
if (id)
{
tmpsock->Send(finalidcode,250);
tmpsock->SetTimeout(0);
/* if (strncmp(hostname,"ID",2)!=0)
{
while (true)
{
char result[1];
tmpsock->Read(result,1);
if (strcmp(result,"2")==0)
break;
tmpsock->Send("1",1);
}
}*/
// adzm 2009-07-05 - repeater IDs
// Add the new client to this server
// adzm 2009-08-02
开发者ID:copilot-com,项目名称:CopilotVNC,代码行数:67,代码来源:vncconndialog.cpp
示例6: GetWindowLong
//.........这里部分代码省略.........
if (iMsg == MENU_DEFAULT_PROPERTIES_SHOW)
{
// External request to show our Properties dialog
PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_DEFAULT_PROPERTIES, 0), 0);
return 0;
}
if (iMsg == MENU_ABOUTBOX_SHOW)
{
// External request to show our About dialog
PostMessage(hwnd, WM_COMMAND, MAKELONG(ID_ABOUT, 0), 0);
return 0;
}
if (iMsg == MENU_SERVICEHELPER_MSG)
{
// External ServiceHelper message.
// This message holds a process id which we can use to
// impersonate a specific user. In doing so, we can load their
// preferences correctly
// vncService::ProcessUserHelperMessage(wParam, lParam);
// Modif Jeremy C.
vncService::ProcessUserHelperMessage((WPARAM)&_this->m_server->m_impersonationtoken, lParam);
// - Trigger a check of the current user
PostMessage(hwnd, WM_USERCHANGED, 0, 0);
return 0;
}
if (iMsg == RETRY_MESSAGE)
{
connect_counter++;
if (connect_counter%5==0)
{
// Attempt to create a new socket
// Beep(1000,100);
VSocket *tmpsock;
tmpsock = new VSocket;
if (tmpsock) {
// Connect out to the specified host on the VNCviewer listen port
tmpsock->Create();
if (tmpsock->Connect(szAdrName, nport)) {
// Add the new client to this server
if (strcmp(g_idcode,"")==NULL) g_id=false;
else g_id=true;
char sendID[_MAX_PATH];
strcpy(sendID,"ID:");
strcat(sendID,g_idcode);
if (g_id)
tmpsock->Send(sendID,250);
_this->m_server->AddClient(tmpsock, TRUE, TRUE);
nport=0;
connected=1;
_this->FlashTrayIcon(_this->m_server->AuthClientCount() != 0);
return 0;
} else {
delete tmpsock;
connect_counter++;
if (connect_counter>25)
// Sleep(5000);
PostMessage(hwnd, WM_CLOSE, 0, 0);
}
}
}
return 0;
}
if (iMsg == MENU_ADD_CLIENT_MSG)
开发者ID:adrianovieira,项目名称:cacic3-agente_windows,代码行数:67,代码来源:vncmenu.cpp
示例7: GetWindowLong
BOOL CALLBACK vncConnDialog::vncConnDlgProc(HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam) {
// This is a static method, so we don't know which instantiation we're
// dealing with. But we can get a pseudo-this from the parameter to
// WM_INITDIALOG, which we therafter store with the window and retrieve
// as follows:
vncConnDialog *_this = (vncConnDialog *) GetWindowLong(hwnd, GWL_USERDATA);
switch (uMsg) {
// Dialog has just been created
case WM_INITDIALOG:
{
// Save the lParam into our user data so that subsequent calls have
// access to the parent C++ object
SetWindowLong(hwnd, GWL_USERDATA, lParam);
vncConnDialog *_this = (vncConnDialog *) lParam;
// Make the text entry box active
SetFocus(GetDlgItem(hwnd, IDC_HOSTNAME_EDIT));
// Return success!
return TRUE;
}
// Dialog has just received a command
case WM_COMMAND:
switch (LOWORD(wParam)) {
// User clicked OK or pressed return
case IDOK:
{
char viewer[256];
char hostname[256];
VCard display_or_port;
// Get the viewer to connect to
GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, viewer, 256);
// Process the supplied viewer address
int result = sscanf(viewer, "%255[^:]:%u", hostname, &display_or_port);
if (result == 1) {
display_or_port = 0;
result = 2;
}
if (result == 2) {
// Correct a display number to a port number if required
if (display_or_port < 100) {
display_or_port += INCOMING_PORT_OFFSET;
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (!tmpsock)
return TRUE;
// Connect out to the specified host on the VNCviewer listen port
// To be really good, we should allow a display number here but
// for now we'll just assume we're connecting to display zero
tmpsock->Create();
if (tmpsock->Connect(hostname, display_or_port)) {
// Add the new client to this server
_this->m_server->AddClient(tmpsock, TRUE, TRUE);
// And close the dialog
EndDialog(hwnd, TRUE);
} else {
// Print up an error message
MessageBox(NULL,
"Failed to connect to listening VNC viewer",
"Outgoing Connection",
MB_OK | MB_ICONEXCLAMATION );
delete tmpsock;
}
} else {
// We couldn't process the machine specification
MessageBox(NULL, "Unable to process specified hostname and display/port",
"Outgoing Connection", MB_OK | MB_ICONEXCLAMATION);
}
}
return TRUE;
// Cancel the dialog
case IDCANCEL:
EndDialog(hwnd, FALSE);
return TRUE;
};
break;
case WM_DESTROY:
EndDialog(hwnd, FALSE);
return TRUE;
}
return 0;
}
开发者ID:lizard007,项目名称:msf3,代码行数:100,代码来源:vncconndialog.cpp
示例8: vncSockConnect
// Socket connection handling
BOOL
vncServer::SockConnect(BOOL On)
{
// Are we being asked to switch socket connects on or off?
if (On)
{
// Is there a listening socket?
if (m_socketConn == NULL)
{
m_socketConn = new vncSockConnect();
if (m_socketConn == NULL)
return FALSE;
// Are we to use automatic port selection?
if (m_autoportselect)
{
BOOL ok = FALSE;
// Yes, so cycle through the ports, looking for a free one!
for (int i=0; i < 99; i++)
{
m_port = DISPLAY_TO_PORT(i);
vnclog.Print(LL_CLIENTS, VNCLOG("trying port number %d\n"), m_port);
// Attempt to connect to the port
VSocket tempsock;
if (tempsock.Create())
{
if (!tempsock.Connect("localhost", m_port))
{
// Couldn't connect, so this port is probably usable!
if (m_socketConn->Init(this, m_port))
{
ok = TRUE;
break;
}
}
}
}
if (!ok)
{
delete m_socketConn;
m_socketConn = NULL;
return FALSE;
}
} else
{
// No autoportselect
if (!m_socketConn->Init(this, m_port))
{
delete m_socketConn;
m_socketConn = NULL;
return FALSE;
}
}
}
}
else
{
// *** JNW - Trying to fix up a lock-up when the listening socket closes
KillAuthClients();
KillUnauthClients();
WaitUntilAuthEmpty();
WaitUntilUnauthEmpty();
// Is there a listening socket?
if (m_socketConn != NULL)
{
// Close the socket
delete m_socketConn;
m_socketConn = NULL;
}
}
return TRUE;
}
开发者ID:petersenna,项目名称:pvnc,代码行数:79,代码来源:vncserver.cpp
示例9: Sleep
//.........这里部分代码省略.........
char *name = inet_ntoa(address);
if (name == 0)
return 0;
nameDup = _strdup(name);
if (nameDup == 0)
return 0;
strcpy(szAdrName, nameDup);
// Free the duplicate name
if (nameDup != 0) free(nameDup);
// Get the port number
nport = (unsigned short)wParam;
if (nport == 0)
nport = INCOMING_PORT_OFFSET;
}
// [email protected] -- added support for the AutoReconnectId
// (but it's not required)
bool bId = ( strlen(_this->m_server->AutoReconnectId() ) > 0);
if ( bId )
strcpy( szId, _this->m_server->AutoReconnectId() );
// [email protected]
// Stores the client adr/ports the first time we try to connect
// This way we can call this message again later to reconnect with the same values
if ((_this->m_server->AutoReconnect() || _this->m_server->IdReconnect())&& strlen(_this->m_server->AutoReconnectAdr()) == 0)
{
_this->m_server->AutoReconnectAdr(szAdrName);
_this->m_server->AutoReconnectPort(nport);
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (tmpsock) {
// Connect out to the specified host on the VNCviewer listen port
tmpsock->Create();
if (tmpsock->Connect(szAdrName, nport)) {
if ( bId )
{
// [email protected] -- added support for the AutoReconnectId
// Set the ID for this client -- code taken from vncconndialog.cpp (ln:142)
tmpsock->Send(szId,250);
tmpsock->SetTimeout(0);
// adzm 2009-07-05 - repeater IDs
// Add the new client to this server
// adzm 2009-08-02
_this->m_server->AddClient(tmpsock, TRUE, TRUE, 0, NULL, szId, szAdrName, nport);
} else {
// Add the new client to this server
// adzm 2009-08-02
_this->m_server->AddClient(tmpsock, TRUE, TRUE, 0, NULL, NULL, szAdrName, nport);
}
} else {
delete tmpsock;
_this->m_server->AutoConnectRetry();
}
}
return 0;
}
// Process FileTransfer asynchronous Send Packet Message
开发者ID:DennisHeerema,项目名称:ultravnc,代码行数:67,代码来源:vncmenu.cpp
示例10: WinVNCDll_ListenForClient
extern "C" DLLEXPORT /*export without name mangling*/
int WinVNCDll_ListenForClient(PSTR szRemoteClient, PSTR szIdCode)
{
// Compatible with both RealVNC and TightVNC methods
char hostname[_MAX_PATH];
char actualhostname[_MAX_PATH];
char idcode[_MAX_PATH];
char *portp;
int port;
bool id;
// Get the hostname of the VNCviewer
strcpy(hostname, szRemoteClient);
strcpy(idcode, szIdCode);
//GetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, hostname, _MAX_PATH);
//GetDlgItemText(hwnd, IDC_IDCODE, idcode, _MAX_PATH);
if (strcmp(idcode,"")==0) id=false;
else id=true;
strcpy(actualhostname, hostname);
vnclog.Print(LL_STATE, VNCLOG("WinVNCDll_ListenForClient(%s %s)\n"),hostname,idcode);
//adzm 2010-02-15 - Multiple repeaters chosen by modulo of ID
char finalidcode[_MAX_PATH];
//adzm 2010-08 - this was sending uninitialized data over the wire
ZeroMemory(finalidcode, sizeof(finalidcode));
//adzm 2009-06-20
if (id) {
size_t i = 0;
for (i = 0; i < strlen(idcode); i++)
{
finalidcode[i] = toupper(idcode[i]);
}
finalidcode[i] = 0;
if (0 != strncmp("ID:", idcode, 3)) {
strcpy(finalidcode, "ID:");
for (i = 0; i < strlen(idcode); i++)
{
finalidcode[i+3] = toupper(idcode[i]);
}
finalidcode[i+3] = 0;
}
//adzm 2010-02-15 - At this point, finalidcode is of the form "ID:#####"
int numericId = atoi(finalidcode + 3);
int numberOfHosts = 1;
for (i = 0; i < strlen(hostname); i++) {
if (hostname[i] == ';') {
numberOfHosts++;
}
}
if (numberOfHosts <= 1) {
// then hostname == actualhostname
} else {
int modulo = numericId % numberOfHosts;
char* szToken = strtok(hostname, ";");
while (szToken) {
if (modulo == 0) {
strcpy(actualhostname, szToken);
break;
}
modulo--;
szToken = strtok(NULL, ";");
}
}
}
// Calculate the Display and Port offset.
port = INCOMING_PORT_OFFSET;
portp = strchr(actualhostname, ':');
if (portp)
{
*portp++ = '\0';
if (*portp == ':') // Tight127 method
{
port = atoi(++portp); // Port number after "::"
}
else // RealVNC method
{
if (atoi(portp) < 100) // If < 100 after ":" -> display number
port += atoi(portp);
else
port = atoi(portp); // If > 100 after ":" -> Port number
}
}
// Attempt to create a new socket
VSocket *tmpsock;
tmpsock = new VSocket;
if (!tmpsock) {
vnclog.Print(LL_STATE, VNCLOG("Could not create socket\n"));
//.........这里部分代码省略.........
开发者ID:FrantisekKlika,项目名称:UltraVncAsDll,代码行数:101,代码来源:winvncdll.cpp
示例11: vncSockConnect
// Socket connection handling
BOOL
vncServer::SockConnect(BOOL On)
{
// Are we being asked to switch socket connects on or off?
if (On)
{
// Is there a listening socket?
if (m_socketConn == NULL)
{
m_socketConn = new vncSockConnect();
if (m_socketConn == NULL)
return FALSE;
// Are we to use automatic port selection?
if (m_autoportselect)
{
BOOL ok = FALSE;
// Yes, so cycle through the ports, looking for a free one!
for (int i = 0; i < 99; i++)
{
m_port = DISPLAY_TO_PORT(i);
m_port_http = DISPLAY_TO_HPORT(i);
vnclog.Print(LL_CLIENTS, VNCLOG("trying port number %d\n"), m_port);
// Attempt to connect to the port
VSocket tempsock;
if (tempsock.Create())
{
if (!tempsock.Connect("localhost", m_port))
{
// Couldn't connect, so this port is probably usable!
if (m_socketConn->Init(this, m_port))
{
ok = TRUE;
break;
}
}
}
}
if (!ok)
{
delete m_socketConn;
m_socketConn = NULL;
return FALSE;
}
} else
{
// No autoportselect
if (!m_socketConn->Init(this, m_port))
{
delete m_socketConn;
m_socketConn = NULL;
return FALSE;
}
}
// Now let's start the HTTP connection stuff
if (m_port_http == m_port) {
vnclog.Print(LL_INTERR, VNCLOG("cannot start both RFB and HTTP servers "
"on the same port\n"));
}
if (m_httpConn == NULL && m_httpd_enabled && m_port_http != m_port) {
m_httpConn = new vncHTTPConnect;
if (m_httpConn != NULL) {
// Start up the HTTP server
if (!m_httpConn->Init(this, m_port_http,
m_httpd_params_enabled)) {
delete m_httpConn;
m_httpConn = NULL;
return FALSE;
}
}
}
}
}
else
{
// *** JNW - Trying to fix up a lock-up when the listening socket closes
#ifndef HORIZONLIVE
KillAuthClients();
KillUnauthClients();
WaitUntilAuthEmpty();
WaitUntilUnauthEmpty();
#endif
// Is there a listening socket?
if (m_socketConn != NULL)
{
// Close the socket
delete m_socketConn;
m_socketConn = NULL;
}
// Is there an HTTP socket active?
if (m_httpConn != NULL)
{
//.........这里部分代码省略.........
开发者ID:bk138,项目名称:CollabTool,代码行数:101,代码来源:vncServer.cpp
示例12:
BOOL
vncClientThread::InitVersion()
{
// Generate the server's protocol version
rfbProtocolVersionMsg protocolMsg;
sprintf((char *)protocolMsg,
rfbProtocolVersionFormat,
rfbProtocolMajorVersion,
rfbProtocolMinorVersion);
// Send the protocol message
if (!m_socket->SendExact((char *)&protocolMsg, sz_rfbProtocolVersionMsg))
return FALSE;
// Now, get the client's protocol version
rfbProtocolVersionMsg protocol_ver;
protocol_ver[12] = 0;
if (!m_socket->ReadExact((char *)&protocol_ver, sz_rfbProtocolVersionMsg))
return FALSE;
// Check the protocol version
int major, minor;
sscanf((char *)&protocol_ver, rfbProtocolVersionFormat, &major, &minor);
if (major != rfbProtocolMajorVersion)
return FALSE;
return TRUE;
}
开发者ID:petersenna,项目名称:pvnc,代码行数:28,代码来源:vncclient.cpp
示例13: VNCLOG
void
vncClientThread::run(void *arg)
{
// All this thread does is go into a socket-recieve loop,
// waiting for stuff on the given socket
// IMPORTANT : ALWAYS call RemoveClient on the server before quitting
// this thread.
vnclog.Print(LL_CLIENTS, VNCLOG("client connected : %s (%hd)\n"),
m_client->GetClientName(),
m_client->GetClientId());
// Save the handle to the thread's original desktop
HDESK home_desktop = GetThreadDesktop(GetCurrentThreadId());
// To avoid people connecting and then halting the connection, set a timeout
if (!m_socket->SetTimeout(30000))
vnclog.Print(LL_INTERR, VNCLOG("failed to set socket timeout(%d)\n"), GetLastError());
// Initially blacklist the client so that excess connections from it get dropped
m_server->AddAuthHostsBlacklist(m_client->GetClientName());
// LOCK INITIAL SETUP
// All clients have the m_protocol_ready flag set to FALSE initially, to prevent
// updates and suchlike interfering with the initial protocol negotiations.
// GET PROTOCOL VERSION
if (!InitVersion())
{
m_server->RemoveClient(m_client->GetClientId());
return;
}
vnclog.Print(LL_INTINFO, VNCLOG("negotiated version\n"));
// AUTHENTICATE LINK
if (!InitAuthenticate())
{
m_server->RemoveClient(m_client->GetClientId());
return;
}
// Authenticated OK - remove from blacklist and remove timeout
m_server->RemAuthHostsBlacklist(m_client->GetClientName());
m_socket->SetTimeout(m_server->AutoIdleDisconnectTimeout()*1000);
vnclog.Print(LL_INTINFO, VNCLOG("authenticated connection\n"));
// INIT PIXEL FORMAT
// Get the screen format
m_client->m_fullscreen = m_client->m_encodemgr.GetSize();
// Get the name of this desktop
char desktopname[MAX_COMPUTERNAME_LENGTH+1];
DWORD desktopnamelen = MAX_COMPUTERNAME_LENGTH + 1;
if (GetComputerName(desktopname, &desktopnamelen))
{
// Make the name lowercase
for (int x=0; x<strlen(desktopname); x++)
{
desktopname[x] = tolower(desktopname[x]);
}
}
else
{
strcpy(desktopname, "WinVNC");
}
// Send the server format message to the client
rfbServerInitMsg server_ini;
server_ini.format = m_client->m_encodemgr.m_buffer->GetLocalFormat();
// Endian swaps
server_ini.framebufferWidth = Swap16IfLE(m_client->m_fullscreen.br.x);
server_ini.framebufferHeight = Swap16IfLE(m_client->m_fullscreen.br.y);
server_ini.format.redMax = Swap16IfLE(server_ini.format.redMax);
server_ini.format.greenMax = Swap16IfLE(server_ini.format.greenMax);
server_ini.format.blueMax = Swap16IfLE(server_ini.format.blueMax);
server_ini.nameLength = Swap32IfLE(strlen(desktopname));
if (!m_socket->SendExact((char *)&server_ini, sizeof(server_ini)))
{
m_server->RemoveClient(m_client->GetClientId());
return;
}
if (!m_socket->SendExact(desktopname, strlen(desktopname)))
{
m_server->RemoveClient(m_client->GetClientId());
return;
}
vnclog.Print(LL_INTINFO, VNCLOG("sent pixel format to client\n"));
// UNLOCK INITIAL SETUP
// Initial negotiation is complete, so set the protocol ready flag
m_client->EnableProtocol();
// Add a fullscreen update to the client's update list
{ omni_mutex_lock l(m_client->GetUpdateLock());
m_client->m_update_tracker.add_changed(m_client->m_fullscreen);
}
//.........这里部分代码省略.........
开发者ID:petersenna,项目名称:pvnc,代码行数:101,代码来源:vncclient.cpp
示例14: plain
BOOL
vncClientThread::InitAuthenticate()
{
// Retrieve the local password
char password[MAXPWLEN];
m_server->GetPassword(password);
vncPasswd::ToText plain(password);
// Verify the peer host name against the AuthHosts string
vncServer::AcceptQueryReject verified;
if (m_auth) {
verified = vncServer::aqrAccept;
} else {
verified = m_server->VerifyHost(m_socket->GetPeerName());
}
// If necessary, query the connection with a timed dialog
if (verified == vncServer::aqrQuery) {
vncAcceptDialog *acceptDlg = new vncAcceptDialog(m_server->QueryTimeout(), m_socket->GetPeerName());
if ((acceptDlg == 0) || (!(acceptDlg->DoDialog())))
verified = vncServer::aqrReject;
}
if (verified == vncServer::aqrReject) {
CARD32 auth_val = Swap32IfLE(rfbConnFailed);
char *errmsg = "Your connection has been rejected.";
CARD32 errlen = Swap32IfLE(strlen(errmsg));
if (!m_socket->SendExact((char *)&auth_val, sizeof(auth_val)))
return FALSE;
if (!m_socket->SendExact((char *)&errlen, sizeof(errlen)))
return FALSE;
m_socket->SendExact(errmsg, strlen(errmsg));
return FALSE;
}
// By default we disallow passwordless workstations!
if ((strlen(plain) == 0) && m_server->AuthRequired())
{
vnclog.Print(LL_CONNERR, VNCLOG("no password specified for server - client rejected\n"));
// Send an error message to the client
CARD32 auth_val = Swap32IfLE(rfbConnFailed);
char *errmsg =
"This server does not have a valid password enabled. "
"Until a password is set, incoming connections cannot be accepted.";
CARD32 errlen = Swap32IfLE(strlen(errmsg));
if (!m_socket->SendExact((char *)&auth_val, sizeof(auth_val)))
return FALSE;
if (!m_socket->SendExact((char *)&errlen, sizeof(errlen)))
return FALSE;
m_socket->SendExact(errmsg, strlen(errmsg));
return FALSE;
}
// By default we filter out local loop connections, because they're pointless
if (!m_server->LoopbackOk())
{
char *localname = strdup(m_socket->GetSockName());
char *remotename = strdup(m_socket->GetPeerName());
// Check that the local & remote names are different!
if ((localname != NULL) && (remotename != NULL))
{
BOOL ok = strcmp(localname, remotename) != 0;
if (localname != NULL)
free(localname);
if (remotename != NULL)
free(remotename);
if (!ok)
{
vnclog.Print(LL_CONNERR, VNCLOG("loopback connection attempted - client rejected\n"));
// Send an error message to the client
CARD32 auth_val = Swap32IfLE(rfbConnFailed);
char *errmsg = "Local loop-back connections are disabled.";
CARD32 errlen = Swap32IfLE(strlen(errmsg));
if (!m_socket->SendExact((char *)&auth_val, sizeof(auth_val)))
return FALSE;
if (!m_socket->SendExact((char *)&errlen, sizeof(errlen)))
return FALSE;
m_socket->SendExact(errmsg, strlen(errmsg));
return FALSE;
}
}
}
// Authenticate the connection, if required
if (m_auth || (strlen(plain) == 0))
{
// Send no-auth-required message
CARD32 auth_val = Swap32IfLE(rfbNoAuth);
if (!m_socket->SendExact((char *)&auth_val, sizeof(auth_val)))
return FALSE;
}
//.........这里部分代码省略.........
开发者ID:petersenna,项目名称:pvnc,代码行数:101,代码来源:vncclient.cpp
注:本文中的VSocket类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论