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

📄 cardif_generic.c

📁 Linux dot1x认证的实现
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************* * A generic PCAP/DNET handler for support of various OSes.  (Doesn't * provide any kind of wireless support!!!!!!) * * File: cardif_generic.c * * Authors: Chris.Hessing@utah.edu * * $Id: cardif_generic.c,v 1.10 2006/10/05 22:23:50 chessing Exp $ * $Date: 2006/10/05 22:23:50 $ * $Log: cardif_generic.c,v $ * Revision 1.10  2006/10/05 22:23:50  chessing * Added new association option to the config file, and attempt to associate using methods other than open system. * * Revision 1.9  2006/06/02 00:17:22  galimorerpg * More "-L" fixups for building with broken linkers. * Added missing stubs to cardif_generic to prevent linker bail on missing symbols. * * Revision 1.8  2006/06/01 23:30:46  galimorerpg * Removed whitespace between -L and path to fix building with grumpy linkers. * * Fixups to help cardif_generic.c build. * * Revision 1.7  2006/06/01 22:49:49  galimorerpg * Converted all instances of u_char to uint8_t * Fixed a bad #include in the generic frame handler. * * Revision 1.6  2006/05/13 05:56:44  chessing * Removed last pieces of code that relied on SIGALRM.  Active scan timeout is now configurable so that people that wish to hammer on their cards now have the option to do that. ;) * * Revision 1.5  2006/01/19 05:37:04  chessing * WPA2 is working correctly.  Added the ability to query the card to gather encryption/authentication capabilities.  1.2.3 is now ready to go. * * Revision 1.4  2005/08/09 01:39:14  chessing * Cleaned out old commit notes from the released version.  Added a few small features including the ability to disable the friendly warnings that are spit out.  (Such as the warning that is displayed when keys aren't rotated after 10 minutes.)  We should also be able to start when the interface is down.  Last, but not least, we can handle empty network configs.  (This may be useful for situations where there isn't a good reason to have a default network defined.) * * *******************************************************************/#ifdef GENERIC_FRAMER#include <dnet.h>#include <pcap.h>#include <stdlib.h>#include <string.h>#include <unistd.h>#include "cardif/cardif.h"#include "xsupconfig.h"#include "profile.h"#include "xsup_debug.h"#include "xsup_err.h"#include "cardif/generic/cardif_generic.h"#ifndef ETH_P_EAPOL#define ETH_P_EAPOL 0x888e#endifconst struct pcap_pkthdr *packet_header;const uint8_t *packet_ptr;int more_frames_avail = 0;pcap_handler packet_catch(uint8_t *args, const struct pcap_pkthdr *header, 			  const uint8_t *packet){  packet_header = header;  packet_ptr = packet;}/*********************************************** * * Return a handle to a pcap descriptor.  If NULL is returned, * we have an error. * ***********************************************/pcap_t *setup_pcap(char *dev_to_use, char *src_mac, int buf_size, int timeout, 		   char pcapErr[PCAP_ERRBUF_SIZE]){  char pcap_err[PCAP_ERRBUF_SIZE];   // pcap error buffer.  pcap_t *pcap_descr = NULL;  bpf_u_int32 pcap_maskp;  bpf_u_int32 pcap_netp;  char pcap_filter[100];  struct bpf_program pcap_fp;  char *errbuf=NULL;  pcap_lookupnet(dev_to_use, &pcap_netp, &pcap_maskp, pcap_err);  pcap_descr = pcap_open_live(dev_to_use, buf_size, 1, timeout, pcap_err);  if (pcap_descr == NULL)    {      debug_printf(DEBUG_NORMAL, "pcap_open_live(): %s\n", pcap_err);      return NULL;    }  sprintf(pcap_filter, "ether dst %s or ether dst 01:80:c2:00:00:03 and ether proto 0x888e", eth_ntoa(src_mac));  debug_printf(DEBUG_INT, "PCAP Filter : %s\n", pcap_filter);    if (pcap_compile(pcap_descr, &pcap_fp, pcap_filter, 0, pcap_netp) == -1)    {      debug_printf(DEBUG_NORMAL, "Error running pcap compile!\n");      return NULL;    }  if (pcap_setfilter(pcap_descr, &pcap_fp) == -1)    {      debug_printf(DEBUG_NORMAL, "Error setting filter!\n");      return NULL;    }  if (pcap_setnonblock(pcap_descr, 1, errbuf) == -1)    {      debug_printf(DEBUG_NORMAL, "Couldn't put interface in to non-blocking "		   "mode!\n");      debug_printf(DEBUG_NORMAL, "Timers won't work, and problems may "		   "result!\n");    }  return pcap_descr;}/*********************************************** * * Do whatever is needed to get the interface in to a state that we can send * and recieve frames on the network.  Any information that we need to later * use should be stored in the interface_data structure. * ***********************************************/int cardif_init(struct interface_data *thisint, char driver){  char pcap_err[PCAP_ERRBUF_SIZE], source_mac[6];  struct gen_sock_data *sockData;  debug_printf(DEBUG_INT, "Initializing interface %s..\n", thisint->intName);  if (thisint->intName == NULL)    {      debug_printf(DEBUG_NORMAL, "Invalid interface!\n");      return -1;    }  // For this code, we only handle 1 interface, so the index doesn't matter.  thisint->intIndex = 0;  // Allocate memory for the things we need.  thisint->sockData = (void *)malloc(sizeof(struct gen_sock_data));  if (thisint->sockData == NULL)    {      debug_printf(DEBUG_NORMAL, "Error allocating memory!\n");      return XEMALLOC;    }  sockData= thisint->sockData;  if ((sockData->eth = eth_open(thisint->intName)) == NULL)    {      debug_printf(DEBUG_NORMAL, "Couldn't open interface %s at line %d in cardif_generic.c!\n",		   thisint->intName, __LINE__);      return -1;    }  // Get our MAC address.  if (eth_get(sockData->eth, &source_mac) < 0)    {      debug_printf(DEBUG_NORMAL, "Couldn't get MAC address!\n");      return -1;    }  if ((sockData->pcap_descr = setup_pcap(thisint->intName, 					 (char *)&source_mac, 					 1700, 0, 					 pcap_err)) == NULL)    {      debug_printf(DEBUG_NORMAL, "Couldn't open interface %s at line %d in cardif_generic.c!\n",		   thisint->intName, __LINE__);      return -1;    }  // Store a copy of our source MAC for later use.  memcpy((char *)&thisint->source_mac[0], (char *)&source_mac[0], 6);  return XENONE;}/************************************************************** * * We don't know how to handle keys, so don't do anything. * **************************************************************/void cardif_reset_keys(struct interface_data *thisint){  return;}/************************************************************** * * If we determine that this interface is a wireless interface, then * we should call this, to have the destination address changed to the * AP that we are talking to.  Otherwise, we will always send frames to * the multicast address, instead of the AP.  (And, most APs won't answer * to the multicast address.) * **************************************************************/int cardif_check_dest(struct interface_data *thisint){  // We probably don't need this either.  return XENOWIRELESS;}/****************************************** * * Return the socket number for functions that need it. * ******************************************/int cardif_get_socket(struct interface_data *thisint){  // This has no meaning in the context of this driver!  return -1;}/****************************************** * * Clean up anything that was created during the initialization and operation * of the interface.  This will be called before the program terminates. * ******************************************/int cardif_deinit(struct interface_data *thisint){  struct gen_sock_data *sockData;  sockData = thisint->sockData;  debug_printf(DEBUG_EVERYTHING, "Cleaning up interface %s...\n",thisint->intName);  // Shutdown libdnet  if (sockData->eth != NULL)    {      sockData->eth = eth_close(sockData->eth);    }  if (sockData->pcap_descr != NULL)    {      pcap_close(sockData->pcap_descr);    }  // Now clean up the memory.  if (thisint->sockData != NULL)    {      free(thisint->sockData);      thisint->sockData = NULL;    }  return XENONE;}/****************************************** * * Set a wireless key.  Also, based on the index, we may change the transmit * key. * ******************************************/int cardif_set_wireless_key(struct interface_data *thisint, uint8_t *key, 			    int keylen, int index){  // We won't ever set a key, so return an error.  return XENOWIRELESS;}/****************************************** * * Ask the wireless card for the ESSID that we are currently connected to.  If * this is not a wireless card, or the information is not available, we should * return an error. * ******************************************/int cardif_GetSSID(struct interface_data *thisint, char *ssid_name){  // We don't have any wireless interfaces.  return XENOWIRELESS;}/****************************************** * * Normally set the SSID on the card.  But, cardif_generic doesn't understand * keying, so return XENOWIRELESS. * ******************************************/int cardif_SetSSID(struct interface_data *thisint, char *ssid_name){  return XENOWIRELESS;}/****************************************** * * Check the SSID against what we currently have, and determine if we need * to reset our configuration. * ******************************************/int cardif_check_ssid(struct interface_data *thisint){  // We aren't wireless!  return XENOWIRELESS;}/****************************************** * * Get the Broadcast SSID (MAC address) of the Access Point we are connected  * to.  If this is not a wireless card, or the information is not available, * we should return an error. * ******************************************/int cardif_GetBSSID(struct interface_data *thisint, char *bssid_dest){  // Not wireless  return XENOWIRELESS;}/****************************************** * * Set the flag in the state machine that indicates if this interface is up * or down.  If there isn't an interface, we should return an error. * ******************************************/int cardif_get_if_state(struct interface_data *thisint){  // Not sure if there is a good way to do this.  return TRUE;}/****************************************** * * Send a frame out of the network card interface.  If there isn't an 

⌨️ 快捷键说明

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