Re: libnm



On Fri, 2019-02-15 at 12:32 +0200, Kalev Toots wrote:
Hello

I try to connect 3G GSM modem to network using Network Manager,libnm
API 
and C/C++ code.
I cannot find any C/C++ example code which connects prepared NM
profile 
to network
and waits until connection is up or error or timeout. Can anybody
direct 
me to such
piece of code.


Hi,


see https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/examples/C


NetworkManager is profile based, that means in one step you create the
profile to your liking, then you just call
nm_client_activate_connection_async(). This returns you a D-Bus path to
the NMActiveConnection (which represents the activation and ties the
profile (NMRemoteConnection) to the device (NMDevice).

See for example,

nmcli: 
https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/clients/cli/connections.c?id=c032690df227a609fc4b47c78269448576b6bda1#n2790
The complicated part is waiting until the profile is fully activated:
https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/clients/cli/connections.c?id=c032690df227a609fc4b47c78269448576b6bda1#n2584


Another example is the ansible-role (Which is Python with libnm via GObject introspection):
https://github.com/linux-system-roles/network/blob/master/library/network_connections.py#L1083
This is a rather unconventional example, because it manually iterates the
glib mainloop. If you are unclear how to use the glib mainloop, then this might
*not* be the example to look at.


best,
Thomas

Attachment: signature.asc
Description: This is a digitally signed message part



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]