libnetconf2 icon indicating copy to clipboard operation
libnetconf2 copied to clipboard

get the hello capability list

Open sangamesh82 opened this issue 4 years ago • 11 comments

After the call to nc_accept_callhome, I get the return as success. How do I get the hello capability list (module list) ?

sangamesh82 avatar Aug 31 '21 11:08 sangamesh82

What capability list are you trying to get, sent from the client? There should only be NETCONF 1.0/1.1 capability, which is automatically selected.

michalvasko avatar Aug 31 '21 11:08 michalvasko

What I wanted to ask was, how do I access the hello capabilities of the server from the client side ? Wanted to print all the module namespace.

sangamesh82 avatar Sep 01 '21 03:09 sangamesh82

Ah, right, it is on the client side. Call nc_session_get_cpblts().

michalvasko avatar Sep 01 '21 06:09 michalvasko

Got it.

For this to work, I need to include #include <session_p.h> which is present in the src directory.

sangamesh82 avatar Sep 01 '21 09:09 sangamesh82

Why would you? Just include nc_client.h and it will be available, you are not supposed to include anything else in a NETCONF client.

michalvasko avatar Sep 01 '21 09:09 michalvasko

If I don't include it then I get compilation error when I deference the nc_session ptr.

sangamesh82 avatar Sep 01 '21 10:09 sangamesh82

You are supposed to use the function nc_session_get_cpblts() I have mentioned, not access the structure directly.

michalvasko avatar Sep 01 '21 11:09 michalvasko

This is the error I get when I compile,

nc_call_home.c: In function ‘main’:
nc_call_home.c:89:83: error: dereferencing pointer to incomplete type ‘struct nc_session’
   89 |  printf("Session ..... \r\n\tstatus %d, NC version %d, session-id %d\r\n", session->status, session->version, session->id);
      |                                                                                   ^~
nc_call_home.c:91:8: error: too few arguments to function ‘nc_session_get_cpblts’
   91 |  cap = nc_session_get_cpblts();
      |        ^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/include/nc_client.h:32,
                 from nc_call_home.c:15:
/usr/local/include/libnetconf2/session_client.h:533:21: note: declared here
  533 | const char * const *nc_session_get_cpblts(const struct nc_session *session);
      |                     ^~~~~~~~~~~~~~~~~~~~~
	-----COMPILATION ERROR-----

sangamesh82 avatar Sep 01 '21 11:09 sangamesh82

I am not sure what to tell you, your compiler said it all.

michalvasko avatar Sep 01 '21 12:09 michalvasko

Then I need to copy the session_p.h to /usr/local/libnetconf2/ folder for easy use. Is there any other way.

sangamesh82 avatar Sep 01 '21 13:09 sangamesh82

I really do not know why I have to write it all for you but here it goes. This is the same code that you will be able to compile:

printf("Session ..... \r\n\tstatus %d, NC version %d, session-id %u\r\n", nc_session_get_status(session), nc_session_get_version(session), nc_session_get_id(session));

const char * const *capabs = nc_session_get_cpblts(session);
for (int i = 0; capabs[i]; ++i) {
    printf("Capability %s\n", capabs[i]);
}

michalvasko avatar Sep 01 '21 13:09 michalvasko