Skip to content

amarula/nlcpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NlCpp

C++ wrapper around the libnl library; main focus of this library is:

  • Provide API suitable to use with modern C++.

  • Add type information where reasonably possible.

  • Encapsulate handling of object lifetime in a way compatible with RAII style.

Examples

List all available network interfaces:

nl::RouteCacheManager mngr;
auto rcache = mngr.linkCache();

for (const auto & link : rcache) {
    std::cout << link.ifindex() << ": " << link.name().value() << std::endl;
}

Remove all IPv4 addresses from interface with index 2:

nl::RouteSocket rsocket;
rsocket.del(nl::RouteAddress()
    .ifindex(2)
    .family(AF_INET)
);

Add a new IPv4 address:

rsocket.add(nl::RouteAddress()
    .ifindex(2)
    .local(nl::Address("192.168.0.2/24"))
);

Add a default route:

rsocket.add(nl::Route()
    .dst(nl::Address("0.0.0.0/0"))
    .add(nl::NextHop()
        .ifindex(2)
        .gateway(nl::Address("192.168.0.1"))
    )
);

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •