⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wlan_monitor.c.old

📁 wlan_monitor monitor utility for wlan device
💻 OLD
字号:
/*--------------------------------*-C-*---------------------------------* * *  Copyright 1999, Terry Duchastel <tld@cise.ufl.edu>. * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation. * *  See the INSTALL file for instructions on how to install the *  Wireless LAN Monitor. * *----------------------------------------------------------------------*/#include <applet-widget.h>#include <gnome.h>#include <gdk/gdkx.h>#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <string.h>#include <netdb.h>#include <sys/types.h>#include <netinet/in.h>#include <linux/sockios.h>#include <sys/ioctl.h>#include "wlan_monitor.h"/* Defines */#define ARRAY_WIDTH 22#define ECHO_PORT 7#define WLAN_TLD  (SIOCDEVPRIVATE +10)/* Typedefs */typedef unsigned short  UINT16;typedef struct wlan_req{	char 	name[16];	void	*data;	UINT16	result;	UINT16	len;} wlan_req_t;/* Prototypes */GtkWidget * applet_start_new_applet (const gchar *goad_id, const char	**params, int nparams);GtkWidget * make_new_panel_applet (const gchar *goad_id);gint expose_event (GtkWidget *widget, GdkEventExpose *event);gint configure_event (GtkWidget *widget, GdkEventConfigure *event);gint wlan_update (gpointer data);void wlan_init();int read_rssi();/* Global Variables */// FIX ME: These should really go into one one large struct instead of being globalGdkPixmap *graph_pixmap;         // Used for double-bufferingGdkColor blue_color;int rssi_array[ARRAY_WIDTH];     // Holds the rssi values to graphintmain (int argc, char ** argv){  const gchar *goad_id;  GtkWidget *applet;    // My own initializations  wlan_init();  applet_widget_init ("wlan_monitor", "1.0", argc, argv, NULL, 0, NULL);  applet_factory_new ("wlan_monitor", NULL,		     (AppletFactoryActivator) applet_start_new_applet);  goad_id = goad_server_activation_id ();  if (! goad_id)    return 1;  // Create the applet widget  applet = make_new_panel_applet (goad_id);  // Run...  applet_widget_gtk_main ();  return 0;} /* main */voidwlan_init( GtkWidget * applet ) {  int i=0;  for (i=0; i<ARRAY_WIDTH; i++)    rssi_array[i] = 0;}GtkWidget *applet_start_new_applet (const gchar *goad_id, const char **params,			 int nparams){  return make_new_panel_applet (goad_id);}// This is the function that actually creates the display widgetsGtkWidget *make_new_panel_applet (const gchar *goad_id){  GtkWidget *applet;               // The start of it all  GtkWidget *root;                 // The applet's only child  GtkWidget *button;  GtkWidget *graph_frame;          // Provides the bevelling and sizing  GtkWidget *graph_box;            // Holds the canvas named 'graph_area'  GtkWidget *graph_area;           // The canvas we draw on  GdkColormap *colormap;  guint update_timeout_id;  applet = applet_widget_new (goad_id);  // All widgets will go into this container.  root = gtk_hbox_new (FALSE, 0);  applet_widget_add(APPLET_WIDGET(applet), root);  // The 'graph frame' is the root widget of the entire graph mode.  // It provides the pretty bevelling.  graph_frame = gtk_frame_new (NULL);  gtk_frame_set_shadow_type (GTK_FRAME (graph_frame), GTK_SHADOW_IN);  gtk_box_pack_start_defaults (GTK_BOX (root), graph_frame);  gtk_widget_set_usize (graph_frame, 48, 48);  graph_box = gtk_vbox_new (TRUE, 0);  gtk_container_add( GTK_CONTAINER(graph_frame), graph_box );  graph_area = gtk_drawing_area_new ();  gtk_box_pack_start_defaults (GTK_BOX (graph_box), graph_area);    //////// BIND FUNCTIONS ////////  gtk_signal_connect (GTK_OBJECT(graph_area),"configure_event",		      (GtkSignalFunc) configure_event, NULL);  gtk_signal_connect (GTK_OBJECT (graph_area), "expose_event",		      (GtkSignalFunc) expose_event, NULL);  update_timeout_id = gtk_timeout_add (2000,				       (GtkFunction) wlan_update, 				       graph_area);  gtk_widget_show_all( applet );  //////// COLORS /////////*  colormap = gtk_widget_get_colormap (graph_area);  gdk_color_parse ( "#0000ff", &blue_color );  gdk_color_alloc ( colormap, &blue_color );*/    return(applet);} /* make_new_panel_applet */// Create a new backing pixmap of the appropriate size.gint configure_event (GtkWidget *widget, GdkEventConfigure *event){  wlan_update( widget );  return TRUE;}// Redraw the screen from the backing pixmap.gint expose_event (GtkWidget *widget, GdkEventExpose *event){  gdk_draw_pixmap(widget->window,		  widget->style->fg_gc[GTK_WIDGET_STATE (widget)],		  graph_pixmap,		  0, 0,		  0, 0,		  widget->allocation.width,		  widget->allocation.height);  return FALSE;}/** * Every two seconds this function is called.  It creates a new * pixmap, gets the latest rssi value, draws the graph on the pixmap, * and then calls wlan_expose to actually blit it on the screen. */gintwlan_update (gpointer data){  GtkWidget * graph_area = data;  GdkGC graph_gc;  int i=0;  int width, height;  double rssi_value=0, temp =0;  width =  graph_area->allocation.width;  height = graph_area->allocation.height;  if (graph_pixmap)    gdk_pixmap_unref(graph_pixmap);  // Get a new pixmap and make the background color black  graph_pixmap = gdk_pixmap_new(graph_area->window,				width,				height,				-1);  gdk_draw_rectangle (graph_pixmap,		      graph_area->style->black_gc,		      TRUE,		      0, 0,		      width,		      height);  // Move everything in the array down  for ( i=1; i< ARRAY_WIDTH; i++ )    rssi_array[i-1] = rssi_array[i];  /* Read_rssi() returns a number between 0 and 255.     We need a value between 0 and 44.  That's      because the graph is 44 pixels in height. */  i = (int) ( read_rssi() / 5 );  if ( i < 0 )    i = 0;  // Add the new value  rssi_array[ARRAY_WIDTH - 1] = i;    // Draw every value onto the pixmap  for ( i=0; i < ARRAY_WIDTH; i++ )    gdk_draw_rectangle (graph_pixmap,			graph_area->style->white_gc,			TRUE,			2*i, 44-rssi_array[i],			2, 44);  // Redraw the screen  expose_event( graph_area, NULL );    return TRUE;}  /* wlan_update */intread_rssi(){  int sockfd;  struct sockaddr_in send_addr;  int numbytes;  struct hostent *he;  //char host_name[17] = "128.227.162.246";  int io_ret=2;  wlan_req_t req;  char message[2] = "A";    ////////////////// SEND A PACKET ///////////////  // Get the host info  if (( he=gethostbyname(host_name) ) == NULL) {      gnome_error_dialog	(_("Error (A) querying gateway.  "	   "Make sure that your card is "	   "inserted properly."));  }    // Get a socket  if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {    gnome_error_dialog	(_("Error (B) querying gateway.  "	   "Make sure that your card is "	   "inserted properly."));  }    send_addr.sin_family = AF_INET;            // host byte order  send_addr.sin_port = htons(ECHO_PORT);     // short, network byte order  send_addr.sin_addr = *((struct in_addr *)he->h_addr);  bzero(&(send_addr.sin_zero), 8);           // zero the rest of the struct    // Send the UDP packet  if ((numbytes=sendto(sockfd, message,strlen(message),0,(struct sockaddr *)&send_addr,		       sizeof(struct sockaddr))) == -1) {    gnome_error_dialog	(_("Error (C) querying gateway.  "	   "Make sure that your card is "	   "inserted properly."));    return (-1);  }    /////////////////// GET RSSI INFO //////////////////  // Test that there is a card  strcpy( req.name, eth_socket );  req.result = 0;  req.data = NULL;  req.len = 0;    io_ret = ioctl(sockfd, WLAN_TLD, &req);  if ( io_ret < 0 ) {    gnome_error_dialog	(_("Error (D) querying ioctl.  "	   "Make sure that you're using "	   "the correct driver."));    return (-1);  }  close(sockfd);    return( req.result );}  /* read_rssi */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -