libmnl
1.0.4
Main Page
Modules
Data Structures
Files
File List
examples
usersock
sender.c
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <unistd.h>
4
#include <time.h>
5
#include <arpa/inet.h>
6
7
#include <libmnl/libmnl.h>
8
9
int
main(
int
argc,
char
*argv[])
10
{
11
struct
mnl_socket
*nl;
12
char
*buf;
13
struct
nlmsghdr *nlh;
14
struct
nfgenmsg *nfh;
15
uint32_t portid;
16
int
ret;
17
18
buf = malloc(1 << 30);
19
20
if
(argc != 2) {
21
fprintf(stderr,
"Usage: %s <portid>\n"
, argv[0]);
22
exit(EXIT_FAILURE);
23
}
24
25
nl = mnl_socket_open(NETLINK_USERSOCK);
26
if
(nl == NULL) {
27
perror(
"mnl_socket_open"
);
28
exit(EXIT_FAILURE);
29
}
30
31
printf(
"connecting to port ID %d\n"
, atoi(argv[1]));
32
/* if (mnl_socket_connect(nl, 0, atoi(argv[1])) < 0) {
33
perror("mnl_socket_connect");
34
exit(EXIT_FAILURE);
35
}*/
36
37
nlh = mnl_nlmsg_put_header(buf);
38
nlh->nlmsg_type = 0;
39
nlh->nlmsg_flags = 0;
40
41
struct
sockaddr_nl addr = {
42
.nl_family = AF_NETLINK,
43
.nl_pid = atoi(argv[1]),
44
};
45
46
ret = mnl_socket_send_addr(nl, buf, 1 << 30, &addr);
47
if
(ret == -1) {
48
perror(
"mnl_socket_sendto"
);
49
exit(EXIT_FAILURE);
50
}
51
/*
52
portid = mnl_socket_get_portid(nl);
53
54
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
55
if (ret == -1) {
56
perror("mnl_socket_recvfrom");
57
exit(EXIT_FAILURE);
58
}
59
60
ret = mnl_cb_run(buf, ret, seq, portid, data_cb, NULL);
61
if (ret == -1) {
62
perror("mnl_cb_run");
63
exit(EXIT_FAILURE);
64
} else if (ret <= MNL_CB_STOP)
65
break;
66
}
67
68
mnl_socket_close(nl);
69
*/
70
return
0;
71
}
mnl_socket
Definition:
socket.c:69
Generated on Wed Jan 10 2018 02:27:29 for libmnl by
1.8.8