util.c File Reference

#include "top_defs.h"
#include "util.h"
#include "wl_util.h"
#include <stdio.h>
#include <errno.h>
#include <string.h>

Go to the source code of this file.

Functions

const char * ip2str (struct ip_addr addr)
int join_argv (char *dst, size_t dst_len, int argc, char *argv[])
void print_network (struct wl_network_t *wl_network)
void print_network_list (void)
struct ip_addr str2ip (const char *str)


Function Documentation

const char* ip2str ( struct ip_addr  addr  ) 

Definition at line 35 of file util.c.

Referenced by cmd_ping(), cmd_status(), document_index_html_cb(), gui_status_up_cb(), ip_status_cb(), ping_recv(), and print_stats().

00036 {
00037         static char buf[16];
00038         sniprintf(buf, sizeof(buf), "%lu.%lu.%lu.%lu",
00039                  (addr.addr >> 24) & 0xff,
00040                  (addr.addr >> 16) & 0xff,
00041                  (addr.addr >> 8) & 0xff,
00042                  (addr.addr) & 0xff);
00043         return buf;
00044 }

int join_argv ( char *  dst,
size_t  dst_len,
int  argc,
char *  argv[] 
)

Definition at line 100 of file util.c.

References printk().

Referenced by cmd_connect().

00100                                                                  {
00101         char *p = dst;
00102         int i;
00103         int len = 0;
00104 
00105         /* Not really kosher, an ssid may legally contain 0-bytes but
00106          * the console interface does not deal with that.
00107          */
00108         for (i = 0; i < argc; i++) {
00109                 len += strlen(argv[i]);
00110                 if (len > dst_len) {
00111                         printk("ssid too long (max %d)\n", dst_len);
00112                         return 0;
00113                 }
00114                 p += sniprintf(p,
00115                                dst_len - (p - dst), 
00116                                "%s ", 
00117                                argv[i]);
00118         }
00119         p--;
00120         *p = '\0'; /* Delete last space */
00121 
00122         return p - dst;
00123 }

void print_network ( struct wl_network_t *  wl_network  ) 

Definition at line 66 of file util.c.

References mac2str(), printk(), and ssid2str().

Referenced by cmd_status(), and print_network_list().

00067 {
00068         printk("%s ", mac2str(wl_network->bssid.octet));
00069         printk("\"%s\"", ssid2str(&wl_network->ssid));
00070         printk(" RSSI %d dBm ", wl_network->rssi);
00071         switch (wl_network->enc_type) {
00072         case ENC_TYPE_WEP :
00073                 printk(" (WEP encryption)");
00074                 break;
00075         case ENC_TYPE_TKIP :
00076                 printk(" (TKIP encryption)");
00077                 break;
00078         case ENC_TYPE_CCMP :
00079                 printk(" (CCMP encryption)");
00080                 break;
00081         case ENC_TYPE_NONE :
00082                 break;
00083         }
00084         printk("\n");
00085 }

void print_network_list ( void   ) 

Definition at line 87 of file util.c.

References print_network(), and printk().

Referenced by cmd_scan().

00088 {
00089         struct wl_network_t* wl_network_list;
00090         uint8_t wl_network_cnt, i;
00091         
00092         wl_get_network_list(&wl_network_list, &wl_network_cnt);
00093         if (wl_network_cnt == 0)
00094                 printk("no nets found\n");
00095 
00096         for (i = 0; i < wl_network_cnt; i++)
00097                 print_network(&wl_network_list[i]);
00098 }

struct ip_addr str2ip ( const char *  str  )  [read]

Definition at line 46 of file util.c.

References str.

Referenced by cmd_ttcp(), and init_ping_info().

00047 {
00048         int a,b,c,d;
00049         uint32_t ip = 0;
00050 
00051         if (siscanf(str,"%d.%d.%d.%d",&a,&b,&c,&d) != 4)
00052                 goto out;
00053 
00054         if (a < 0 || a > 255 || b < 0 || b > 255 ||
00055             c < 0 || c > 255 || d < 0 || d > 255)
00056                 goto out;
00057         
00058         ip = (a << 24) | (b << 16) | (c << 8) | d;
00059 
00060  out:
00061         return *(struct ip_addr*) &ip;
00062 }


Generated on Fri Feb 19 02:24:09 2010 for AVR32 - H&D by  doxygen 1.5.5