且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Linux内核中的时间戳错误?

更新时间:2022-12-18 09:24:46

sk_buff->tstampktime_t类型的变量. do_gettimeofday将时间设置为struct timeval的变量.您在这里有不同的类型,因此需要进行转换.一个简单的例子是:

sk_buff->tstamp is variable of ktime_t type. do_gettimeofday sets time to variable of struct timeval. You have different types here and so you need a conversion. A simple one would be:

int netif_rx(struct sk_buff *skb) 
{
    if(skb -> tstamp.off_sec ==0)
    {
        struct timespec now;
        getnstimeofday(&now);
        skb->tstamp = timespec_to_ktime(now);
    }
}

修改: 如果您只想为套接字缓冲区添加时间戳,则可以调用 __net_timestamp

If you just want to timestamp socket buffer you can call __net_timestamp

int netif_rx(struct sk_buff *skb) 
{
    __net_timestamp(skb);
}

或者,如果您不能拨打__net_timestamp,也可以手动进行:

Or if you can't call __net_timestamp you can do it by your hands:

int netif_rx(struct sk_buff *skb) 
{
    skb->tstamp = ktime_get_real();
}