Conversion of Ethernet address to readable form?

前端 未结 3 563
鱼传尺愫
鱼传尺愫 2021-01-27 03:33
struct ethernet_header
{
    u_char ether_dhost[ ETHER_ADDR_LEN];

    u_char ether_shost[ETHER_ADDR_LEN];

    u_short ether_type;
};

for(i = 0;i <6; i++)
  printf(         


        
3条回答
  •  逝去的感伤
    2021-01-27 03:43

    How about:

    printf("%02x:%02x:%02x:%02x:%02x:%02x",
        (unsigned)ethernet->ether_dhost[0],
        (unsigned)ethernet->ether_dhost[1],
        (unsigned)ethernet->ether_dhost[2],
        (unsigned)ethernet->ether_dhost[3],
        (unsigned)ethernet->ether_dhost[4],
        (unsigned)ethernet->ether_dhost[5]);
    

提交回复
热议问题