본문 바로가기

리눅스 커널/네트워크

Ethernet & ARP Header

첫번째는 이더넷 헤더이다.

#include <linux/if_ether.h>

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

h_dest: 도착지 MAC주소

h_source: 출발지 MAC주소

h_proto: 상위 계층 헤더의 프로토콜

다음은 ARP 헤더이다.

#include <linux/if_arp.h>

struct arphdr {
	__be16		ar_hrd;		/* format of hardware address	*/
	__be16		ar_pro;		/* format of protocol address	*/
	unsigned char	ar_hln;		/* length of hardware address	*/
	unsigned char	ar_pln;		/* length of protocol address	*/
	__be16		ar_op;		/* ARP opcode (command)		*/

#if 0
	 /*
	  *	 Ethernet looks like this : This bit is variable sized however...
	  */
	unsigned char		ar_sha[ETH_ALEN];	/* sender hardware address	*/
	unsigned char		ar_sip[4];		/* sender IP address		*/
	unsigned char		ar_tha[ETH_ALEN];	/* target hardware address	*/
	unsigned char		ar_tip[4];		/* target IP address		*/
#endif

};

ar_hrd: 1 이면 이더넷

ar_pro: 0x0800 이면 IPv4 

ar_hln: 하드웨어 주소 길이(이더넷인 경우 6)

ar_pln: 프로토콜 주소 길이(IPv4인 경우 4)

ar_op: 1 이면 요청, 2 이면 응답

 

이 후 필드는 포인터를 옮겨 가며 접근 할 수 있다.



'리눅스 커널 > 네트워크' 카테고리의 다른 글

Raw socket outgoing packet capture  (0) 2021.10.24
Raw socket incoming packet capture  (0) 2021.10.24
IP & ICMP Header  (0) 2021.10.24
TCP & UDP Header  (0) 2021.10.24
ioctl - socket  (0) 2021.10.24