Default port (4822) and working connect message

This commit is contained in:
Michael Jumper
2010-11-25 19:05:15 -08:00
parent bb1ed2172a
commit e392fb59b6
2 changed files with 43 additions and 39 deletions

View File

@@ -102,50 +102,60 @@ guac_client* guac_get_client(int client_fd) {
} }
/* Connect instruction read */ /* Connect instruction read */
if (result > 0 && strcmp(instruction.opcode, "connect") == 0) { if (result > 0) {
/* Get protocol from message */ if (strcmp(instruction.opcode, "connect") == 0) {
char* protocol = instruction.argv[0];
strcat(protocol_lib, protocol); /* Get protocol from message */
strcat(protocol_lib, ".so"); char* protocol = instruction.argv[0];
/* Create new client */ strcat(protocol_lib, protocol);
client = __guac_alloc_client(io); strcat(protocol_lib, ".so");
/* Load client plugin */ /* Create new client */
client->client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY); client = __guac_alloc_client(io);
if (!(client->client_plugin_handle)) {
fprintf(stderr, "Could not open client plugin for protocol \"%s\": %s\n", protocol, dlerror());
exit(EXIT_FAILURE);
}
dlerror(); /* Clear errors */ /* Load client plugin */
client->client_plugin_handle = dlopen(protocol_lib, RTLD_LAZY);
if (!(client->client_plugin_handle)) {
syslog(LOG_ERR, "Could not open client plugin for protocol \"%s\": %s\n", protocol, dlerror());
guac_send_error(io, "Could not load server-side client plugin.");
guac_free_instruction_data(&instruction);
return NULL;
}
/* Get init function */ dlerror(); /* Clear errors */
alias.obj = dlsym(client->client_plugin_handle, "guac_client_init");
if ((error = dlerror()) != NULL) { /* Get init function */
fprintf(stderr, "Could not get guac_client_init in plugin: %s\n", error); alias.obj = dlsym(client->client_plugin_handle, "guac_client_init");
exit(EXIT_FAILURE);
}
/* Initialize client arguments */ if ((error = dlerror()) != NULL) {
argc = instruction.argc; syslog(LOG_ERR, "Could not get guac_client_init in plugin: %s\n", error);
argv = instruction.argv; guac_send_error(io, "Invalid server-side client plugin.");
guac_free_instruction_data(&instruction);
return NULL;
}
break; /* Initialize client arguments */
argc = instruction.argc;
argv = instruction.argv;
if (alias.client_init(client, argc, argv) != 0) {
guac_free_instruction_data(&instruction);
guac_send_error(io, "Error initializing server-side client.");
return NULL;
}
guac_free_instruction_data(&instruction);
return client;
} /* end if connect */
guac_free_instruction_data(&instruction);
} }
} }
if (alias.client_init(client, argc, argv) != 0)
return NULL;
guac_free_instruction_data(&instruction);
return client;
} }

View File

@@ -82,7 +82,7 @@ int main(int argc, char* argv[]) {
int connected_socket_fd; int connected_socket_fd;
/* Arguments */ /* Arguments */
int listen_port = -1; int listen_port = 4822; /* Default port */
int opt; int opt;
/* Parse arguments */ /* Parse arguments */
@@ -95,17 +95,11 @@ int main(int argc, char* argv[]) {
} }
} }
else { else {
fprintf(stderr, "USAGE: %s -l LISTENPORT\n", argv[0]); fprintf(stderr, "USAGE: %s [-l LISTENPORT]\n", argv[0]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
/* Validate arguments */
if (listen_port < 0) {
fprintf(stderr, "The port to listen on must be specified.\n");
exit(EXIT_FAILURE);
}
/* Get binding address */ /* Get binding address */
memset(&server_addr, 0, sizeof(server_addr)); /* Zero struct */ memset(&server_addr, 0, sizeof(server_addr)); /* Zero struct */
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;