netmon_wce - network tray monitor

Configuration wizards, scanners, remote desktop, etc.
Message
Author
User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

netmon_wce - network tray monitor

#1 Post by 01micko »

netmon_wce-3.1 - see changelog below for updates

(updated 20160121)

Alternate lighter coloured icons are available from this post. (you don't need the pet as they are included but need renaming to work)

A .pot file for translators is included. Translation thread
Some translations are available from above link.
German thanks to L18L
Chinese (simplified and traditional) thanks to icake
Spanish thanks to nilsonmorales
Italian thanks to xanad

All .po files are in the source. Full NLS pets will be available soon.


netmon_wce doesn't look like anything new. It's just the same old tray app with some bugs fixed (atoll, and the sprintf) and some new headers added to reduce system calls. It also incorporates Patriot's (forum member from days gone) 'Lame WiFi', so if you are connected by wifi you get wifi signal strength icons and the %age in the tooltip. NEW VERSION. More below. (also changelog)
README.txt wrote:This is a fork of Barry's "network_tray" since it uses different icons
and has a few bugs fixed. It also incorporates Patriot's "Lame Wifi", so that
if you are connected by wifi you will get signal strength icons in the tray
and tooltip. The tooltip also shows the interface address (eg: eth0, eth1 wlan0)
and your current IPv4 address.

It also incorporates new libraries since Barry's version relied on dirent.h to
open the relevant files for reading. I have included arpa/inet.h, ifaddrs.h
and netinet/in.h to gain access to the structures that hold the interface
info and the IP address. Patriot's Lame Wifi also adds the linux/wireless.h
dependency and sys/ioctl.h.

While this does make the executable bigger (~17KB[32] ~20KB[64] stripped) I think
the gains in versatility, stability* and reliability* (* to be proven) are worth
it in the long run.

To build the exec just type 'make' at the cli. Of course devx must be loaded.
Install the exec to your PATH (or $HOME/Startup). The .desktop is provided for
recent woof puppies to be installed to $HOME/.config/autostart.

A .pot file is included for translators. The code is i18n/gettext compliant.

Install the icons to /usr/share/pixmaps/puppy

The exec is designed to run when your window manager starts (either by new woof
method of adding the supplied .desktop file and placed in $HOME/.config/autostart
or symlinking the exec to /root/Starup)

The program now has wireless polling off by default, toggled in the right click
menu. There is a mechanism whereby you can start the program in wireless polling
mode from a symlink to the exec named "netmon_wpoll" (or rename the exec). If you
do this then edit the .desktop file or the symlink in /root/Startup must be
name "netmon_wpoll".


GPL2 or later at your discretion.

NO WARRANTY!!!
Source and pets provided. If any problems, rebuild and post a pet and I'll add it here. Compiling has been tested in tahrpup and it builds and runs cleanly.

Bug reports needed.

From the changelog -

Code: Select all

netmon_wce
----------
Forked from Barry's version at 'network_tray-2.5' (2013) including Patriot's 
'Lame WiFi Tray' features.
===============================================================================
20160120 netmon_wce-3.1
-----------------------
support ipv6
 -full rewrite of struct iface_info get_info()
 -added additional headers
 -call getnameinfo() instead of directly accessing the sockets
 -code cleanup
remove the puppyism patch. I might make a separate package.
===============================================================================
20160113 netmon_wce-3.0
-----------------------
improvements to ppp icons
if pppoe is running and iface is ppp[0-9] use the standard icons
make fgets() calls more robust
exit the program if we aproach the limit for ULLONG_MAX for rx/tx bytes
add GIGABYTE definition in bytes
add <limits.h>
===============================================================================
20160106 netmon_wce-3.0beta
-----------------------
Add new icons for cell phone/3G
Add code to change icons if a ppp interface is detected
===============================================================================
20160106 netmon_wce-2.9
-----------------------
change all calls to network????_bixbuf to neticon[array]
===============================================================================
20151005 netmon_wce-2.8
-----------------------
change long long to unsigned long long - Iguleder
add French [fr] translation (thanks ASRI éducation) 
===============================================================================
20151003 netmon_wce-2.7
-----------------------
edit package script
 -bugfix a typo creating wrong symlink - peebee
change wireless icons to a 'ray' type style
add more wireless icons to indicate network activity - peebee
 -note - this will be more responsive if wifi polling is off
adjust C code for icons
adjust patch for non-puppy use
===============================================================================
20150728 netmon_wce-2.6-2
-------------------------
add Chinese, simplified and traditional [zh_CN],[zh_SG],[zh_TW],[zh_HK]
 (thanks icake)
add Spanish [es] (thanks nilsonmorales)
add Italian [it] (thanks xanad)
===============================================================================
20150728 netmon_wce-2.6-1
-------------------------
add German [de] translation (thanks L18L)
adjust make file to build .mo files and install/uninstall
moved pot to ./po
===============================================================================
20150727 netmon_wce-2.6
-----------------------
bugfix - gettext - remove '\n' char from translations for clarity
 -@line 221
 -@line 258
 -@line 313
 -@line 330
bugfix - fix compile warning -Wformat @line 139 (seen in tahrpup)
add .pot file to 'package'
fix patch for dhcpcd -k
===============================================================================
20150718 netmon_wce-2.5
-----------------------
added IP address
changed icons to SVG from XPM
added wireless icons and capability to monitor signal strength (LameWiFi tray)
removed dep dirent.h
removed dep fcntl.h
removed dep gdk/gdk.h (redundant)
added dep sys/socket.h
added dep sys/ioctl.h
added dep arpa/inet.h
added dep iwlib.h (now depends libiw)
added dep ifaddrs.h
added dep netinet/in.h
added type structure iface_info to hold ifname and ip address
added type structure link_qual to hold actual and maximum quality (wireless)
full rewrite of find_active()
 -removed dirent calls so doesn't get info from system files
 -rather, gets info from sockets
 -bugfix for atoll
 -gettext bugfixes
 -removed support for multiple interfaces
 -wireless detection
 -moved necessary globals to locals
 -added ip address
full rewrite of Update()
 -added wireless in detect mode (non-polling and polling mode)
 -added signal strength to tooltip
 -variable timeout for polling mode (5 seconds)
 -bugfix/feature addition to get correct wireles strength (Lame, thx to mikeb)
  or die trying, and suggest fallback to non-polling in tooltip
full rewrite of create_tray_icon()
 -add wireless icons
added fn get_info() to get iface_info
added fn card_qual() to get link_qual
added fn toggle_wireless_polling()
added fn quit()
added to menu Disable/Enable wireless device polling
added to menu Quit
added icons to right click menu
added variable interval timeout (only enabled for wifi polling)
ability to call from symlink 'netmon_wpoll' to start in wireless polling mode
===============================================================================
extras
------
Makefile
package script
icons (most are already in woof-ce)
netmon_wce.desktop - for woof-ce puppies (however, covered in pinstall.sh)
pinstall.sh script to accommodate woof-ce and pre-woof-ce puppies
patch to remove most 'puppyisms' + script to apply (for other distros - mikeb)
snippet for caching traffic at shut down (for other distros)
Attachments
netmon_wce-3.1-i686_s570.pet
Built in slacko-5.7
NOTE: may need to symlink libiw-29 to libiw-30 in tahr and librepup
(10.88 KiB) Downloaded 855 times
netmon_wce-3.1-x86_64_s631.pet
Built in Slacko64
(9.06 KiB) Downloaded 761 times
netmon_wce-3.1.tar.bz2
Source Code
(42.48 KiB) Downloaded 651 times
Last edited by 01micko on Thu 21 Jan 2016, 00:03, edited 14 times in total.
Puppy Linux Blog - contact me for access

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#2 Post by mikeb »

stop being so damn sensible...it will make you unpopular...nice one merging the lame wifi..I use it all the time on the laptop and long overdue to be included in puppy stuff.

Will build and test at some point..... life permitting...

now about this svg obsession that's floating around......

mike

User avatar
Smithy
Posts: 1151
Joined: Mon 12 Dec 2011, 11:17

#3 Post by Smithy »

Any chance of a pet for those who can't or won't? Might improve the amount of testers that will have a go micko.
Shiny Glossy signal strength lcd svgs, system wide for any internet source would be good.
And 'aint it funny that windows has no indicator of the 3gb consumed just looking at farcebook and so on.

User avatar
peebee
Posts: 4370
Joined: Sun 21 Sep 2008, 12:31
Location: Worcestershire, UK
Contact:

#4 Post by peebee »

Looks AOK here...........
Attachments
Screenshot.png
(10.58 KiB) Downloaded 1832 times
ImageLxPup = Puppy + LXDE
Main version used daily: LxPupSc; Assembler of UPups, ScPup & ScPup64, LxPup, LxPupSc & LxPupSc64

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#5 Post by 01micko »

mikeb wrote:stop being so damn sensible...it will make you unpopular...nice one merging the lame wifi..I use it all the time on the laptop and long overdue to be included in puppy stuff.

Will build and test at some point..... life permitting...
When yer ready :wink:
mikeb wrote:now about this svg obsession that's floating around......

mike
pros
- efficiency
- size
- simplicity

cons
- old gtk (don't work)

Besides, to patch with png or xpm is simple enough - here's the declaration

Code: Select all

//wireless icons
#define icon_wi_q5		"/usr/share/pixmaps/puppy/quality_5.svg"
#define icon_wi_q4		"/usr/share/pixmaps/puppy/quality_4.svg"
#define icon_wi_q3		"/usr/share/pixmaps/puppy/quality_3.svg"
#define icon_wi_q2		"/usr/share/pixmaps/puppy/quality_2.svg"
#define icon_wi_q1		"/usr/share/pixmaps/puppy/quality_1.svg"
#define icon_wi_dis		"/usr/share/pixmaps/puppy/quality_0.svg"

//other icons
#define networkblank 	"/usr/share/pixmaps/puppy/internet_connect.svg"
#define networkboth		"/usr/share/pixmaps/puppy/internet_connect_both.svg"
#define networkdead		"/usr/share/pixmaps/puppy/internet_connect_no.svg"
#define networkin 		"/usr/share/pixmaps/puppy/internet_connect_yes.svg"
#define networkout 		"/usr/share/pixmaps/puppy/internet_connect_yes.svg"
Puppy Linux Blog - contact me for access

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#6 Post by 01micko »

Smithy wrote:Any chance of a pet for those who can't or won't? Might improve the amount of testers that will have a go micko.
Shiny Glossy signal strength lcd svgs, system wide for any internet source would be good.
And 'aint it funny that windows has no indicator of the 3gb consumed just looking at farcebook and so on.
No (not from me). See above.

Maybe someone else will, it's all open source.
Puppy Linux Blog - contact me for access

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#7 Post by mikeb »

pros
- efficiency
- size
- simplicity
hmm one file instead of many I suppose...though not so universally supported..not just older gtk.

size...are they optimised?

simplicity... well seems to be causing a little mayhem

Anyway a little off topic.... will keep on pinging here :D

mike

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#8 Post by mikeb »

Ok built on slax 6 just fine after adding #include <linux/if.h> .. older headers need it thats all.

Ran just fine...very neat ...no wireless here but can test later...since lame wifi works I fully expect this too also.

Just wondered if there is a (easy) way to include current net load/use as well or instead of total bandwidth used? I usually have the that in xfce4...

On eof those times when a binary beats a script hands down... :)

one must give the obligatory screen shot.

mike
Attachments
icon.png
(57.31 KiB) Downloaded 1801 times

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#9 Post by mikeb »

ok feedback you want eh... ok forgot there is a machine using a ralink adapter.... tested on something resembling Lucid and it showed the right icons for thee job.

Only thing was it gave signal strength around 140% , lame wifi running concurrently said around the 98-100% mark.

Good for me as the dongle working much better that it has recently though the discrepancy seems a bit odd as both montors are based on the same code...I don't remember making any changes to lame wifi but it was some years ago so you never know....

mike

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#10 Post by rcrsn51 »

01micko wrote:pros
- efficiency
What takes more CPU cycles to render - a fixed bitmap icon or an SVG icon?

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#11 Post by mikeb »

Actually I can resize the panel up to 128 pixels high and the icon grows and grows and looks sweet...so might be love at first sight :D

mike

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#12 Post by 01micko »

rcrsn51 wrote:
01micko wrote:pros
- efficiency
What takes more CPU cycles to render - a fixed bitmap icon or an SVG icon?
Wouldn't it depend on size and complexity of the image? The svg's supplied are very simple. Note - I haven't measured.

Below is a routine I wrote just for fun (a while ago) - if GTK does it anything like this XPM seems to undergo more processing than SVG.

I must admit I haven't looked at the GTK sources, but to my way of thinking, the fact that there is a glib/GDK routine for processing XPM that surely GTK would use that. I know Joe does it in JWM directly with libxpm which would be the efficient way to do it, however his routine is rather complex compared with the librsvg>cairo routine for SVG (similar in JWM to what is posted below).

The decision to use SVG at the woof level wasn't totally blind. :)

(Disclaimer - The code below may have a bunch of bugs - I'm NOT a real programmer)

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <cairo.h>
#include <cairo-svg.h>
#include <librsvg/rsvg.h>
#include <pango/pangocairo.h>
#include <assert.h>
#include <gdk/gdk.h>
#include "xicons.h"
#include "drawicons.h"

int width = 2 * I_WIDTH;
int height = 2 * I_HEIGHT;


/* credit for this function: Owen Taylor otaylor@redhat.com 
 * http://lists.cairographics.org/archives/cairo/2006-January/006178.html */
 
cairo_surface_t *scale_surface(cairo_surface_t *old_surface, 
                int old_width, int old_height,
                int new_width, int new_height) {
	cairo_surface_t *new_surface = cairo_surface_create_similar(old_surface, 
							CAIRO_CONTENT_COLOR_ALPHA, new_width, new_height);
	cairo_t *cr = cairo_create (new_surface);
	
	/* Scale *before* setting the source surface (1) */
	cairo_scale (cr, (double)new_width / old_width, 
									(double)new_height / old_height);
	cairo_set_source_surface (cr, old_surface, 0, 0);
	
	/* To avoid getting the edge pixels blended with 0 alpha, which would 
	 * occur with the default EXTEND_NONE. Use EXTEND_PAD for 1.2 or newer (2)
	  */
	cairo_pattern_set_extend (cairo_get_source(cr), CAIRO_EXTEND_PAD); 
	
	 /* Replace the destination with the source instead of overlaying */
	cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
	
	/* Do the actual drawing */
	cairo_paint (cr);
	cairo_destroy (cr);
	return new_surface;
}

int draw_icon(cairo_surface_t *cs, 
					char *image_loc, 	
					int call_type,
					char *label,
					char *save_name) {
	/* call_type determines who called here */
	int img_type;
	char *ext_png = (strstr(image_loc, ".png"));
	char *ext_svg = (strstr(image_loc, ".svg"));
	char *ext_xpm = (strstr(image_loc, ".xpm"));
	if (ext_png) {
		img_type = 0;
		printf("image is %s\n", ext_png);
	} else if (ext_svg) {
		img_type = 1;
		printf("image is %s\n", ext_svg);
	} else if (ext_xpm) {
		img_type = 2;
		printf("image is %s\n", ext_xpm);
	} else {
		printf("extension not supported\n");
		return 1;
	}
	/* to be removed for production */
	/*char save[60];*/
	/*sprintf(save,"/tmp/icons/%s.png", save_name);*/
	/*----------------------------------*/
	int str_ln;
	str_ln = strlen(label);
	if (str_ln > 40) {
		printf("%d too long\n", str_ln);
		return 1;
	}
	
	/* font size */
	double f_size = 12.0;
	
	if (img_type == 1 ) { /* svg */
		RsvgHandle *rh;
		RsvgDimensionData dim;
		GError *e;
		/* Load the image from the file. */
		e = NULL;
		cairo_surface_t *target;
		cairo_t *context;
		int stride;
		rh = rsvg_handle_new_from_file(image_loc, &e);
		if(!rh) {
			printf("error - no rsvg handle\n");
			return 1;
		}
		rsvg_handle_get_dimensions(rh, &dim);
		unsigned char *data = malloc(4 * dim.width * dim.height);
		memset(data, 0, 4 * dim.width * dim.height);
		/* Create the target surface. */
		stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, dim.width);
		target = cairo_image_surface_create_for_data(data,
												CAIRO_FORMAT_ARGB32,
												dim.width, dim.height, stride);
		context = cairo_create(target);
		cairo_paint_with_alpha(context, 0.0);
		rsvg_handle_render_cairo(rh, context);
		cairo_surface_write_to_png (target, "/tmp/buf_svg.png");
		cairo_destroy(context);
		cairo_surface_destroy(target);
		g_object_unref(rh);
		free(data);
		
	}
	/* NOTE: this will change as I do NOT want to depend on 
	 * GDK (part of GTK) */
	if (img_type == 2) { /* XPM */
		GdkPixbuf *x_buf;
		GdkPixbuf *new_x_buf;
		int x_width = I_WIDTH;
		int x_height = I_HEIGHT;
		GError *x_e;
		x_e = NULL;
		cairo_t *xr;
		cairo_surface_t *x_surface;
		x_surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 
														x_width, x_height);
		xr = cairo_create(x_surface);
		x_buf = gdk_pixbuf_new_from_file(image_loc, &x_e); 
		new_x_buf = gdk_pixbuf_scale_simple (x_buf, x_width, x_height,
													GDK_INTERP_BILINEAR);
		gdk_cairo_set_source_pixbuf (xr, new_x_buf, 0.0, 0.0);
		cairo_paint(xr);
		cairo_surface_write_to_png (x_surface, "/tmp/buf_xpm.png");
		cairo_destroy(xr);
		cairo_surface_destroy(x_surface);
		g_object_unref(x_buf);
		g_object_unref(new_x_buf);
	}
	
	cairo_t *c;
	c = cairo_create(cs);
	if (call_type == 0) {
		cairo_set_source_rgba(c, 0.0, 0.0, 0.0, 0.0);
	} else {
		cairo_set_operator(c, CAIRO_OPERATOR_SOURCE);
	}
	cairo_rectangle(c, 0.0, 0.0, width, height);
	cairo_fill(c);
	cairo_set_antialias(c, CAIRO_ANTIALIAS_BEST);
	glob i;
	if (img_type == 0) {
		i.image = cairo_image_surface_create_from_png(image_loc);
	} else if (img_type == 1) {
		if (access("/tmp/buf_svg.png", F_OK) != -1) {
			i.image = cairo_image_surface_create_from_png("/tmp/buf_svg.png");
			unlink("/tmp/buff_svg");
		}
	} else if (img_type == 2) {
		if (access("/tmp/buf_xpm.png", F_OK) != -1) {
			i.image = cairo_image_surface_create_from_png("/tmp/buf_xpm.png");
			unlink("/tmp/buff_xpm");
		}
	}
	/* scale image to 48*48 */
	int old_w = cairo_image_surface_get_width(i.image);
	int old_h = cairo_image_surface_get_height(i.image);
	int new_w = I_WIDTH;
	int new_h = I_HEIGHT;
	cairo_surface_t *scaled_img;
	scaled_img = scale_surface(i.image, old_w, old_h, new_w, new_h);
	
	cairo_status_t res = cairo_surface_status(cs);
	const char *ret;
	ret = cairo_status_to_string (res);
	printf("Cairo : %s\n", ret);
	
	cairo_set_source_surface(c, scaled_img, I_WIDTH / 2, 0);
	
	cairo_paint(c);
	/* label */
	
	PangoLayout *layout;
	PangoFontDescription *font_description;
	
	font_description = pango_font_description_new ();
	pango_font_description_set_family (font_description, "DejaVu Sans");
	pango_font_description_set_weight (font_description, PANGO_WEIGHT_MEDIUM);
	pango_font_description_set_absolute_size (font_description, 
													f_size * PANGO_SCALE);
	
	layout = pango_cairo_create_layout (c);
	pango_layout_set_font_description (layout, font_description);
	pango_layout_set_width (layout, 19 * width / 20 * PANGO_SCALE);
	pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
	pango_layout_set_wrap (layout, PANGO_WRAP_WORD);
	pango_layout_set_text (layout, label, -1);
	
	
	cairo_move_to(c, 0 , height / 2);
	if (call_type == 1) {
		cairo_set_source_rgb(c, 1.0, 1.0, 1.0);
	} else {
		cairo_set_operator(c, CAIRO_OPERATOR_SOURCE);
	}
	pango_cairo_show_layout (c, layout);
	
	g_object_unref (layout);
	pango_font_description_free (font_description);
	
	
	cairo_show_page(c);
	cairo_surface_destroy(i.image);
	cairo_destroy(c);
	/* to be removed for production */
	/*cairo_surface_write_to_png (cs, save);*/
	/*----------------------------------*/
	return 0;
}
Puppy Linux Blog - contact me for access

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#13 Post by mikeb »

