4
* Copyright 2012-2013 Alex <alex@linuxonly.ru>
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 3 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
#include <sys/types.h>
25
#include <netinet/in.h>
26
#include <linux/netlink.h>
27
#include <linux/inet_diag.h>
28
#include <linux/rtnetlink.h>
30
enum _mmgui_netlink_interface_event_type {
31
MMGUI_NETLINK_INTERFACE_EVENT_TYPE_UNKNOWN = 0,
32
MMGUI_NETLINK_INTERFACE_EVENT_TYPE_ADD = 1 << 0,
33
MMGUI_NETLINK_INTERFACE_EVENT_TYPE_REMOVE = 1 << 1,
34
MMGUI_NETLINK_INTERFACE_EVENT_TYPE_STATS = 1 << 2,
37
struct _mmgui_netlink_connection {
45
gchar srcaddr[INET6_ADDRSTRLEN + 8];
46
gchar dstaddr[INET6_ADDRSTRLEN + 8];
52
typedef struct _mmgui_netlink_connection *mmgui_netlink_connection_t;
54
struct _mmgui_netlink_connection_info_request {
55
struct nlmsghdr msgheader;
56
struct inet_diag_req nlreq;
59
struct _mmgui_netlink_interface_info_request {
60
struct nlmsghdr msgheader;
61
struct ifinfomsg ifinfo;
64
struct _mmgui_netlink_interface_event {
65
enum _mmgui_netlink_interface_event_type type;
66
gchar ifname[IFNAMSIZ];
73
typedef struct _mmgui_netlink_interface_event *mmgui_netlink_interface_event_t;
75
struct _mmgui_netlink {
76
//Connections monitoring
79
GHashTable *connections;
80
struct sockaddr_nl connaddr;
81
//Network interfaces monitoring
83
struct sockaddr_nl intaddr;
86
typedef struct _mmgui_netlink *mmgui_netlink_t;
88
gboolean mmgui_netlink_terminate_application(pid_t pid);
89
gchar *mmgui_netlink_socket_state(guchar state);
90
gboolean mmgui_netlink_update(mmgui_netlink_t netlink);
92
gboolean mmgui_netlink_request_connections_list(mmgui_netlink_t netlink, guint family);
93
gboolean mmgui_netlink_request_interface_statistics(mmgui_netlink_t netlink, gchar *interface);
94
gboolean mmgui_netlink_read_interface_event(mmgui_netlink_t netlink, gchar *data, gsize datasize, mmgui_netlink_interface_event_t event);
96
gint mmgui_netlink_get_connections_monitoring_socket_fd(mmgui_netlink_t netlink);
97
gint mmgui_netlink_get_interfaces_monitoring_socket_fd(mmgui_netlink_t netlink);
99
struct sockaddr_nl *mmgui_netlink_get_connections_monitoring_socket_address(mmgui_netlink_t netlink);
100
struct sockaddr_nl *mmgui_netlink_get_interfaces_monitoring_socket_address(mmgui_netlink_t netlink);
102
GHashTable *mmgui_netlink_get_connections_list(mmgui_netlink_t netlink);
104
void mmgui_netlink_close(mmgui_netlink_t netlink);
105
mmgui_netlink_t mmgui_netlink_open(void);
107
#endif /* __NETLINK_H__ */