common.c File Reference

wpa_supplicant/hostapd / common helper functions, etc. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
#include <ctype.h>
#include <time.h>
#include <sys/time.h>
#include "common.h"

Include dependency graph for common.c:

Go to the source code of this file.

Functions

int hostapd_get_rand (u8 *buf, size_t len)
void hostapd_hexdump (const char *title, const u8 *buf, size_t len)
int hwaddr_aton (const char *txt, u8 *addr)
 Convert ASCII string to MAC address.
int hexstr2bin (const char *hex, u8 *buf, size_t len)
 Convert ASCII hex string into binary data.
char * rel2abs_path (const char *rel_path)
void inc_byte_array (u8 *counter, size_t len)
 Increment arbitrary length byte array by one.
void print_char (char c)
void fprint_char (FILE *f, char c)
void wpa_debug_print_timestamp (void)
 Print timestamp for debug output.
void wpa_printf (int level, char *fmt,...)
 conditional printf
void wpa_hexdump (int level, const char *title, const u8 *buf, size_t len)
 conditional hex dump
void wpa_hexdump_key (int level, const char *title, const u8 *buf, size_t len)
 conditional hex dump, hide keys
void wpa_hexdump_ascii (int level, const char *title, const u8 *buf, size_t len)
 conditional hex dump
void wpa_hexdump_ascii_key (int level, const char *title, const u8 *buf, size_t len)
 conditional hex dump, hide keys

Variables

int wpa_debug_level = MSG_INFO
int wpa_debug_show_keys = 0
int wpa_debug_timestamp = 0


Detailed Description

wpa_supplicant/hostapd / common helper functions, etc.

Copyright
Copyright (c) 2002-2005, Jouni Malinen <[email protected]>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation.

Alternatively, this software may be distributed under the terms of BSD license.

See README and COPYING for more details.

Definition in file common.c.


Function Documentation

int hexstr2bin const char *  hex,
u8 *  buf,
size_t  len
 

Convert ASCII hex string into binary data.

Parameters:
hex ASCII hex string (e.g., "01ab")
buf Buffer for the binary data
len Length of the text to convert in bytes (of buf); hex will be double this size
Returns:
0 on success, -1 on failure (invalid hex string)

Definition at line 143 of file common.c.

int hwaddr_aton const char *  txt,
u8 *  addr
 

Convert ASCII string to MAC address.

Parameters:
txt MAC address as a string (e.g., "00:11:22:33:44:55")
addr Buffer for the MAC address (ETH_ALEN = 6 bytes)
Returns:
0 on success, -1 on failure (e.g., string not a MAC address)

Definition at line 112 of file common.c.

void inc_byte_array u8 *  counter,
size_t  len
 

Increment arbitrary length byte array by one.

Parameters:
counter Pointer to byte array
len Length of the counter in bytes
This function increments the last byte of the counter by one and continues rolling over to more significant bytes if the byte was incremented from 0xff to 0x00.

Definition at line 209 of file common.c.

void wpa_debug_print_timestamp void   ) 
 

Print timestamp for debug output.

This function prints a timestamp in <seconds from 1970>.<microsoconds> format if debug output has been configured to include timestamps in debug messages.

Definition at line 241 of file common.c.

void wpa_hexdump int  level,
const char *  title,
const u8 *  buf,
size_t  len
 

conditional hex dump

Parameters:
level priority level (MSG_*) of the message
title title of for the message
buf data buffer to be dumped
len length of the buf
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. The contents of buf is printed out has hex dump.

Definition at line 303 of file common.c.

void wpa_hexdump_ascii int  level,
const char *  title,
const u8 *  buf,
size_t  len
 

conditional hex dump

Parameters:
level priority level (MSG_*) of the message
title title of for the message
buf data buffer to be dumped
len length of the buf
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. The contents of buf is printed out has hex dump with both the hex numbers and ASCII characters (for printable range) are shown. 16 bytes per line will be shown.

Definition at line 359 of file common.c.

void wpa_hexdump_ascii_key int  level,
const char *  title,
const u8 *  buf,
size_t  len
 

conditional hex dump, hide keys

Parameters:
level priority level (MSG_*) of the message
title title of for the message
buf data buffer to be dumped
len length of the buf
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. The contents of buf is printed out has hex dump with both the hex numbers and ASCII characters (for printable range) are shown. 16 bytes per line will be shown. This works like wpa_hexdump_ascii(), but by default, does not include secret keys (passwords, etc.) in debug output.

Definition at line 365 of file common.c.

void wpa_hexdump_key int  level,
const char *  title,
const u8 *  buf,
size_t  len
 

conditional hex dump, hide keys

Parameters:
level priority level (MSG_*) of the message
title title of for the message
buf data buffer to be dumped
len length of the buf
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration. The contents of buf is printed out has hex dump. This works like wpa_hexdump(), but by default, does not include secret keys (passwords, etc.) in debug output.

Definition at line 309 of file common.c.

void wpa_printf int  level,
char *  fmt,
  ...
 

conditional printf

Parameters:
level priority level (MSG_*) of the message
fmt printf format string, followed by optional arguments
This function is used to print conditional debugging and error messages. The output may be directed to stdout, stderr, and/or syslog based on configuration.

Note: New line '
' is added to the end of the text when printing to stdout.

Definition at line 270 of file common.c.

Here is the call graph for this function:


Generated on Sat May 6 21:14:20 2006 for wpa_supplicant by  doxygen 1.4.2