well if its xpm vs svg then I am with you all the way... 'orrible little things.... even if you can stuff them in source code.

mike

ps any thoughts on the wifi percentage, or current net usage for that matter...just to be less puppy like.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#14 Post by 01micko »

mikeb wrote:ps any thoughts on the wifi percentage, or current net usage for that matter...just to be less puppy like.
Patriot wrote:Hmmm .....

Code: Select all

    if (wiQ > 66)
		wicon = 3;
	else if (wiQ > 33)
		wicon = 2;
	else if (wiQ > 0)
		wicon = 1;
	else
		wicon = 0;

	gtk_status_icon_set_from_pixbuf(tray_icon, wiconset[wicon]);

	g_snprintf(tipbuf, 18, " lameWiFi %d%% ", wiQ);
That's Patriot's original for 4 icons plus the percentage. The other one I got from peebee's version. I'll look into it.

---------------

Code: Select all

char *rxmonthfile = "/var/local/sns/rx_bytes_month";
char *txmonthfile = "/var/local/sns/tx_bytes_month";
Yes, a few puppyisms in there. :lol:

Maybe I'll make those definitions with a compile time switch? Or not.
Puppy Linux Blog - contact me for access

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#15 Post by 01micko »

Here is a version that I want mikeb and rcrsn51 to try.

