summaryrefslogtreecommitdiffstats
path: root/libvncserver/sockets.c
diff options
context:
space:
mode:
Diffstat (limited to 'libvncserver/sockets.c')
-rw-r--r--libvncserver/sockets.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/libvncserver/sockets.c b/libvncserver/sockets.c
index e1c5a7f..b7ea8c1 100644
--- a/libvncserver/sockets.c
+++ b/libvncserver/sockets.c
@@ -260,37 +260,7 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
if (rfbScreen->listenSock != -1 && FD_ISSET(rfbScreen->listenSock, &fds)) {
- if ((sock = accept(rfbScreen->listenSock,
- (struct sockaddr *)&addr, &addrlen)) < 0) {
- rfbLogPerror("rfbCheckFds: accept");
- return -1;
- }
-
- if(!rfbSetNonBlocking(sock)) {
- closesocket(sock);
- return -1;
- }
-
- if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
- (char *)&one, sizeof(one)) < 0) {
- rfbLogPerror("rfbCheckFds: setsockopt");
- closesocket(sock);
- return -1;
- }
-
-#ifdef USE_LIBWRAP
- if(!hosts_ctl("vnc",STRING_UNKNOWN,inet_ntoa(addr.sin_addr),
- STRING_UNKNOWN)) {
- rfbLog("Rejected connection from client %s\n",
- inet_ntoa(addr.sin_addr));
- closesocket(sock);
- return -1;
- }
-#endif
-
- rfbLog("Got connection from client %s\n", inet_ntoa(addr.sin_addr));
-
- rfbNewClient(rfbScreen,sock);
+ rfbProcessNewConnection(rfbScreen);
FD_CLR(rfbScreen->listenSock, &fds);
if (--nfds == 0)
@@ -352,6 +322,47 @@ rfbCheckFds(rfbScreenInfoPtr rfbScreen,long usec)
return result;
}
+void
+rfbProcessNewConnection(rfbScreenInfoPtr rfbScreen)
+{
+ const int one = 1;
+ int sock = -1;
+ struct sockaddr_in addr;
+ socklen_t addrlen = sizeof(addr);
+
+ if ((sock = accept(rfbScreen->listenSock,
+ (struct sockaddr *)&addr, &addrlen)) < 0) {
+ rfbLogPerror("rfbCheckFds: accept");
+ return -1;
+ }
+
+ if(!rfbSetNonBlocking(sock)) {
+ closesocket(sock);
+ return -1;
+ }
+
+ if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY,
+ (char *)&one, sizeof(one)) < 0) {
+ rfbLogPerror("rfbCheckFds: setsockopt");
+ closesocket(sock);
+ return -1;
+ }
+
+#ifdef USE_LIBWRAP
+ if(!hosts_ctl("vnc",STRING_UNKNOWN,inet_ntoa(addr.sin_addr),
+ STRING_UNKNOWN)) {
+ rfbLog("Rejected connection from client %s\n",
+ inet_ntoa(addr.sin_addr));
+ closesocket(sock);
+ return -1;
+ }
+#endif
+
+ rfbLog("Got connection from client %s\n", inet_ntoa(addr.sin_addr));
+
+ rfbNewClient(rfbScreen,sock);
+}
+
void
rfbDisconnectUDPSock(rfbScreenInfoPtr rfbScreen)