UDP ÀÀ´ä½Ã°£ üũÇϱâ.
ÃÑ ÆäÀÌÁö ¼ö : 3224

Àüü ÇÔ¼ö/¿ë¾î»çÀü
Facebook Joinc ±×·ì   Joinc QA »çÀÌÆ®



joinc´Â Firefox¿Í chrome¿¡¼­ Å×½ºÆ® Çß½À´Ï´Ù. IE¿¡¼­´Â Å×À̺íÀÌ ±úÁö°Å³ª À̹ÌÁö°¡ º¸ÀÌÁö ¾ÊÀ» ¼ö ÀÖ½À´Ï´Ù. ƯÈ÷ ±¸±Û DocsÀ̹ÌÁöÀÇ °æ¿ì ¿¢¹Úó¸®µÉ ¼ö ÀÖ½À´Ï´Ù.

À̱ÛÀº TCP, IP, UDP ±×¸®°í libpcap¿¡ ´ëÇÑ ³»¿ëÀ» ¾Ë°í ÀÖÀ» °ÍÀ̶ó´Â °¡Á¤ÇÏ¿¡ ÀÛ¼ºµÇ¾ú´Ù.

TCP ÇÁ·ÎÅäÄݰú´Â ´Þ¸® UDP ÇÁ·ÎÅäÄÝÀº º°µµÀÇ ¿¬°á°úÁ¤À» °ÅÄ¡Áö ¾Ê°í, ±×³É µ¥ÀÌÅ͸¦ Àü¼ÛÇÏ°í ¹Þ´Â´Ù. ¶ÇÇÑ È帧Á¦¾î¸¦ À§ÇÑ SQE ACK, ACK¸¦ °¡ÁöÁö ¾Ê´Â´Ù. ±×·¯¹Ç·Î ´ÜÁö Src IP, Src Port, Dst IP, Dst Port ¸¸À» °¡Áö°í ÀÀ´ä½Ã°£À» Ã¼Å©ÇØ¾ßÇÑ´Ù. pcap ¶óÀ̺귯¸®¸¦ ÀÌ¿ëÇÏ¸é ´ÙÀ½°ú °°ÀÌ °£´ÜÇÏ°Ô UDP ÆÐŶÀÇ Á¤º¸¸¦ ¾ò¾î¿À´Â ÇÁ·Î±×·¥À» ¸¸µé ¼ö ÀÖ´Ù.

#ifdef HAVE_CONFIG_H 
#include <config.h> 
#endif 
 
// Unix Standard Library 
#include <time.h> 
#include <unistd.h> 
#include <stdlib.h> 
 
#include <iostream> 
 
#include <pcap.h> 
 
#include <net/bpf.h> 
#include <netinet/in.h> 
 
#include <stdio.h> 
#include <stdlib.h> 
 
#include <netinet/ip.h> 
#include <netinet/tcp.h> 
#include <netinet/udp.h> 
#include <netinet/if_ether.h> 
#include <netinet/in.h> 
 
#include <net/if.h> 
#include <net/ethernet.h> 
#include <arpa/inet.h> 
 
#include <sys/socket.h> 
 
 
#define TCPHEADERSIZE 6*4 
 
using namespace std; 
 
enum MODE{NONPROMISCUOUS, PROMISCOUS}; 
 
struct _connect_Info 
{ 
  struct timeval start_Time; 
  int flag; 
}; 
 
