How to compile libnl-3.2.25 in CentOS 6

Source: Internet
Author: User
Tags centos

I. There is a software compilation prompt for libnl3: no, all need to install a libnl, here choose to compile and install the latest libnl-3.2.25.tar.gz, the compilation process is as follows:

Wget http://www.infradead.org /~ Tgr/libnl/files/libnl-3.2.25.tar.gz
Tar zxvf libnl-3.2.25.tar.gz
Cd libnl-3.2.25
./Configure -- prefix =/usr/
Make & make install

2. The following prompt is displayed after you execute./configure:


-------------------------------------------------------------------------------
NOTE
 
There have been some changes starting with 3.2 regarding where and how libnl
Is being installed on the system in order to allow multiple libnl versions
To be installed in parallel:
 
-Headers will be installed in $ {prefix}/include/libnl3, therefore
You will need to add "-I/usr/include/libnl3" to CFLAGS
 
-The library basename was renamed to libnl-3, I. e. the SO names become
Libnl-3.so, libnl-route-3.so, etc.
 
-Libtool versioning was assumed, to revoke detection of compatible library
Versions.
 
If you are using pkg-config for detecting and linking against the library
Things will continue magically as if nothing every happened. If you are
Linking manually you need to adapt your Makefiles or switch to using
Pkg-config files.
 
-------------------------------------------------------------------------------
3. Execute the following command before re-compiling the software so that the corresponding lib can be found.

Export LIBGNUTLS_LIBS = "-L/usr/lib/-lgnutls"
Export LIBGNUTLS_CFLAGS = "-I/usr/include /"
 
Export LIBNL3_CFLAGS = "-I/usr/include/libnl3"
Export LIBNL3_LIBS = "-L/usr/lib/-lnl-3-lnl-route-3"

4. What is libnl3?

Core library provides basic functions for communication using netlink sockets. It processes socket connection establishment and disconnection, sends and receives data, constructs and parses messages, and provides a configurable receiving state machine. In addition, it provides a framework for abstract data types, which makes object-based netlink protocol easier to implement. In this protocol, objects can be added, deleted, or modified through the netlink-based protocol.

How to link to this library

Use autoconf to check whether the library exists

For those projects that use autoconf, you can use PKG_CHECK_MODULES () to check whether a specific version of libnl exists in the system. The following example also shows how to obtain the CFLAGS and link dependencies required to link to the libnl Library.

The following example shows how to check whether a specific version of libnl exists. If so, this example also shows how to correctly extend the CFLAGS and LIBS variables:

PKG_CHECK_MODULES (LIBNL3, libnl3-3.0> = 3.1, [have_libnl3] = yes, [have_libnl3 = no])
If (test "$ (have_libnl3)" = "yes"); then
CFLAGS + = "$ (LIBNL3_CFLAGS )"
LIBS + = "$ (LIBNL3_LIBS )"
Fi
Note: naming pkgconfig as a libnl-3.0.pc is a legacy issue and it actually contains libraries with version numbers greater than 3.1.

Header file

The header file to be included is <netlink/netlink. h>. Depending on the subsystems and components you use, you may need to add some additional header files to your header files.

# Include <netlink/netlinl. h>
# Include <netlink/cache. h>
# Include <netlink/route/link. h>
Code dependent on the version number

If you want to link multiple versions of libnl in your code, you can let the compiler compile the code that contains specific parts of your code based on the specific version of the libnl library you want to link.

# Include <netlink/version. h>

# If LIBNL_VER_NUM> = LIBNL_VER (3.1)
/* Include code if compiled with libnl version >=3.1 */
# End if
Link

$ Gcc myprogram. c-o myprogram $ (pkgconfig -- cflags -- libs libnl-3.0)
1.3. Debugging

This library contains debugging statements during compilation, so that it can print debugging information to stderr when you set the environment variable value of NLDBG to a value greater than 0.

$ NLDBG = 2./myprogram
Table 1. Debugging level
Level Description
0

Disable debugging (default)

1

Warning information, important events and notification information

2

More less important information

3

This leads to repeated screen flushing of debugging information.

4

Messages that are less important than the above information

Netlink protocol debugging

It is usually useful to view the netlink message streams exchanged between sockets. Set the environment variable NLCB value to debug (NLCB = debug) to run the debugging message processor, which prints the exchanged netlink message into a format that is easy to read and output to stderr.

$ NLCB = debug./myprogram
-- Debug: Sent Message:
-------------------------- Begin netlink message ---------------------------
[HEADER] 16 ETS
. Nlmsg_len = 20
. Nlmsg_type = 18 & lt; route/link: get & gt;
. Nlmsg_flags = 773 & lt; REQUEST, ACK, ROOT, MATCH & gt;
. Nlmsg_seq = 1301410712
. Nlmsg_pid = 20014
[PAYLOAD] 16 ETS
00 00 00 00 00 00 00 00 00 00 00 00 00 ................
--------------------------- End netlink message ---------------------------
-- Debug: Received Message:
-------------------------- Begin netlink message ---------------------------
[HEADER] 16 ETS
. Nlmsg_len = 996
. Nlmsg_type = 16 & lt; route/link: new & gt;
. Nlmsg_flags = 2 & lt; MULTI & gt;
. Nlmsg_seq = 1301410712
. Nlmsg_pid = 20014
[PAYLOAD] 16 ETS
00 00 04 03 01 00 00 00 00 49 00 00 00 00 00 ...... I .......
[ATTR 03] 3 octets
6c 6f 00 lo.
[PADDING] 1 octets
00.
[ATTR 13] 4 octets
00 00 00 00 ....
[ATTR 16] 1 octets
00.
[PADDING] 3 octets
00 00 00...
[ATTR 17] 1 octets
00.
[...]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.