in src/tpm_comm_emulator.c [218:260]
TPM_COMM_HANDLE tpm_comm_create(const char* endpoint)
{
TPM_COMM_INFO* result;
if ((result = malloc(sizeof(TPM_COMM_INFO))) == NULL)
{
LogError("Failure: malloc tpm communication info.");
}
else
{
memset(result, 0, sizeof(TPM_COMM_INFO));
int cpy_res;
if (endpoint != NULL)
{
cpy_res = mallocAndStrcpy_s(&result->socket_ip, endpoint);
}
else
{
cpy_res = mallocAndStrcpy_s(&result->socket_ip, TPM_SIMULATOR_ADDRESS);
}
if (cpy_res != 0)
{
LogError("Failure: to copy endpoint");
free(result);
result = NULL;
}
else if ((result->socket_conn = tpm_socket_create(result->socket_ip, TPM_SIMULATOR_PORT)) == NULL)
{
LogError("Failure: connecting to tpm simulator.");
free(result->socket_ip);
free(result);
result = NULL;
}
else if (execute_simulator_setup(result) != 0)
{
LogError("Failure: connecting to tpm simulator.");
tpm_socket_destroy(result->socket_conn);
free(result->socket_ip);
free(result);
result = NULL;
}
}
return result;
}