日期:2014-05-16  浏览次数:20751 次

求救。。。linux kernel 下的结构体使用问题。。。。
不行了。。。我的代码如下,请高手指教
* Implementation of a cut-through target for client.
 *@author Ivan Lam <ivanlam@antioch.poly.edu>
 */
 
//#define __KERNEL__
//#define MODULE

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
//#include <linux/config.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/slab.h>
#include <linux/netfilter_ipv4.h>
#include <net/checksum.h>
#include <net/udp.h>
#include <net/tcp.h>
#include <linux/time.h>
#include <linux/tty.h>


// Necessary because we use proc fs
//#include <linux/proc_fs.h>
//#include <asm/uaccess.h>

// We scheduale tasks here
//#include <linux/tqueue.h>

// We also need a timer
//#include <linux/sched.h>

#include "test.h"
/*#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

static int debug=0;
module_param(debug, int, 0000);

static char *target_eth = "0"; // the interface to monitor
module_param(target_eth, charp, 0000);

/* System parameters */
MODULE_AUTHOR(AUTHOR);
MODULE_LICENSE("GPL"); // Just to avoid the taint message

/* Program vaiables */
// counters
static unsigned int packetInCount[MAX_INGRESS_IF] = {0};
static unsigned int packetInBytes[MAX_INGRESS_IF] = {0};
static unsigned int packetInDropCount[MAX_INGRESS_IF] = {0};
static unsigned int packetInDropBytes[MAX_INGRESS_IF] = {0};
static unsigned int packetOutCount[MAX_INGRESS_IF] = {0};
static unsigned int packetOutBytes[MAX_INGRESS_IF] = {0};
static unsigned int tablenumber = 0;

typedef struct ipdata
{
unsigened char prot = "\0xx";//the protcol
unsigened char *sradd = "\0xx\0xx\0xx\0xx";//the ip sourch address
unsigened char *dtadd = "\0xx\0xx\0xx\0xx";//the ip destine address
unsigened char *destport = "\0xx\0xx";//the destine port
unsigened char *sourport = "\0xx\0xx";//the source port
}

typedef struct hashmember
{
   
struct ipdata netdata;// the data we need now
unsigned char counter = "\0xx";//the counter not used
unsigned char later ="\0xx";//the vector not used
int key = 0;//the key to found data
int length = 0;
struct hashmember *Next = 0;//the pointer to the next member

}



// For SMP, need locks

/*
 * print message to the screen
 * ref: http://tldp.org/LDP/lkmpg/2.6/html/x1161.html
 */

// hash table class.Include the fuction of search data, store data.The Remove fuction has not been finished since unused now.

static struct ipdata ipcontent;//the variable to read the data
static struct hashmember hmember;
static struct hashmember *Chashtable[251] = {0};//the member in the hashtable

bool FindValue(int key,struct ipdata &value)
{
bool ret = false;
int num = key % 251;
if(num>0)
{
hashmember *phe = Chashtable[num];
  while(phe)
{
if(phe->key = key)
{
value = phe ->netdata;
ret = true;
}
phe = phe->Next;
}
}
ALERT(0,"The value is d%",int(value->prot));
return ret;
}

bool Insert(int key,ipdata value)
{
bool ret = false;
int