int main(int argc, char *argv[]) 
{ 
  char errbuf[256]; 
  int ret; 
  struct _connect_Info  *connect_Info; 
 
  bpf_u_int32 netp; 
  bpf_u_int32 maskp; 
 
  char *dev; 
 
  struct pcap_pkthdr hdr; 
  struct ether_header *ep; 
  struct tcphdr    *tcph; 
  struct udphdr    *udph; 
  struct ip *iph; 
 
  struct timeval current_time; 
 
  struct sockaddr_in *sin; 
 
  const u_char *packet; 
 
  unsigned short ether_type; 
  pcap_t *pcd; 
 
  // 65536°³ ¸¸Å­ÀÇ Src Port¸¦ ÀúÀåÇÒ ¼ö ÀÖ´Â ÀÚ·á°ø°£À» ¸¸µç´Ù. 
  connect_Info = (struct _connect_Info *)malloc(sizeof(struct _connect_Info) * 65536); 
 
  dev = pcap_lookupdev(errbuf); 
  if (dev == NULL) 
  { 
    printf("%s\n", errbuf); 
    return 1; 
  } 
 
  // Non Promiscous ¸ðµå·Î ÀÌ´õ³Ý ÀåÄ¡¸¦ ¿¬´Ù. 
  pcd = pcap_open_live(dev, BUFSIZ, NONPROMISCUOUS, -1, errbuf); 
  if (pcd == NULL) 
  { 
    printf("%s\n", errbuf); 
    return 1; 
  } 
 
  // ÆÐŶÀ» ÀоîµéÀδÙ. 
  for (;packet=(const unsigned char *)pcap_next(pcd, &hdr);) 
  { 
    ep = (struct ether_header *)packet; 
    packet += sizeof(struct ether_header); 
    ether_type = ntohs(ep->ether_type); 
    // UDP/IP ÆÐŶÀÎ °æ¿ì¿¡¸¸ ºÐ¼®ÇÑ´Ù. 
    if (ether_type == ETHERTYPE_IP) 
    { 
      iph = (struct ip *)packet; 
      if(iph->ip_p == IPPROTO_UDP) 
      { 
        udph = (struct udphdr *)(packet + iph->ip_hl *4); 
        printf("%16s(%06d) -> %16s(%d06) : %d, %d\n", 
              inet_ntoa(iph->ip_src), 
              ntohs(udph->source), 
              inet_ntoa(iph->ip_dst), 
              ntohs(udph->dest), 
              ntohs(udph->len), 
              ntohs(iph->ip_id)); 
      } 
    } 
  } 
  return EXIT_SUCCESS; 
} 
 

´ÙÀ½Àº ½ÇÇà½ÃŲ °á°ú´Ù.
# ./pcap 
  218.234.17.184(000138) ->   218.234.17.184(13806) : 200, 264 
  218.234.17.196(000138) ->   218.234.17.196(13806) : 182, 27542 
  218.234.17.196(000137) ->   218.234.17.196(13706) : 58, 27543 
  218.234.17.194(000138) ->   218.234.17.194(13806) : 209, 265 
  218.234.17.184(000138) ->   218.234.17.184(13806) : 209, 266 
  218.234.17.225(000138) ->   218.234.17.225(13806) : 182, 5887 
  218.234.17.225(000137) ->   218.234.17.225(13706) : 58, 5888 
  218.234.17.196(000137) ->   218.234.17.196(13706) : 58, 27545 
  218.234.17.227(000138) ->   218.234.17.227(13806) : 182, 19602 
  218.234.17.227(000137) ->   218.234.17.227(13706) : 58, 19603 
 
ÀÌÁ¦ gettimeofday(2) ÇÔ¼ö¸¦ ÀÌ¿ëÇϸé, ½±°Ô ÀÀ´ä½Ã°£À» ±¸ÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù. ÀÌ·¯ÇÑ Á¤º¸´Â ¼­ºñ½ºÀÇ Ç°ÁúÀ» ³ôÀ̱â À§ÇÑ QOS ½Ã½ºÅ۵ À¯¿ëÇÏ°Ô È°¿ëÇÒ ¼ö ÀÖÀ» °ÍÀÌ´Ù.

°ü·Ã±Û

EmailÀ» ±âÀÔÇϸé, ´ñ±ÛÀÌ ¸ÞÀÏ·Î Àü´ÞµË´Ï´Ù.