LoginSignup
1
1

More than 1 year has passed since last update.

Dockerネットワークで遊ぶ_その3_ARP,IP,ICMP編

Last updated at Posted at 2023-05-07

はじめに

前回記事では、イーサネットフレームの外側を見た
今回はARP, IP, ICMPパケットの中身をみる

連載情報

連載 内容
その1 〈実践〉同じセグメント内のPING疎通確認
その2 〈コード〉イーサネットヘッダの中身をみてみる
その3 〈コード〉ARP,IP,ICMPの中身をみてみる
その4 〈実践〉IP,TCPをキャプチャする
その5 〈実践)ルーターを準備する
その6 〈実践〉別セグメントのWEBへアクセスをする

ARPパケットのフォーマット

ARPパケットフォーマット

cat /usr/include/net/if_arp.h
/* ARP protocol opcodes. */
#define ARPOP_REQUEST   1               /* ARP request.  */
#define ARPOP_REPLY     2               /* ARP reply.  */

struct arphdr
  {
    unsigned short int ar_hrd;          /* Format of hardware address.  */
    unsigned short int ar_pro;          /* Format of protocol address.  */
    unsigned char ar_hln;               /* Length of hardware address.  */
    unsigned char ar_pln;               /* Length of protocol address.  */
    unsigned short int ar_op;           /* ARP opcode (command).  */
  };

/* ARP protocol HARDWARE identifiers. */
#define ARPHRD_ETHER    1               /* Ethernet 10/100Mbps.  */
  • ハードウェアアドレスはMACアドレス
    • 物理アドレスとも言う
  • プロトコルアドレスはIPアドレス
  • unsigned charは1byte, unsigned short intは2byte
cat /usr/include/netinet/if_ether.h
#include <net/if_arp.h>

struct  ether_arp {
        struct  arphdr ea_hdr;          /* fixed-size header */
        uint8_t arp_sha[ETH_ALEN];      /* sender hardware address */
        uint8_t arp_spa[4];             /* sender protocol address */
        uint8_t arp_tha[ETH_ALEN];      /* target hardware address */
        uint8_t arp_tpa[4];             /* target protocol address */
};
  • structの中の1行目でarphdr(ARPヘッダー)が書かれている
  • 続いて送信元と宛先それぞれのMACアドレス、プロトコルアドレス(=IPアドレス)が書かれている

IPパケット

IPパケット - ネットワーク入門サイト

ip構造体にTTLや送信元・宛先の32bitが書かれている

cat /usr/include/netinet/ip.h
struct ip
  {
    uint8_t ip_tos;                     /* type of service */
    unsigned short ip_len;              /* total length */
    unsigned short ip_id;               /* identification */
    unsigned short ip_off;              /* fragment offset field */
#define IP_RF 0x8000                    /* reserved fragment flag */
#define IP_DF 0x4000                    /* dont fragment flag */
#define IP_MF 0x2000                    /* more fragments flag */
#define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
    uint8_t ip_ttl;                     /* time to live */
    uint8_t ip_p;                       /* protocol */
    unsigned short ip_sum;              /* checksum */
    struct in_addr ip_src, ip_dst;      /* source and dest address */
  };

#define IPVERSION       4               /* IP version number */
#define IP_MAXPACKET    65535           /* maximum packet size */

/*
 * Internet implementation parameters.
 */
#define MAXTTL          255             /* maximum time to live (seconds) */
#define IPDEFTTL        64              /* default ttl, from RFC 1340 */

ICMPパケット

ネットワーク入門サイト - ICMP

cat /usr/include/netinet/ip_icmp.h
#include <stdint.h>

struct icmphdr
{
  uint8_t type;         /* message type */
  uint8_t code;         /* type sub-code */
  uint16_t checksum;
};

#define ICMP_ECHOREPLY          0       /* Echo Reply                   */
#define ICMP_DEST_UNREACH       3       /* Destination Unreachable      */
#define ICMP_REDIRECT           5       /* Redirect (change route)      */
#define ICMP_ECHO               8       /* Echo Request                 */

糸冬了!!

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1