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

📄 os_wireless_ext.c

📁 linux下可以用来通过802.1x认证
💻 C
字号:
/** * A client-side 802.1x implementation supporting EAP/TLS * * This code is released under both the GPL version 2 and BSD licenses. * Either license may be used.  The respective licenses are found below. * * Copyright (C) 2002 Bryan D. Payne & Nick L. Petroni Jr. * All Rights Reserved * * --- GPL Version 2 License --- * 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; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. * * --- BSD License --- * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * *  - Redistributions of source code must retain the above copyright notice, *    this list of conditions and the following disclaimer. *  - Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. *  - All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *       This product includes software developed by the University of *       Maryland at College Park and its contributors. *  - Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. *//******************************************************************* * The driver function for a Linux application layer EAPOL  * implementation * File: os_wireless_ext.c * * Authors: bdpayne@cs.umd.edu, npetroni@cs.umd.edu * * $Id: os_wireless_ext.c,v 1.4 2003/03/05 21:18:46 npetroni Exp $ * $Date: 2003/03/05 21:18:46 $ * $Log: os_wireless_ext.c,v $ * Revision 1.4  2003/03/05 21:18:46  npetroni * migration to libdnet. Please notify developers of build problems AFTER doing a cvs update. * * Revision 1.3  2003/02/27 04:05:58  chessing * Added more error checking, fixed a few omissions that have not yet caused bugs. ;) * * Revision 1.2  2003/01/09 20:17:30  galimorerpg * Logging Updates * * Revision 1.1  2003/01/02 19:35:47  chessing * Add some files that were missed in the last import.. * * *******************************************************************//* This code originally came from eapol-bsd.c */#include <sys/types.h>#include <stdlib.h>#include <sys/param.h>  /* needed to compile; not sure why */#include <sys/socket.h>  /* needed for if.h and dummy socket */#include <net/if.h> /* for struct ifreq */#include <errno.h>#include <err.h>#include <string.h>  /* bzero, strlcpy */#include <unistd.h>  /* close */#include <stdio.h>#include <sys/ioctl.h>#include <sys/sockio.h> /* for if_aironet_ieee.h */#include "logging.h"#include "if_aironet_ieee.h"#ifndef __OpenBSD__#include <net/ethernet.h>//#include <net/if_ieee80211.h>#endif#ifndef __OpenBSD__static int ieee80211_ioctl(const char *iface, struct ieee80211req *ireq,                           u_long icall){  int d;  int s;  d = socket(AF_INET, SOCK_DGRAM, 0);  if (d == -1) {    xlogf(DEBUG_NORMAL, "Error opening socket\n");    return d;  }  s = ioctl(d, icall, &ireq);  close(d);  return s;}#endifstatic int an_ioctl(const char *iface, struct an_req *areq, u_long icall){  struct ifreq req; /* generic interface request */  int    d; /* dummy socket needed for ioctl */  int    s; /* status for ioctl */  bzero((char *) &req, sizeof(struct ifreq));  strlcpy(req.ifr_name, iface, sizeof(req.ifr_name));  /* strlcpy has bette\							  r string handling than strncpy */  req.ifr_data = (caddr_t) areq;  d = socket(AF_INET, SOCK_DGRAM, 0);  if(d == -1) {    xlogf(DEBUG_NORMAL, "Error opening socket\n");    return d;  }  s = ioctl(d, icall, &req);  //  if(s == -1)  //    err(1, "SIOCGAIRONET");  close(d);  return s;}int eapol_wireless_get_bssid(char *dev, u_char *bssid){  struct an_req areq;  struct an_ltv_status *stat;  int i,s;  areq.an_len = sizeof(areq);  areq.an_type = AN_RID_STATUS;  s = an_ioctl(dev, &areq, SIOCGAIRONET);  if(s == -1)    return s;  stat = (struct an_ltv_status *) &areq;  for(i = 0; i < 6; i++)    {      bssid[i] = (u_char) stat->an_cur_bssid[i];    }#ifdef DEBUG  xlogf(DEBUG_EVERYTHING, "BSSID = %02x", bssid[0]);  for(i = 1; i < 6; i++)    {      xlogf(DEBUG_EVERYTHING, ":%02x", bssid[i]);    }  xlogf(DEBUG_EVERYTHING, "\n");#endif  return s;}int eapol_wireless_get_ssid(char *dev, u_char *ssid){      struct an_req areq;      struct an_ltv_status *stat;      int s;      areq.an_len = sizeof(areq);      areq.an_type = AN_RID_STATUS;      s = an_ioctl(dev, &areq, SIOCGAIRONET);      if(s == -1)	return s;      stat = (struct an_ltv_status *) &areq;      strlcpy(ssid, stat->an_ssid, stat->an_ssidlen+1);#ifdef DEBUG      xlogf(DEBUG_EVERYTHING, "SSID = %s, length = %d \n", ssid, stat->an_ssidlen);#endif      return s;}int eapol_wireless_set_key(char *dev, u_char *key, int klen, int index){   struct an_req areq;   struct an_ltv_key *theKey;   int s;   /* zero out the key */   memset((char *)&areq, 0, sizeof(areq));   theKey = (struct an_ltv_key *)&areq;   memcpy(theKey->key, key, klen);   theKey->kindex = (index & 0x7f);   theKey->klen = klen;   theKey->mac[0] = 1;   theKey->mac[1] = 0;   theKey->mac[2] = 0;   theKey->mac[3] = 0;   theKey->mac[4] = 0;   theKey->mac[5] = 0;   areq.an_len = sizeof(struct an_ltv_key);   areq.an_type = AN_RID_WEP_PERM;   s = an_ioctl(dev, &areq, SIOCSAIRONET);   if (s == -1) {     xlogf(DEBUG_NORMAL, "Failed to set WEP key\n");     return s;   }   xlogf(DEBUG_NORMAL, "Successfully set WEP key %d\n", (index & 0x7f));   if (index & 0x80) {     memset((char *)&areq, 0, sizeof(areq));     theKey = (struct an_ltv_key *)&areq;     //    memcpy(theKey->key, key, klen);     theKey->kindex = 0xffff;     theKey->klen = 0;     theKey->mac[0] = (index & 0x7f);     areq.an_len = sizeof(struct an_ltv_key);     areq.an_type = AN_RID_WEP_PERM;     s = an_ioctl(dev, &areq, SIOCSAIRONET);     if (s != -1) {       xlogf(DEBUG_NORMAL, "Successfully set transmit key %d\n", (index & 0x7f));     }   }   return s;}// We don't need to do anything here for BSD.int eapol_wireless_init(){  return 0;}// We don't need to do anything here for BSD.int eapol_wireless_cleanup(){  return 0;}

⌨️ 快捷键说明

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