我需要在 linux 内核空间中将 char[] 转换为 __be16 类型。
我可以使用 kstrtoint
将 char[] 转换为 int。同样的功能也适用于 __be16,但有警告。同样,任何预定义函数也可用于 __be16 吗?
示例:
char x[120] = "02"到 __be16 xx
最佳答案
__be16
实际上是一个network short int
,所以可以使用htons
函数:
char* str = "123"; // input
int val;
__be16 nval; // output
kstrtoint(str, 10, &val);
nval = htons(val);
此外,cpu_to_be16
可以用来代替 htons
。
关于linux - 在 linux 内核空间中将 char[] 转换为 __be16 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32346795/