mirror of
https://github.com/gyurix1968/guacamole-client.git
synced 2025-09-07 05:31:22 +00:00
Added dummy proxy implementation, moved client, added main Makefile.
This commit is contained in:
committed by
Mike Jumper
parent
7ee970c88a
commit
c048537232
96
guacamole/proxy/daemon.c
Normal file
96
guacamole/proxy/daemon.c
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "proxy.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
/* Server */
|
||||
int socket_fd;
|
||||
struct sockaddr_in server_addr;
|
||||
|
||||
/* Client */
|
||||
struct sockaddr_in client_addr;
|
||||
unsigned int client_addr_len;
|
||||
int connected_socket_fd;
|
||||
pid_t proxy_pid ;
|
||||
|
||||
/* Get binding address */
|
||||
memset(&server_addr, 0, sizeof(server_addr)); /* Zero struct */
|
||||
server_addr.sin_family = AF_INET;
|
||||
server_addr.sin_addr.s_addr = INADDR_ANY;
|
||||
server_addr.sin_port = htons(1234);
|
||||
|
||||
/* Get socket */
|
||||
socket_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (socket_fd < 0) {
|
||||
perror("Error opening socket");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Bind socket to address */
|
||||
if (bind(socket_fd, (struct sockaddr*) &server_addr,
|
||||
sizeof(server_addr)) < 0) {
|
||||
perror("Error binding socket");
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Daemon loop */
|
||||
for (;;) {
|
||||
|
||||
fprintf(stderr, "Listening...\n");
|
||||
|
||||
/* Listen for connections */
|
||||
if (listen(socket_fd, 5) < 0) {
|
||||
perror("Error listening on socket");
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* Accept connection */
|
||||
client_addr_len = sizeof(client_addr);
|
||||
connected_socket_fd = accept(socket_fd, (struct sockaddr*) &client_addr, &client_addr_len);
|
||||
if (connected_socket_fd < 0) {
|
||||
perror("Error accepting client");
|
||||
return 3;
|
||||
}
|
||||
|
||||
/* Fork proxy */
|
||||
proxy_pid = fork();
|
||||
if (proxy_pid < 0) {
|
||||
perror("Could not fork child");
|
||||
}
|
||||
|
||||
/* In child ... */
|
||||
else if (proxy_pid == 0) {
|
||||
proxy(connected_socket_fd);
|
||||
|
||||
/* Close socket */
|
||||
if (close(connected_socket_fd) < 0) {
|
||||
perror("Error closing connection");
|
||||
return 3;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Child exiting.\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
else
|
||||
fprintf(stderr, "Child forked.\n");
|
||||
|
||||
}
|
||||
|
||||
/* Close socket */
|
||||
if (close(socket_fd) < 0) {
|
||||
perror("Error closing socket");
|
||||
return 3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user