IPv6용 pcap 프로그래밍 중에서요 궁금한게 있어서 질문 드립니다.

chogood의 이미지

일단 리눅스에서 IPv6용 패킷을 분석하기 위해 pcap 프로그램을 작성했는데요..

한개의 인터페이스 패킷을 캡쳐하는 것은 잘 동작하고 있습니다.

그런데 한 pc에 두개의 인터페이스가 있을 때 둘다 패킷을 캡쳐 하고 싶습니다.
또한 캡쳐한 패킷이 어느 인터페이스에서 캡쳐된 건지도 알고 싶은데요...

현재 여러가지 검색을 해보고 혼자 삽질을 했는데 잘 몰라서요.

일단 IPv6용 패킷 분석하는 프로그램의 소스를 올려놓으께요..

많은 도움 부탁드립니다.

#include
//#include
#include
#include
void HexView(u_char* ucData, int len);
void PrintIPHeader(u_char* ucData);
int i=1;

int main()
{
char errbuf[PCAP_ERRBUF_SIZE];
char* spNetDevName = pcap_lookupdev(errbuf);
u_char* ucData;
int iDataLink;
int retv;

struct pcap_pkthdr stPInfo;

pcap_t* pDes;

if(0 == spNetDevName)
{
printf("Error : [%s]\n", errbuf);
return 100;
}
else
{
printf("Network Devie Name : [%s]\n", spNetDevName);
}
pDes = pcap_open_live(spNetDevName, 1500, 1, 0, errbuf);

if(0 == pDes)
{
printf("Error : [%s]\n", errbuf);
return 101;
}
else
{
iDataLink = pcap_datalink(pDes);
}

if(DLT_EN10MB == iDataLink)
{
printf("2Layer Type : [Ethernet (10Mb)]\n", iDataLink);
}

do
{
ucData = pcap_next(pDes, &stPInfo);

printf("\n\nCap Length : %d Bytes\n", stPInfo.caplen);
printf("Length : %d Bytes\n", stPInfo.len);
if(40 > stPInfo.caplen) continue;

printf("=========================================================================\n");
printf("Destination MAC Address : %02X:%02X:%02X:%02X:%02X:%02X\n",
*ucData, *(ucData+1), *(ucData+2), *(ucData+3), *(ucData+4),
*(ucData+5));
printf("Source MAC Address : %02X:%02X:%02X:%02X:%02X:%02X\n",
*(ucData+6), *(ucData+7), *(ucData+9), *(ucData+10), *(ucData+11),
*(ucData+12));

PrintIPHeader(ucData+14);
HexView(ucData, stPInfo.caplen);
}while(stPInfo.caplen < 4000);

// pcap_close(pDes);

// return 0;
}

void PrintIPHeader(u_char* ucData)
{
u_char* p = ucData;
u_char uctemp;
uint16_t ustemp;
uint32_t uitemp;

// IP Version(4bits)
uctemp = *p;
uctemp = uctemp>>4;

if(4 == uctemp)
{
printf("IP Version : IPv4\n");
}
else if(6 == uctemp)
{
printf("IP Version : IPv6\n");
}
else
{
printf("IP Version : %d\n", uctemp);
}

++p;

ustemp = *(uint16_t *)p;
ustemp = ntohs(ustemp);
p += 2;

ustemp = *(uint16_t *)p;
ustemp = ntohs(ustemp);
p += 2;
++p;
++p;
uitemp = *p;
printf("Source Ip Address : %02X%02X::%02X%02X:%02X%02X:%02X%02X:%02X%02X\n",
*(ucData+8), *(ucData+9), *(ucData+16), *(ucData+17), *(ucData+18),*(ucData+19), *(ucData+20), *(ucData+21), *(ucData+22), *(ucData+23));
uitemp = *p;
printf("Destination Ip Address : %02X%02X::%02X%02X:%02X%02X:%02X%02X:%02X%02X\n",
*(ucData+24), *(ucData+25), *(ucData+32), *(ucData+33), *(ucData+34),*(ucData+35), *(ucData+36), *(ucData+37), *(ucData+38), *(ucData+39), *(ucData+40));
p += 4;

printf("ping number : %d\n", i);
i++;

}

void HexView(u_char * ucData, int len)
{
int iCntx, iCnty, iCntz;
int addr = 0;
u_char * p = ucData;

printf("=========================================================================\n");
printf("address 0 1 2 3 4 5 6 7 8 9 A B C D E F ASCII code\n");
printf("=========================================================================\n");

for(iCntx = 0, iCntz = 0; iCntx < len/16+1; ++iCntx)
{
printf("%08X ", addr);

for(iCnty = 0; iCnty < 16; ++iCnty)
{
if(iCntz < len)
printf("%02X ", *p);
else
printf("00 ");
++p;
++iCntz;
}
p -= 16;
iCntz -= 16;

for(iCnty = 0; iCnty < 16; ++iCnty)
{
if((0x21 <= *p) && (0x7E >= *p) && (iCntz < len))
printf("%c", *p);
else
printf(".");
++p;
}
putchar('\n');
addr += 16;
}
}

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.