Added dummy proxy implementation, moved client, added main Makefile.
This commit is contained in:
1 parent
7ee970c88a
commit
c048537232
70 files changed
+159
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
.PHONY: client proxy clean
|
||||||
|
|
||||||
|
all: client proxy
|
||||||
|
|
||||||
|
client:
|
||||||
|
$(MAKE) -C client all
|
||||||
|
|
||||||
|
proxy:
|
||||||
|
$(MAKE) -C proxy all
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(MAKE) -C client clean
|
||||||
|
$(MAKE) -C proxy clean
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
.PHONY: client clean
|
||||||
|
|
||||||
|
all: client
|
||||||
|
|
||||||
|
client:
|
||||||
|
ant war
|
||||||
|
|
||||||
|
clean:
|
||||||
|
ant clean
|
||||||
|
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
|
||||||
|
all: guacd
|
||||||
|
|
||||||
|
guacd: daemon.o proxy.o
|
||||||
|
$(CC) daemon.o proxy.o -o guacd
|
||||||
|
|
||||||
|
proxy.o: proxy.c proxy.h
|
||||||
|
$(CC) -c -ansi -pedantic proxy.c
|
||||||
|
|
||||||
|
daemon.o: daemon.c proxy.h
|
||||||
|
$(CC) -c -ansi -pedantic daemon.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) *.o guacd
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
$(RM) *~
|
||||||
|
|
||||||
@@ -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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "proxy.h"
|
||||||
|
|
||||||
|
void proxy(int client_fd) {
|
||||||
|
|
||||||
|
write(client_fd, "name:hello;size:1024,768;error:Test finished.;", 46);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#ifndef _PROXY_H_
|
||||||
|
#define _PROXY_H
|
||||||
|
|
||||||
|
void proxy(int client_fd);
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in new issue
Block a user