Conversion of Ethernet address to readable form?

前端 未结 3 558
鱼传尺愫
鱼传尺愫 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:54

    I think the best way would be to use ether_ntoa() which is available on just about any *nix operating system (available in net/ethernet.h). The following works quite well for me.

    char *addr;
    struct ether_addr host;
    
    memcpy(&host, ethernet->ether_dhost, sizeof(host));
    addr = ether_ntoa(&host);
    

提交回复
热议问题