I am trying to add SSL functionality to my existing TCP echo client-server application.
Earlier in my simple server, I was spawning a new child for every incoming client connection. To this child, I was passing the conn-fd (char*) as a command-line argument. (shown below)
execl("./simple_server_instance", conn_fd, NULL);
Now, for my secure server, I need to pass a CYASSL object (a structure in effect) instead of the conn_fd. (shown below)
ssl = CyaSSL_new(ctx);
CyaSSL_set_fd(ssl, connfd);
Here ‘ssl’ is the object that needs to be passed to the child process. I tried the following ways to achieve it, but unsuccessful. Is there a simple alternative, or should i go the serialization way?
-
Typecasting the ssl object to char*
-
Creating a buffer and doing a memcpy of the entire structure. (shown below)
unsigned char sslobjbuf[sizeof(ssl)]; memcpy(&sslobjbuf, ssl, sizeof(ssl)); execl("./secure_server_instance", "hello", "25", sslobjbuf, NULL );
sdsd
When you
execl()a process, you completely replace the running process with the exec’ed process. Theexecfamily of functions expect a sequence of null terminated strings which will become available asarvg[]in the spawned application. You can’t just pass arbitrary objects via this interface.When you probably want to use instead is the
forksystem call which gives you a new child process which shares its code/data with the parent. The code for./simple_server_instancewould be merged with the main server code. You can do yourssl = CyaSSL_new(ctx);call in the parent process to obtain the object you require, thenfork. The parent can then continue to serve new requests while the child runs the thesslobject.Something like this flow of control may work: