gpt4 book ai didi

C: ether_aton 不起作用

转载 作者:行者123 更新时间:2023-11-30 15:08:46 26 4
gpt4 key购买 nike

我有以下功能:

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com