>> Read No. 24272 article  
정말감사염[냉무]

등록 2001-03-19 02:49:00     조회 2
이름 쉬바    

		:  아 넷스 넘드리당.
:
: SIOCGIF~ 이런 류는 sys/ioctl.h에 들어있습니다.
: #include <sys/ioctl.h>
: 헤더를 포함하시길.
: 
: : 리눅스 보안쪽을 공부하려구 무작정 책을 보구 있습니다.
: :
: : 리눅스 프로그래밍을 공부한게 아니라서...
: :
: : 혹 이글을 보시구 먼저 공부해야 할게 있다면 가차없는 채찍질을 해 주세요.
: :
: :
: : linux_sniffer.c 화일을 받아다가
: : cc linux_sniffer.c -o linux_sniffer 하구 컴팔을 했는데 오류 메시지는 다음과 같습니다.
: :
: : linux_sniffer.c: In function 'initdevice':
: : linux_sniffer.c:72: 'SIOCGIFFLAGS' undeclared (first use in this function)
: : linux_sniffer.c:72: (Each undelcared identifier is reported only once
: :                      for each function it appears in.)
: : linux_sniffer.c:84: 'SIOCSIFFLAGS' undeclared (first use in this function)
: :
: :
: : 이걸 보시구 꼭 연락좀 주시면 감사하겠습니다.
: :
: :
: :
: : 소스 코드를 넣죠.
: :
: : /* ipl.c 1/3/95    by loq */
: : /* monitors ip packets for Linux */
: : #include <sys/types.h>
: : #include <sys/socket.h>
: : #include <sys/time.h>
: : #include <netinet/in.h>
: : #include <linux/if.h>
: : #include <signal.h>
: : #include <stdio.h>
: : #include <linux/socket.h>
: : #include <linux/ip.h>
: : #include <linux/tcp.h>
: : #include <linux/if_ether.h>
: :
: : #define BUFLEN 8192
: : #define ETHLINKHDR 14
: :
: :
: : print_data(int count, char *buff)
: : {
: : 	int i,j,c;
: : 	int printnext=1;
: : 	if(count)
: : 	{
: : 	if(count%16)
: : 		c=count+(16-count%16);
: : 	else c=count;
: : 	}
: : 		else
: : 		c=count;
: : 	for(i=0;i<c;i++)
: : 	{
: : 		if(printnext) { printnext--; printf("%.4x ",i&0xffff); }
: : 		if(i<count)
: : 		printf("%3.2x",buff[i]&0xff);
: : 		else
: : 		printf("   ");
: : 		if(!((i+1)%8))
: : 			if((i+1)%16)
: : 				printf(" -");
: : 			else
: : 				{
: : 					printf("   ");
: : 					for(j=i-15;j<=i;j++)
: : 					  if(j<count) {
: : 						if( (buff[j]&0xff) >= 0x20 &&
: : 						    (buff[j]&0xff)<=0x7e)
: : 						      printf("%c",buff[j]&0xff);
: : 						else printf(".");
: : 						} else printf(" ");
: : 				printf(""); printnext=1;
: : 				}
: : 	}
: : }
: :
: : int
: : initdevice(device, pflag)
: : 	char *device;
: : 	int pflag;
: : {
: : #define PROTO htons(0x0800)   /* Ethernet code for IP protocol */
: :
: : 	int if_fd=0;
: : 	struct ifreq ifr;
: :
: : 	if ( (if_fd=socket(AF_INET,SOCK_PACKET,PROTO)) < 0 ) {
: : 		perror("Can't get socket");
: : 		exit(2);
: : 	}
: :
: : 	strcpy(ifr.ifr_name, device);       /* interface we're gonna use */
: : 	if( ioctl(if_fd, SIOCGIFFLAGS, &ifr) < 0 ) {    /* get flags */
: : 		close(if_fd);
: : 		perror("Can't get flags");
: : 		exit(2);
: : 	}
: : #if 1
: : 	if ( pflag )
: : 		ifr.ifr_flags |= IFF_PROMISC;         /* set promiscuous mode */
: : 	else
: : 		ifr.ifr_flags &= ~(IFF_PROMISC);
: : #endif
: :
: : 	if( ioctl(if_fd, SIOCSIFFLAGS, &ifr) < 0 ) {    /* set flags */
: : 		close(if_fd);
: : 		perror("Can't set flags");
: : 		exit(2);
: : 	}
: : 	return if_fd;
: : }
: :
: : struct etherpacket {
: : 	struct ethhdr		eth;
: : 	struct iphdr		ip;
: : 	struct tcphdr		tcp;
: : 	char			data[8192];
: : 	};
: :
: : main()
: : {
: : 	int linktype;
: : 	int if_eth_fd=initdevice("eth0",1);
: : #if 0
: : 	int if_ppp_fd=initdevice("sl0",1);
: : #endif
: : 	struct etherpacket ep;
: : 	struct sockaddr dest;
: : 	struct iphdr *ip;
: : 	struct tcphdr *tcp;
: : 	struct timeval timeout;
: : 	fd_set rd,wr;
: : 	int dlen;
: : #if 0
: : 	struct slcompress *slc=slhc_init(64,64);
: : #endif
: :
: : 	for(;;)
: : 	{
: : 		bzero(&dest,sizeof(dest));
: : 		dlen=0;
: : 		FD_ZERO(&rd);
: : 		FD_ZERO(&wr);
: : 		FD_SET(if_eth_fd,&rd);
: : #if 0
: : 		FD_SET(if_ppp_fd,&rd);
: : #endif
: : 		timeout.tv_sec=0;
: : 		timeout.tv_usec=0;
: : 		ip=(struct iphdr *)(((unsigned long)&ep.ip)-2);
: : 		tcp=(struct tcphdr *)(((unsigned long)&ep.tcp)-2);
: : 		while(timeout.tv_sec==0 && timeout.tv_usec==0)
: : 		{
: : 		timeout.tv_sec=10;
: : 		timeout.tv_usec=0;
: : 		select(20,&rd,&wr,NULL,&timeout);
: : 		if(FD_ISSET(if_eth_fd,&rd))
: : 			{
: : 			printf("eth");
: : 			recvfrom(if_eth_fd,&ep,sizeof(ep),0,&dest,&dlen);
: : 			}
: : #if 0
: : 		else
: : 			if(FD_ISSET(if_ppp_fd,&rd))
: : 			{
: : 			recvfrom(if_ppp_fd,&ep,sizeof(ep),0,&dest,&dlen);
: : 			printf("ppp");
: : 			}
: : #endif
: : 		}
: :
: : 		printf("proto: %.4x",ntohs(ep.eth.h_proto));
: : #if 0
: : 		if(ep.eth.h_proto==ntohs(8053))
: : 		{
: : 			slhc_uncompress(slc,&ep,sizeof(ep));
: : 		}
: : #endif
: :
: : 		if(ep.eth.h_proto==ntohs(ETH_P_IP))
: : 		{
: : 		printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x->",
: : 			ep.eth.h_source[0],ep.eth.h_source[1],
: : 			ep.eth.h_source[2],ep.eth.h_source[3],
: : 			ep.eth.h_source[4],ep.eth.h_source[5]);
: : 		printf("%.2x:%.2x:%.2x:%.2x:%.2x:%.2x ",
: : 			ep.eth.h_dest[0],ep.eth.h_dest[1],
: : 			ep.eth.h_dest[2],ep.eth.h_dest[3],
: : 			ep.eth.h_dest[4],ep.eth.h_dest[5]);
: : 		printf("%s[%d]->",inet_ntoa(ip->saddr),ntohs(tcp->source));
: : 		printf("%s[%d]",inet_ntoa(ip->daddr),ntohs(tcp->dest));
: : 		print_data(htons(ip->tot_len)-sizeof(ep.ip)-sizeof(ep.tcp),
: : 			ep.data-2);
: : 		}
: : 	}
: : }
: :
: : --
: : 도배성 글인갑다. 지숭.--감사염 ^^
이름
암호
Register [ localhost 목록보기 윗글 아랫글
글쓰기
답장쓰기 수정 삭제
정규표현식 [ 상세 검색 ]
페이지로딩: [ 6.22 초 ] 작업시간: [ 5.8 초 ]

Copyleft 1999-2026 by JSBoard Open Project
Theme Designed by IDOO All right reserved
[TOP]

적수네 동네
+
| 적수네 동네
| 공부방
| 리눅스 잡지 서고
| LSN 소스
| 링크 모음
+---+
게시판
+
| 떠들어보세!
| 질문과 답변
| 새소식과 정보
| 1원짜리 팁?
| 대화방
+---+
칼럼?
+
| 세하 훔쳐보기
| Welcome2nite
| 혜진의 염장판
+---+
리눅스 상표권
+
| 반대 서명란
| 토론 게시판
+---+
GNU
+
| GNU 선언문
| GNU GPL
| GNU 미러 목록
+---+
프로젝트?
+
| 리눅스카운터
| RC5DES
| 실질헌법 제작
+---+
커널 소식
+
| 안정 버젼: 2.4.14
+---+
테마 선택
+
LSN 방송국?
+
| OFF AIR
+---+
회원
+
| 로그인
+---+
[ 적수네 동네 ] [ 리눅스 상표권 독점 반대 ] [ 한글 리눅스 문서 프로젝트 ] [ KrLine ] [ 사랑넷 ] [ Valid HTML 4.0! ] [ SlashDot ] [ Freshmeat ]
Copyleft (C) 1998-2001 Byeong-Chan Kim . License
TIME: 1789599579
System by WYZsoft, HDD by I.O.Linux, Mizi Research, Embryo, WOWLINUX, Domain by SarangNet, Network by KrLine.