From 365bf2609c2dd145c4ce1b3674e26f811d736351 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Sun, 16 Jun 2024 19:32:47 +0200 Subject: [PATCH] The pong client can now select the name of the service. --- c/pong.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/c/pong.c b/c/pong.c index fb0e569..d5fd80e 100644 --- a/c/pong.c +++ b/c/pong.c @@ -17,7 +17,9 @@ int err(void *ctx, char *msg) { return 1; } -int main(void) { +int main(int argc, char **argv, char** env) { + argc = argc; + argv = argv; int ret = 0; int servicefd = 0; char message[MAX_MSG_SIZE]; @@ -29,6 +31,15 @@ int main(void) { int newfd = 0; void *ctx = NULL; + char *service = SERVICE; + size_t i = 0; + while(env[i] != NULL) { + if(0 == memcmp(env[i], "SERVICE", strlen("SERVICE"))) { + service = env[i] + strlen("SERVICE") + 1; + } + i++; + } + printf ("Init context.\n"); ret = ipc_context_init (&ctx); @@ -37,8 +48,8 @@ int main(void) { return 1; } - printf ("Connect to a 'pong' service.\n"); - ret = ipc_connect_service (ctx, &servicefd, SERVICE, SERVICE_LEN); + printf ("Connect to a '%s' service.\n", service); + ret = ipc_connect_service (ctx, &servicefd, service, strlen(service)); if (ret != 0) { return err(ctx, "Cannot connect to a service.");