libmnl
1.0.4
Main Page
Modules
Data Structures
Files
File List
examples
kobject
uevent.c
1
#include <stdio.h>
2
#include <arpa/inet.h>
3
#include <linux/netlink.h>
4
#include <netlink/netlink.h>
5
#include <linux/filter.h>
6
#include <sys/stat.h>
7
#include <sys/socket.h>
8
9
//#include "xxd.c"
10
11
int
main() {
12
int
s=socket(PF_NETLINK,SOCK_RAW,NETLINK_KOBJECT_UEVENT);
13
struct
sockaddr_nl snl;
14
struct
msghdr mh;
15
struct
iovec iov;
16
ssize_t buflen;
17
unsigned
char
buf[1024];
18
19
if
(-1==s) {
20
perror(
"socket"
);
21
return
1;
22
}
23
snl.nl_family=AF_NETLINK;
24
snl.nl_groups=1|2;
25
if
(-1==bind(s,(
struct
sockaddr *)&snl,
sizeof
(snl))) {
26
perror(
"bind"
);
27
return
1;
28
}
29
while
(1) {
30
iov.iov_base=&buf;
31
iov.iov_len=
sizeof
(buf);
32
memset(&mh,0,
sizeof
(mh));
33
mh.msg_iov=&iov;
34
mh.msg_iovlen=1;
35
mh.msg_name=&snl;
36
mh.msg_namelen=
sizeof
(snl);
37
buflen=recvmsg(s,&mh,0);
38
printf(
"%s\n"
, buf);
39
// xxd(buf,buflen);
40
}
41
return
0;
42
}
Generated on Wed Jan 10 2018 02:27:29 for libmnl by
1.8.8