[완료]리눅스 커널 프로그래밍 패킷뷰어 를 공부하는데

minsu9101의 이미지

환경은 우분투입니다
커널 버전은 2.6 이상이구요 ㅎ
아래는 공부하던 소스에서 에러가 난 부분의 함수를 복사해온 것입니다.

IP헤더라고 주석이 쓰여져 있는 곳에
struct iphdr *iph = (struct iphdr*)(*pskb)->nh.iph;
이부분 nh라는 멤버가 없다고 하네요
그래서 sk_buff 헤더파일을 찾아봤는데
nh가 없더라구요
혹시 우분투는 뭔가 다른건지 (다른 리눅스와 다른 부분이 여러가지 있더라구요 ㅋㅋ)
아 그리고 sk_buff.h 의 위치가 /usr/src/커널버전/include/linux 아래에 있는게 맞는건가요??
부탁드립니다 고수님들 ㅋㅋ

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/ip.h>			// iphdr
#include <linux/tcp.h>			// tcphdr
#include <linux/netdevice.h> 		// net_device
 
unsigned int hook_simple( unsigned int hook_no,
    struct sk_buff **pskb,
    const struct net_device *dev_in,
    const struct net_device *dev_out,
    int (*handler)( struct sk_buff * ) )
{
  // IP 헤더
	struct iphdr *iph = (struct iphdr*)(*pskb)->nh.iph;//--------nh라는 멤버가 없데요ㅜㅜ---------
  // IP 부분을 건너뛴 곳에서부터 TCP 헤더의 시작
	struct tcphdr *th = (struct tcphdr*)( (*pskb)->data + ( iph->ihl * 4 ) );
 
  char *data = NULL;
  int length = 0;
 
  unsigned long saddr = 0;
  unsigned long daddr = 0;
  unsigned short sport = 0;
  unsigned short dport = 0;
 
  int ctr = 0;
 
  length = (*pskb)->len - iph->ihl * 4 - th->doff * 4;
 
  data = kmalloc( length, GFP_KERNEL );
  memset( data, 0, length );
 
  // 데이터 영역만 복사
  memcpy( data, (unsigned char *)th + th->doff * 4, length );
 
  saddr = ntohl( iph->saddr );
  daddr = ntohl( iph->daddr );
  sport = th->source;
  dport = th->dest;
 
  printk( "%lu.%lu.%lu.%lu:%5u -> %lu.%lu.%lu.%lu:%5u\n",
      ( saddr & 0xFF000000 ) >> 24,
      ( saddr & 0x00FF0000 ) >> 16,
      ( saddr & 0x0000FF00 ) >> 8,
      ( saddr & 0x000000FF ),
      sport,
      ( daddr & 0xFF000000 ) >> 24,
      ( daddr & 0x00FF0000 ) >> 16,
      ( daddr & 0x0000FF00 ) >> 8,
      ( daddr & 0x000000FF ),
      dport );
 
  /*
  for( ctr = 0; ctr < length; ctr++ )
  {
    printk( "%02x\n", *(data + ctr ) );
  }
  */
 
  kfree( data );
  return NF_ACCEPT;
}

mithrandir의 이미지

이름이 바뀌었댑니다.

http://forum.falinux.com/zbxe/?mid=question&document_srl=530905

언제나 삽질 - http://tisphie.net/typo/
프로그래밍 언어 개발 - http://langdev.net

언제나 삽질 - http://tisphie.net/typo/
프로그래밍 언어 개발 - http://langdev.net

minsu9101의 이미지

감ㄴ사합니닼ㅋㅋㅋㅋ

아 드디어 ㅋㅋ

그런데 sk_buff헤더파일이 제가 말한곳에 있는건가요??