==========================================================================================

NETWORK

==========================================================================================




<NETWORK>



=TCP 







=

http://www.ktword.co.kr/abbr_view.php?nav=&m_temp1=2437&id=1103


. CODE BITS
  URG (1 bit) – URGENT POINTER 필드가 유효
  ACK (1 bit) – ACKNOWLEDGMENT필드를 유효
  PSH (1 bit) – 세그먼트 PUSH를 요청
  RST (1 bit) – 즉시 연결을 끊음(비정상적인 종료)
  SYN (1 bit) – sequence numbers 동기화
  FIN   (1 bit) – 정상적인 종료



<NETWORK>



=TCP 







=

http://www.ktword.co.kr/abbr_view.php?nav=&m_temp1=2437&id=1103


. CODE BITS
  URG (1 bit) – URGENT POINTER 필드가 유효
  ACK (1 bit) – ACKNOWLEDGMENT필드를 유효
  PSH (1 bit) – 세그먼트 PUSH를 요청
  RST (1 bit) – 즉시 연결을 끊음(비정상적인 종료)
  SYN (1 bit) – sequence numbers 동기화
  FIN   (1 bit) – 정상적인 종료


<PACKET.C>

#include <stdio.h>
#include <netinet/in.h>
#include <pcap/pcap.h>
#include <net/ethernet.h>
#include <arpa/inet.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>

#define PORT 7777

int main(void)
{
  char*           cpNICName;
  char           caErrMSG[PCAP_ERRBUF_SIZE];
  int           iCnt;
  unsigned char const *   ucpData;
  pcap_t*         stpDS;
  struct pcap_pkthdr     stInfo;
  struct tcphdr *     stTcp;
  struct ip *        stpIp;  


  cpNICName = pcap_lookupdev(caErrMSG);

  if(0 == cpNICName)
  {
    printf("ERRMSG  : [%s]\n",caErrMSG);
    return 100;
  }

  stpDS = pcap_open_live(cpNICName, ETH_DATA_LEN, 10, caErrMSG);

  printf("Packet Monitoring Start....\n");
  getchar();

  while(1)
  {
    ucpData = pcap_next(stpDS, &stInfo);

    if(ETH_P_IP != ntohs(*(unsigned short*)(ucpData+12))) // 2byte 주소
    {
      continue;
    }

    if(IPPROTO_TCP != *(ucpData+23))
    {
      continue;
    }
  

    stpIp = (struct ip *) (ucpData + sizeof(struct ether_header));
    stTcp = (struct tcphdr *)(ucpData + sizeof(struct ether_header) 
        + ((*(ucpData+ sizeof(struct ether_header)) & 0x0F) * 4));

    if(PORT != ntohs(stTcp -> source))
    {
      if(PORT != ntohs(stTcp -> dest))
      {
        continue;
      }
    }
    printf("===================================================\n");
    printf("[%s:%d] ---> ",
        inet_ntoa(stpIp -> ip_src)
        , ntohs(stTcp -> source)
        );

    printf("[%s:%d]\n",
        inet_ntoa(stpIp -> ip_dst)
        , ntohs(stTcp -> dest)
        );

    printf("SYN[%d] ACK[%d] FIN[%d] Seq[%010u] Ack[%010u]\n"
        , stTcp -> syn
        , stTcp -> ack
        , stTcp -> fin
        , ntohl(stTcp -> seq)
        , ntohl(stTcp -> ack_seq)
        );
  }

  pcap_close(stpDS);

  return 0;
}



=CLIENT

















=CLIENT











= 연결


-3-way handshake








= 종료

( 소스 : SERVER에서 먼저 CLOSE() 호출 )






-FIN









=채팅



-스레드


-client : read() (키입력)- blocking 상태에서 server에서 패킷 보내면 문제생김(못받음)



1. 멀티프로세스

2. 멀티스레드

3. 입력다중화


=멀티프로세스

-과거 ( singlecore - 동시 실행 X )

-현재 ( dualcore이상 - 동시 실행 O )



=fork


<FORK.C>


#include <stdio.h>
#include <unistd.h>
#include <errno.h>

int main()
{
    
int iNum;

    iNum 
= fork(); // 호출한 순간 2개가 됨 ( 자식 iNum== 0 |  부모 iNum>0)
    if(0 > iNum)
    {
        perror(
"fork() fail :");
        
return 1;
    }
    
if(0 == iNum)
    {
        printf(
"CHILD PROCESS\n");
        getchar();
        printf(
"자식프로세스 종료 직전\n");
    }
    
else
    {
        printf(
"PARENT PROCESS\n");
        getchar();
        printf(
"부모프로세스 종료 직전\n");
    }
    
return 0;
}



-PROCESS IDENTIFY


ps -aux | grep fork


| - 파이프 ( 왼쪽결과를 오른쪽으로 넘겨줌)











=키보드









=키보드 입력











=execl : exe실행



=클라이언트 2개 ( 받기 | 보내기 )



=CLIENT

















=CLIENT











= 연결


-3-way handshake








= 종료

( 소스 : SERVER에서 먼저 CLOSE() 호출 )






-FIN









=채팅



-스레드


-client : read() (키입력)- blocking 상태에서 server에서 패킷 보내면 문제생김(못받음)



1. 멀티프로세스

2. 멀티스레드

3. 입력다중화


=멀티프로세스

-과거 ( singlecore - 동시 실행 X )

-현재 ( dualcore이상 - 동시 실행 O )



=fork


<FORK.C>


#include <stdio.h>
#include <unistd.h>
#include <errno.h>

int main()
{
    
int iNum;

    iNum 
= fork(); // 호출한 순간 2개가 됨 ( 자식 iNum== 0 |  부모 iNum>0)
    if(0 > iNum)
    {
        perror(
"fork() fail :");
        
return 1;
    }
    
if(0 == iNum)
    {
        printf(
"CHILD PROCESS\n");
        getchar();
        printf(
"자식프로세스 종료 직전\n");
    }
    
else
    {
        printf(
"PARENT PROCESS\n");
        getchar();
        printf(
"부모프로세스 종료 직전\n");
    }
    
return 0;
}



-PROCESS IDENTIFY


ps -aux | grep fork


| - 파이프 ( 왼쪽결과를 오른쪽으로 넘겨줌)











=키보드









=키보드 입력











=execl : exe실행



=클라이언트 2개 ( 받기 | 보내기 )








'2015 스마트 콘트롤러 > 업무일지' 카테고리의 다른 글

20150728  (0) 2015.07.28
20150727  (0) 2015.07.27
20150723  (0) 2015.07.23
20150722  (0) 2015.07.23
20150721  (0) 2015.07.22
Posted by ahj333
,