CESNET / libnetconf2

C NETCONF library
BSD 3-Clause "New" or "Revised" License
202 stars 145 forks source link

Query: Any MACRO can be used in code to distuigush major SO version 4 and Majsor SO version 3? #456

Open starx1000 opened 7 months ago

starx1000 commented 7 months ago

hello, New libnetconf2 introduced new API e.g

nc_client_ssh_set_knownhosts_mode

and obsolete some API e.g

nc_client_ssh_set_auth_hostkey_check_clb

Changed some API, e.g from void nc_client_init() to int nc_client_init()

Is there any MACRO can be used then we can compile the code and use it with different version?

For example OPENSSL:

#if OPENSSL_VERSION_NUMBER < 0x30000000L
    CallSomeAPIOnlyAvaibleLessThanThirdZero()
#else
    CallSomeAPIOnlyAvaibleBigThanThirdZero()
#endif

Thank you.

starx1000 commented 7 months ago

Then I can write some code like e.g


#if LIBNETCONF2_VERSION_NUMBER < 0x400L
    nc_client_ssh_set_auth_hostkey_check_clb();
#else
   nc_client_ssh_set_knownhosts_mode();
#endif
michalvasko commented 7 months ago

There is the header nc_version.h that you can include manually and then test for NC_VERSION_MAJOR. But I think the differences are significant so I am not sure what code you will end up with when trying to support both version in a single project.

starx1000 commented 7 months ago

OK, got it. thank you.

starx1000 commented 7 months ago

I only used part of the client and all those 3 changes is what I seen from the changes.

nc_client_ssh_set_auth_hostkey_check_clb
nc_client_ssh_set_knownhosts_mode
int nc_client_init()

Other API that I used here includes:

nc_connect_ssh
nc_client_ssh_set_auth_password_clb
nc_client_ssh_set_username
nc_client_destroy

nc_session_free
nc_session_get_status

nc_send_rpc
nc_recv_reply
nc_recv_notif

nc_rpc_establishsub
nc_rpc_free
nc_rpc_getdata
nc_rpc_editdata

Looks like no changes for those APIs? Or do you see any changes inside between the APIs?

michalvasko commented 7 months ago

If you are using only the client API then yes, you should be fine.