libpcap을 이용하여 send packet 만드는데요..

woojisung의 이미지

libpcap을 이용하여 send packet을 만들려고합니다..
winpcap을 응용하여 리눅스 CentOS5에서 libpcap으로

소스를 건드려가면서 하는중인데요...
일단 ARP를 타겟 IP에 보내서 그 타겟 IP가 맥주소를 response
해주면 성공입니다..

지금까지 짠 소스는 이정도인데.. 소스 정리와 추가할것좀 알려주세요.
주석달아주시면서 간단한 설명도 첨부해주시면 감사하겠습니다..
그리고 ARP말고도 IP,TCP등등의 것들의 소스도 올려주시면 감사하겠습니다.

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define PROMISCUOUS 1
#define NONPROMISCUOUS 0

void main(int argc, char **argv)
{
pcap_t *fp;
char errbuf[PCAP_ERRBUF_SIZE];
u_char packet[100];
char *dev;
int i;

dev = pcap_lookupdev(errbuf);

if( dev == NULL )
{
printf("%s\n", errbuf);
exit(1);
}

if(argc !=2)
{

printf("usage : %s interface (e.g. 'rpcap://eth0')", argv[0]);
return;
}

if ( (fp = pcap_open_live(dev, BUFSIZ, NONPROMISCUOUS, 0, errbuf)) == NULL)
{
printf(stderr, "Unable to open the Adapter.%s is not supported by Libpcap ", argv[1]);
return;
}

/* Supposing to be on ethernet, set mac destination to */
packet[0] = 0xFF;
packet[1] = 0xFF;
packet[2] = 0xFF;
packet[3] = 0xFF;
packet[4] = 0xFF;
packet[5] = 0xFF;

/* set mac source to */
packet[6] = 0x00;
packet[7] = 0x11;
packet[8] = 0x22;
packet[9] = 0x33;
packet[10] = 0x44;
packet[11] = 0x55;

/* ARP */
packet[12] = 0x08;
packet[13] = 0x06;

/* Hardware Type (ethernet) */
packet[14] = 0x00;
packet[15] = 0x01;

/* protocol type(ip) */
packet[16] = 0x08;
packet[17] = 0x00;

/* Hardware Length */
packet[18] = 0x06;

/* Protocol Length */
packet[19] = 0x04;

/* Operation (request :1, reply : 2) */
packet[20] = 0x01;
packet[21] = 0x02;

/* Sender Hardware Address */
packet[22] = 0x00;
packet[23] = 0x0C;
packet[24] = 0x29;
packet[25] = 0x71;
packet[26] = 0x4C;
packet[27] = 0x2D;

/* Sender Protocol Address */
packet[28] = 0xC0;
packet[29] = 0xA8;
packet[30] = 0xF7;
packet[31] = 0x82;

/* Target Hardware Address (Empty) */
packet[32] = 0xFF;
packet[33] = 0xFF;
packet[34] = 0xFF;
packet[35] = 0xFF;
packet[36] = 0xFF;
packet[37] = 0xFF;
/*
packet[32] = 0x00;
packet[33] = 0x0E;
packet[34] = 0xE8;
packet[35] = 0xE8;
packet[36] = 0xEC;
packet[37] = 0x5E;
*/
/* Target Protocol Address */
packet[38] = 0xC0;
packet[39] = 0xA8;
packet[40] = 0x00;
packet[41] = 0x04;

/* file the rest of the packet */
for( i=12 ; i<100 ; i++ )
{
packet[i] = i%256;
}

if (pcap_sendpacket(fp, packet, 100 /* size */ ) != 0 )
{
printf(stderr, "\nError sending the packet: \n", pcap_geterr(fp));
return;
}
return;
}

powerson의 이미지

winpcap에서는 지원하는 걸로 알고 있지만, linux의 libpcap에서는 packet을 sending 하는 것을 지원하지 않는 걸로 알고 있습니다. 혹시 최신버전에서는 지원하는 건가요? 그래서 libnet을 이용해서 packet sending 하는 걸로 알고 있습니다만..

------------------------------------------------------
아직은 젊다. 모든 것을 할 수 있는 나이란 말이지.

------------------------------------------------------
아직은 젊다. 모든 것을 할 수 있는 나이란 말이지.