No binaries so not for general usage.

Mike - there is a patch in there! :lol: No need to speak diff as I have a script for you. It moves some stuff around and removes most puppyisms. Still haven't fixed the wifi stats but have made a start on the tc/rx stuff, moving them to /var/log which I reckon is in most if not all linux.

To apply the diff run

Code: Select all

./patch_me.sh yes
The switch is to avoid trip ups like clicking the script.
Oh, one more thing.. calls are to xmessage; just run sed over it and poke a 'g' in front.

edit: new switch
Try (you'll get sed run over the src for gxmessage)

Code: Select all

./patch_me.sh yes please
-----

Bill - I have added a '-o' option on the cli to disable wifi polling. The disadvantage to that is that you can't just poke in /root/Startup but will need a starter script with

Code: Select all

netmon_wce -o
There is also a -h option which just explains the other option.

edit
make a symlink named netmon_o and that will trigger the new feature

ATTACHMENT DELETED by me
Last edited by 01micko on Sat 18 Jul 2015, 10:46, edited 1 time in total.
Puppy Linux Blog - contact me for access

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#16 Post by mikeb »

Ah slick stuff.... I did hear a rumour /var/log was under threat in these 'ere parts ;)

will test soon as...

mike

edit

quick test patched and built and working ok... lan fine..message ok.. will test wifi later.
Will also peek at lamewifi source and see if I can shed some light on the difference.
Noticed you moved the icons...perhaps its own folder in pixmaps would be neat.... eg /usr/share/pixmaps/netmon

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#17 Post by 01micko »

Ok, looking forth to the wireless test.

While you are there, give iwconfig and cat /proc/net/wireless a run to see if we can't find your bug.
Attachments
iwconfig.png
they fluctuate quickly, hence slight differences
(37.5 KiB) Downloaded 579 times
Puppy Linux Blog - contact me for access

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#18 Post by mikeb »

Ok did the wireless test......

The clue...the results from iwconfig and cat give a percentage readout and NOT the n/70 that yours show.
This was lucid and standard lucid kernel by the way.

So it appears to be to do with the way the kernel and iwconfig present the information has changed...or that's my assumption.

Well I noticed the /70 factor adjustment in the sources so perhaps something a builder could adjust depending on the destination system.

mike

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#19 Post by 01micko »

Thanks Mike. Ah. so that explains that.

What I noticed is that Patriots version doesn't really use <ioctl.h>, <linux/wireless.h> and friends so those headers are redundant. However, I did mod the program (not ready yet) to use these headers.

If you want to compile and run the following this *should* output the quality of your wireless, however I suspect it won't make a difference. Check and see if you don't mind.

Code: Select all

#include <sys/types.h>
#include <sys/socket.h>
#include <linux/wireless.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{

    int sockfd;
    struct iw_statistics stats;
    struct iwreq req;

    memset(&stats, 0, sizeof(stats));
    memset(&req, 0, sizeof(req));
    sprintf(req.ifr_name, "wlan0"); // for debug, hardcode the iface
    req.u.data.pointer = &stats;
    req.u.data.length = sizeof(stats);
#ifdef CLEAR_UPDATED
    req.u.data.flags = 1;
#endif


    if((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
    {
        perror("socket failed");
        exit(EXIT_FAILURE);
    }

    if(ioctl(sockfd, SIOCGIWSTATS, &req) == -1)
    {
        perror("ioctl SIOCGIWSTATS failed");
        close(sockfd);
        exit(EXIT_FAILURE);
    }

    close(sockfd);

    printf("qual: %d\n",
        (int)((char)stats.qual.qual));

return 0;
}
That cast in the 'printf' is important as the kernel has its own type called __u8, which essentially is just an unsigned char, so we cast to char then int so we can work with it.

I still don't understand the pre-processor call, and until I do it stays I suppose. However I'm thinking it's irrelevant in the context of this program because we don't need any member of any type named 'flags'.

Just be aware to hard code your iface if it isn't wlan0.

ref: http://www.linuxforums.org/forum/progra ... ics-c.html
Puppy Linux Blog - contact me for access

User avatar
mikeb
Posts: 11297
Joined: Thu 23 Nov 2006, 13:56

#20 Post by mikeb »

Ok no problem... see if i can slip it in tonight....oooerr missus.

By the way a quick hack was

Code: Select all

	//get wifi quality
			if(*pos) pos++;
			sscanf(pos, "%*d %d", &wiQpc);
		}
//		wiQpc = wiQ * 100;
//		wiQpc = wiQpc / 70;
to give the right output.

mike

Post Reply