Changeset d0fd73c


Ignore:
Timestamp:
08/28/06 14:28:16 (14 years ago)
Author:
Perry Lorier <perry@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
5593016
Parents:
9d6b5cd
Message:

Author: Tom Young

Here is a patch to use the control message block, rather than the ioctl for
getting the time stamp. It seems to work for me. As far as i can tell, the
control block stuff has been used for ages (it looked like it was in 2.4.24)
but it should fall back to the ioctl anyway if it has to.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_linux.c

    r85a79b0 rd0fd73c  
    4949#include <net/if.h>
    5050#include <sys/ioctl.h>
     51#include <errno.h>
    5152
    5253struct libtrace_format_data_t {
     
    9394{
    9495        struct sockaddr_ll addr;
     96        int one = 1;
    9597        memset(&addr,0,sizeof(addr));
    9698        FORMAT(libtrace->format_data)->fd =
     
    132134                                socklen);
    133135        }
     136
     137        setsockopt(FORMAT(libtrace->format_data)->fd,
     138                        SOL_SOCKET,
     139                        SO_TIMESTAMP,
     140                        &one,
     141                        sizeof(one));
    134142
    135143        return 0;
     
    202210#define LIBTRACE_MIN(a,b) ((a)<(b) ? (a) : (b))
    203211
     212/* 20 should be enough */
     213#define CMSG_BUF_SIZE 20
    204214static int linuxnative_read_packet(libtrace_t *libtrace, libtrace_packet_t *packet)
    205215{
    206216        struct libtrace_linuxnative_header *hdr;
     217        struct msghdr msghdr;
     218        struct iovec iovec;
     219        unsigned char controlbuf[CMSG_BUF_SIZE];
     220        struct cmsghdr *cmsg;
    207221        socklen_t socklen;
    208222        int snaplen;
     223
    209224        if (!packet->buffer || packet->buf_control == TRACE_CTRL_EXTERNAL) {
    210225                packet->buffer = malloc(LIBTRACE_PACKET_BUFSIZE);
     
    221236                        (int)LIBTRACE_PACKET_BUFSIZE-(int)sizeof(*hdr),
    222237                        (int)FORMAT(libtrace->format_data)->snaplen);
    223         hdr->wirelen = recvfrom(FORMAT(libtrace->format_data)->fd,
    224                         (void*)packet->payload,
    225                         snaplen,
    226                         MSG_TRUNC,
    227                         (struct sockaddr *)&hdr->hdr,
    228                         &socklen);
    229 
    230         if (hdr->wirelen==-1)
     238
     239        msghdr.msg_name = &hdr->hdr;
     240        msghdr.msg_namelen = sizeof(struct sockaddr_ll);
     241
     242        msghdr.msg_iov = &iovec;
     243        msghdr.msg_iovlen = 1;
     244
     245        msghdr.msg_control = &controlbuf;
     246        msghdr.msg_controllen = CMSG_BUF_SIZE;
     247        msghdr.msg_flags = 0;
     248
     249        iovec.iov_base = (void*)packet->payload;
     250        iovec.iov_len = snaplen;
     251
     252        hdr->wirelen = recvmsg(FORMAT(libtrace->format_data)->fd, &msghdr, 0);
     253
     254        if (hdr->wirelen==-1) {
     255                trace_set_err(libtrace,errno,"recvmsg");
    231256                return -1;
     257        }
    232258
    233259        hdr->caplen=LIBTRACE_MIN(snaplen,hdr->wirelen);
    234260
    235         if (ioctl(FORMAT(libtrace->format_data)->fd,SIOCGSTAMP,&hdr->ts)==-1)
     261        for (cmsg = CMSG_FIRSTHDR(&msghdr);
     262                        cmsg != NULL;
     263                        cmsg = CMSG_NXTHDR(&msghdr, cmsg)) {
     264                if (cmsg->cmsg_level == SOL_SOCKET
     265                        && cmsg->cmsg_type == SO_TIMESTAMP
     266                        && cmsg->cmsg_len == CMSG_LEN(sizeof(struct timeval))) {
     267                        memcpy(&hdr->ts, CMSG_DATA(cmsg),
     268                                        sizeof(struct timeval));
     269                        break;
     270                }
     271        }
     272
     273        if (cmsg == NULL && ioctl(FORMAT(libtrace->format_data)->fd,
     274                                SIOCGSTAMP,&hdr->ts)==-1)
    236275                perror("ioctl(SIOCGSTAMP)");
    237276
Note: See TracChangeset for help on using the changeset viewer.