aboutsummaryrefslogtreecommitdiff
path: root/modules/network.c
diff options
context:
space:
mode:
authorBurt P <pburt0@gmail.com>2017-07-18 04:02:46 -0500
committerLeandro Pereira <leandro@hardinfo.org>2017-07-19 07:20:06 -0700
commit86392b019dc32bcf2dc63bad246bd1558f459b04 (patch)
tree0c9162d4f843c4acb638a3f3884f16546414ce0f /modules/network.c
parenta0902475b6541553b365308241bebb93d2ee48f4 (diff)
network: headers for network interfaces list translatable
Some noise in the diff due to automatic trailing whitespace removal. Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules/network.c')
-rw-r--r--modules/network.c114
1 files changed, 59 insertions, 55 deletions
diff --git a/modules/network.c b/modules/network.c
index 18f8ba65..cd942297 100644
--- a/modules/network.c
+++ b/modules/network.c
@@ -80,37 +80,37 @@ void scan_statistics(gboolean reload)
FILE *netstat;
gchar buffer[256];
gchar *netstat_path;
-
+
SCAN_START();
-
+
g_free(__statistics);
__statistics = g_strdup("");
-
+
if ((netstat_path = find_program("netstat"))) {
gchar *command_line = g_strdup_printf("%s -s", netstat_path);
-
+
if ((netstat = popen(command_line, "r"))) {
while (fgets(buffer, 256, netstat)) {
if (!isspace(buffer[0]) && strchr(buffer, ':')) {
gchar *tmp;
-
+
tmp = g_ascii_strup(strend(buffer, ':'), -1);
-
+
__statistics = h_strdup_cprintf("[%s]\n",
__statistics,
tmp);
-
+
g_free(tmp);
} else if (isdigit(buffer[4])) {
gchar *tmp1 = buffer + 4,
*tmp2 = tmp1;
-
+
while (*tmp2 && !isspace(*tmp2)) tmp2++;
*tmp2 = 0;
tmp2++;
-
+
*tmp2 = toupper(*tmp2);
-
+
__statistics = h_strdup_cprintf("%s=%s\n",
__statistics,
g_strstrip(tmp1),
@@ -120,11 +120,11 @@ void scan_statistics(gboolean reload)
pclose(netstat);
}
-
+
g_free(command_line);
g_free(netstat_path);
}
-
+
SCAN_END();
}
@@ -133,24 +133,24 @@ void scan_dns(gboolean reload)
{
FILE *resolv;
gchar buffer[256];
-
+
SCAN_START();
-
+
g_free(__nameservers);
__nameservers = g_strdup("");
-
+
if ((resolv = fopen("/etc/resolv.conf", "r"))) {
while (fgets(buffer, 256, resolv)) {
if (g_str_has_prefix(buffer, "nameserver")) {
gchar *ip;
struct sockaddr_in sa;
char hbuf[NI_MAXHOST];
-
+
ip = g_strstrip(buffer + sizeof("nameserver"));
-
+
sa.sin_family = AF_INET;
sa.sin_addr.s_addr = inet_addr(ip);
-
+
if (getnameinfo((struct sockaddr *)&sa, sizeof(sa), hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD)) {
__nameservers = h_strdup_cprintf("%s=\n",
__nameservers,
@@ -159,15 +159,15 @@ void scan_dns(gboolean reload)
__nameservers = h_strdup_cprintf("%s=%s\n",
__nameservers,
ip, hbuf);
-
- }
-
+
+ }
+
shell_status_pulse();
- }
+ }
}
fclose(resolv);
}
-
+
SCAN_END();
}
@@ -184,15 +184,15 @@ void scan_route(gboolean reload)
FILE *route;
gchar buffer[256];
gchar *route_path;
-
+
SCAN_START();
g_free(__routing_table);
__routing_table = g_strdup("");
-
+
if ((route_path = find_program("route"))) {
gchar *command_line = g_strdup_printf("%s -n", route_path);
-
+
if ((route = popen(command_line, "r"))) {
/* eat first two lines */
(void)fgets(buffer, 256, route);
@@ -203,7 +203,7 @@ void scan_route(gboolean reload)
buffer[31] = '\0';
buffer[47] = '\0';
buffer[53] = '\0';
-
+
__routing_table = h_strdup_cprintf("%s / %s=%s|%s|%s\n",
__routing_table,
g_strstrip(buffer), g_strstrip(buffer + 16),
@@ -211,14 +211,14 @@ void scan_route(gboolean reload)
g_strstrip(buffer + 48),
g_strstrip(buffer + 32));
}
-
+
pclose(route);
}
-
+
g_free(command_line);
g_free(route_path);
}
-
+
SCAN_END();
}
@@ -227,12 +227,12 @@ void scan_arp(gboolean reload)
{
FILE *arp;
gchar buffer[256];
-
+
SCAN_START();
g_free(__arp_table);
__arp_table = g_strdup("");
-
+
if ((arp = fopen("/proc/net/arp", "r"))) {
/* eat first line */
(void)fgets(buffer, 256, arp);
@@ -240,17 +240,17 @@ void scan_arp(gboolean reload)
while (fgets(buffer, 256, arp)) {
buffer[15] = '\0';
buffer[58] = '\0';
-
+
__arp_table = h_strdup_cprintf("%s=%s|%s\n",
__arp_table,
g_strstrip(buffer),
g_strstrip(buffer + 72),
g_strstrip(buffer + 41));
}
-
+
fclose(arp);
}
-
+
SCAN_END();
}
@@ -260,15 +260,15 @@ void scan_connections(gboolean reload)
FILE *netstat;
gchar buffer[256];
gchar *netstat_path;
-
+
SCAN_START();
g_free(__connections);
__connections = g_strdup("");
-
+
if ((netstat_path = find_program("netstat"))) {
gchar *command_line = g_strdup_printf("%s -an", netstat_path);
-
+
if ((netstat = popen("netstat -an", "r"))) {
while (fgets(buffer, 256, netstat)) {
buffer[6] = '\0';
@@ -284,14 +284,14 @@ void scan_connections(gboolean reload)
g_strstrip(buffer + 68)); /* state */
}
}
-
+
pclose(netstat);
}
-
+
g_free(command_line);
g_free(netstat_path);
}
-
+
SCAN_END();
}
@@ -342,18 +342,22 @@ gchar *callback_connections()
gchar *callback_network()
{
- return g_strdup_printf(_("%s\n"
- "[$ShellParam$]\n"
- "ReloadInterval=3000\n"
- "ViewType=1\n"
- "ColumnTitle$TextValue=Interface\n"
- "ColumnTitle$Value=IP Address\n"
- "ColumnTitle$Extra1=Sent\n"
- "ColumnTitle$Extra2=Received\n"
- "ShowColumnHeaders=true\n"
- "%s"),
- network_interfaces,
- network_icons);
+ return g_strdup_printf("%s\n"
+ "[$ShellParam$]\n"
+ "ReloadInterval=3000\n"
+ "ViewType=1\n"
+ "ColumnTitle$TextValue=%s\n" /* Interface */
+ "ColumnTitle$Value=%s\n" /* IP Address */
+ "ColumnTitle$Extra1=%s\n" /* Sent */
+ "ColumnTitle$Extra2=%s\n" /* Received */
+ "ShowColumnHeaders=true\n"
+ "%s",
+ network_interfaces,
+ _("Interface"),
+ _("IP Address"),
+ _("Sent"),
+ _("Received"),
+ network_icons);
}
gchar *callback_route()
@@ -411,12 +415,12 @@ void hi_module_init(void)
void hi_module_deinit(void)
{
moreinfo_del_with_prefix("NET");
-
+
g_free(smb_shares_list);
g_free(nfs_shares_list);
g_free(network_interfaces);
g_free(network_icons);
-
+
g_free(__statistics);
g_free(__nameservers);
g_free(__arp_table);