~ubuntu-branches/ubuntu/trusty/modem-manager-gui/trusty-backports

« back to all changes in this revision

Viewing changes to src/netlink.h

  • Committer: Package Import Robot
  • Author(s): Graham Inggs
  • Date: 2013-07-30 12:51:59 UTC
  • Revision ID: package-import@ubuntu.com-20130730125159-flzv882fhuzhmfmi
Tags: upstream-0.0.16
ImportĀ upstreamĀ versionĀ 0.0.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      netlink.h
 
3
 *      
 
4
 *      Copyright 2012-2013 Alex <alex@linuxonly.ru>
 
5
 *      
 
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.
 
10
 *      
 
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.
 
15
 *      
 
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/>.
 
18
 */
 
19
 
 
20
#ifndef __NETLINK_H__
 
21
#define __NETLINK_H__
 
22
 
 
23
#include <time.h>
 
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>
 
29
 
 
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,
 
35
};
 
36
 
 
37
struct _mmgui_netlink_connection {
 
38
        guint inode;
 
39
        guint dqueue;
 
40
        uid_t userid;
 
41
        time_t updatetime;
 
42
        pid_t apppid;
 
43
        gchar *appname;
 
44
        gchar *dsthostname;
 
45
        gchar srcaddr[INET6_ADDRSTRLEN + 8];
 
46
        gchar dstaddr[INET6_ADDRSTRLEN + 8];
 
47
        gushort srcport;
 
48
        guchar state;
 
49
        guchar family;
 
50
};
 
51
 
 
52
typedef struct _mmgui_netlink_connection *mmgui_netlink_connection_t;
 
53
 
 
54
struct _mmgui_netlink_connection_info_request {
 
55
        struct nlmsghdr msgheader;
 
56
        struct inet_diag_req nlreq;
 
57
};
 
58
 
 
59
struct _mmgui_netlink_interface_info_request {
 
60
        struct nlmsghdr msgheader;
 
61
        struct ifinfomsg ifinfo;
 
62
};
 
63
 
 
64
struct _mmgui_netlink_interface_event {
 
65
        enum _mmgui_netlink_interface_event_type type;
 
66
        gchar ifname[IFNAMSIZ];
 
67
        gboolean running;
 
68
        gboolean up;
 
69
        guint64 rxbytes;
 
70
        guint64 txbytes;
 
71
};
 
72
 
 
73
typedef struct _mmgui_netlink_interface_event *mmgui_netlink_interface_event_t;
 
74
 
 
75
struct _mmgui_netlink {
 
76
        //Connections monitoring
 
77
        gint connsocketfd;
 
78
        pid_t userid;
 
79
        GHashTable *connections;
 
80
        struct sockaddr_nl connaddr;
 
81
        //Network interfaces monitoring
 
82
        gint intsocketfd;
 
83
        struct sockaddr_nl intaddr;
 
84
};
 
85
 
 
86
typedef struct _mmgui_netlink *mmgui_netlink_t;
 
87
 
 
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);
 
91
 
 
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);
 
95
 
 
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);
 
98
 
 
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);
 
101
 
 
102
GHashTable *mmgui_netlink_get_connections_list(mmgui_netlink_t netlink);
 
103
 
 
104
void mmgui_netlink_close(mmgui_netlink_t netlink);
 
105
mmgui_netlink_t mmgui_netlink_open(void);
 
106
 
 
107
#endif /* __NETLINK_H__ */