Mohammad Kahledi
Mohammad Kahledi

Reputation: 31

freeDiameter based server cannot read received buffer

I have tried to set up a server with a specific IP address and Port number by freeDiameter libraries. In other side, there is a client that sends a string message via freeDiameter libraries successfully; I checked it out in Wireshark.

So, here is the problem; when I start listening from the server side, it has no problem until a client sends a connection request; if you look at the below code, "fd_cnx_serv_accept(listener)" is listening to a socket named "listener" which is bind to a specific IP address and Port number.

uint8_t * rcv_buf;
size_t    rcv_size;
struct cnxctx * listener_side = NULL;
int ret;



listener_side = fd_cnx_serv_accept(listener);
ret = fd_cnx_start_clear(listener_side, 0);
if(ret != 0){
    std::cout<<side<<" is unable to accept connections."<<std::endl;
    return -1;
}


ret = fd_cnx_receive(listener_side, NULL, &rcv_buf, &rcv_size);
if(ret == 0){
    std::cout<<"Message received."<<std::endl;
    listener_side = NULL;
    free(rcv_buf);
}

The program works fine until it gets a client request; when "fd_cnx_serv_accept" accept the client side, the program tries to receive the message by "fd_cnx_receive"; but the program stops and shows the error "Segmentation fault (core dumped)". Then, I test the program by gdb and it shows that it is something wrong with the line 309 of "hook.c". Here is the image of the error which is shown by gdb.

Error Screenshot

transcript

multi-thre Thread 0x7fffff72a77 In: fd_hook_call 
[New Thread 0x7fffff72a7700 (LWP 1612914)
Thread 2 "server" received signal SIGSEGEV, Segmentation Fault
[Switching to Thread 0x7fffff72a7700 (LWP 1612914)
--Type <RET> for more, q to quit, c to continue without paging --c

0x00007ffff7f2cefc in fd_hook_call (type=HOOD_DATA_RECEIVED, msg=0x0, peer=0x0, other=0x7ffff72a6be0, pmdl=0x7ffff0000ba8 at /root/projects/start_cnx_free/third-party/libfdcore/hooks.c:309

It is good to mention that I am trying to write a c++ program. How can I solve this problem ?

Upvotes: 0

Views: 157

Answers (1)

Mohammad Kahledi
Mohammad Kahledi

Reputation: 31

I solved this problem myself. I forgot to use fd_hooks_init() at the begining of my program to initialize necessary libraries and objects. Here is the modified code:

 /* Initialize the library -- must come first since it initializes the debug facility */
int ret = fd_libproto_init();
if (ret != 0) {
    fprintf(stderr, "Unable to initialize libfdproto: %s\n", strerror(ret));
    return ret;
}
ret = fd_hooks_init();
if(ret != 0){
     std::cout<<"Unable to initialize the hooks."<<std::endl;
     return ret;
}
/* Initialize the config with default values */
memset(&g_conf, 0, sizeof(struct fd_config));
fd_g_config = &g_conf;
ret = fd_conf_init();
if (ret != 0) {
    printf("Unable to initialize the config with default values.");
    return ret;
}

/* Add definitions of the base protocol */
ret = fd_dict_base_protocol(fd_g_config->cnf_dict);
if (ret != 0) {
    printf("Unable to add definitions of the base protocol.");
    return ret;
}

Upvotes: 2

Related Questions