C: ether_aton 不起作用

标签 c ethernet

我有以下功能:

int parse_mac(const char *hwaddr, uint8_t *dst_mac)
{
    (void)hwaddr; (void)dst_mac;

    //TODO: Parse the MAC address (string) pointed to by hwaddr and store
    //the result in dst. Return 0 on success and -1 on error.

    struct ether_addr* ether_address = ether_aton(hwaddr);
    if(ether_address==NULL){
        return -1;
    }
    int i;
    for(i=0;i<6;i++){
        //*(dst_mac+i) = (*ether_address).ether_addr_octet[i];
    }
    printf("%c\n",(*ether_address).ether_addr_octet[0]);

    return 0;
}

给定一个 MAC 地址(由 hwaddr 指向),我想通过 ether_aton 将其转换为我的 dst_mac 变量。然而,ether_address 结果结构中的数组是空的,或者看起来是这样。例如,底部的 printf 给了我一个空字符。怎么了?

最佳答案

基本上,ether_aton 会将您的 MAC 地址(由冒号分隔的十六进制字符)转换为数字。在我的代码中,我试图打印 %c,而我应该打印 %d。

关于C: ether_aton 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37166834/

相关文章:

c++ - 从表中提取用户数据,使用 lua c API

c++ - 使用 ctypes 向 C/C++ 库提供函数的外部定义

c# - 如何在 .NET 中检测通过串行端口或以太网连接的设备状态的变化

linux - 如何提取以太网 II 帧的有效载荷/数据?

c++ - ioctl(sock, SIOCETHTOOL, &ifr) 为什么一直返回-1

powershell - 如果尚未启用 VLAN,请启用 VLAN 并使用 powershell 脚本设置 VLAN ID

c++ - OpenGL Nvidia 驱动程序 259.12 纹理不工作

javascript - JavaScript 中的无符号字符

c - 在一次解析中解析大文件以获取某些信息

android - 如何知道 Android 是连接到 WiFi 还是以太网?