ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • Ethernet, IP, TCP, UDP Frame
    통신/TCP_IP 2014. 10. 15. 14:23

    ------- Ethernet과 IP, TCP, UDP Header









    ------- Ethernet Frame


    Ethernet frame은 다음과 같이 몇몇 타입이 있다.

    - Ethernet II

    - IEEE 802.3

    - IEEE 802.2 Logical Link Control (LLC) frame

    - IEEE 802.2 Subnetwork Access Protocol (SNAP) frame



    --- Ethernet II


    DEC, Intel, and Xerox에 의해 만들어졌으며,

    DIX Ethernet 이라고도 불린다


    첫 번째 필드엔 목적 MAC주소, 

    두 번재 필드엔 보낸 MAC주소,

    세 번째 필드엔 Ether type이라고 Ethernet 프로토콜 타입,

    네 번째 필드엔 정보,

    다섯 번째 필드엔 CRC(cyclic redundancy check) 또는 FCS(Frame Check Sequence)라고

    오류 검출에 쓰인다.


    (출처 : http://en.wikipedia.org/wiki/Ethernet_frame)






    --- IEEE 802.3


    Novell 사에서 IPX protocol용으로 만들어졌다.

    Ethernet II와 흡사한 구조로 세 번재 필드인 EtherType 대신 Length 이다.







    --- IEEE 802.2 Logical Link Control (LLC) frame


    OSI 계층 구조에서만 사용하는 Frame으로 거의 사용하지 않는다.

    토큰링이 이 구조를 사용한다.







    --- IEEE 802.2 Subnetwork Access Protocol (SNAP) frame


    OSI 계층 구조에서 사용한다. TCP/IP가 주류므로 OSI는 잘 사용하지 않는다.

    AppleTalk이 이 구조를 사용한다.









    --- IEEE 802.1Q tag

    VLAN (virtual local area network) 서비스에 대한 규약으로 Ethernet frame 들에 포함하고 있는데,

    데이타 링크 계층(TCP/IP) or 네트워킹 계층(OSI)인 라우터나 스위치 등에서 운영되는 것으로,

    브로드캐스트 필터링, 보안, 주소 축약, 트래픽 흐름 관리, QoS 등에 사용된다고 한다.


    VLAN은 Ethernet frame에 Source Address 와 EtherType 또는 Length fields 사이에 위치하고 있거나,

    EtherType 또는 Length fields 에 위치하고 있다.

    처음 2 byte (2 octets)에는 Tag Protocol Identifier (TPID) 값이 0x8100으로 되어 있다.









    ------- Ethernet Frame 구조체


    linux 환경

    /usr/include/linux/if_ether.h

    /usr/include/net/ethernet.h

    위치에서 확인할 수 있다




    struct ethhdr { unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ unsigned char h_source[ETH_ALEN]; /* source ether addr */ unsigned short h_proto; /* packet type ID field */ };



    struct ether_header { u_int8_t ether_dhost[ETH_ALEN]; /* destination eth addr */ u_int8_t ether_shost[ETH_ALEN]; /* source ether addr */ u_int16_t ether_type; /* packet type ID field */ };





    --- 데이터 타입은

    /usr/include/i386-linux-gnu/sys/types.h 에 있다.





    --- ETH_ALEN 값은

    /usr/include/linux/if_ether.h 에 있다.






    --- type의 종류는

    /usr/include/net/ethernet.h 에 있다.

    더 많은 type은 /usr/include/linux/if_ether.h를 참고...














    ------- IP Header 구조체


    http://en.wikipedia.org/wiki/IPv4 참고


    /usr/include/netinet/in.h 에 프로토콜에 타입

    /usr/include/netinet/ip.h 에 IP구조체가 정의 되어 있다



    struct iphdr

    {

    #if __BYTE_ORDER == __LITTLE_ENDIAN

    unsigned int  ihl:4;        //헤더 길이

    unsigned int version:4;        //IP version 4

    #elif __BYTE_ORDER == __BIG_ENDIAN

    unsigned int version:4;        //IP version 4

    unsigned int  ihl:4;        //헤더 길이

    #else

    # error "Please fix <bits/endian.h>"

    #endif

    u_int8_t    tos;

    u_int16_t    tot_len;

    u_int16_t    id;

    u_int16_t    frag_off;

    u_int8_t    ttl;

    u_int8_t    protocol;

    u_int16_t    check;

    u_int32_t    saddr;

    u_int32_t    daddr;

    /* The options start here. */

    };







    ------- TCP Header 구조체



    /usr/include/netinet/tcp.h

    /usr/include/linux/tcp.h

    에 위치해 있다.


    struct tcphdr

    {

    u_int16_t    source;        //source port

    u_int16_t    dest;        //destination port

    u_int32_t    seq;          //sequence number

    u_int32_t    ack_seq;          //acknowledgement number

    #if __BYTE_ORDER == __LITTLE_ENDIAN

    u_int16_t    res1:4;           //(unused)

    u_int16_t    doff::4;           //data offset

    u_int16_t    fin:1;

    u_int16_t    syn:1;

    u_int16_t    rst:1;

    u_int16_t    psh:1;

    u_int16_t    ack:1;

    u_int16_t    urg:1;

    u_int16_t    res2:2;

    #elif __BYTE_ORDER == __BIG_ENDIAN

    u_int16_t    doff::4;           //data offset

    u_int16_t    res1:4;           //(unused)

    u_int16_t    res2:2;           //(unused)

    u_int16_t    urg:1;

    u_int16_t    ack:1;

    u_int16_t    psh:1;

    u_int16_t    rst:1;

    u_int16_t    syn:1;

    u_int16_t    fin:1;

    #else

    #error "Adust your <bits/endian.h> defines"

    #endif

    u_int16_t    window;        //window

    u_int16_t    check;       //checksum

    u_int16_t    urg_ptr;        //urgent pointer

    };














    '통신 > TCP_IP' 카테고리의 다른 글

    HTTP 3핸드 쉐이킹 캡쳐  (0) 2020.10.12
    TCP/IP 4 계층  (0) 2014.10.15
Designed by Tistory.