Changeset a984307 for lib


Ignore:
Timestamp:
07/20/16 16:01:58 (5 years ago)
Author:
Shane Alcock <salcock@…>
Branches:
4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, master, ndag_format, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
Children:
000726a
Parents:
733c8b4 (diff), 2b0eae9 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'origin/develop' into libtrace4

Conflicts:

INSTALL
README
lib/format_dpdk.c
lib/trace.c
tools/tracesplit/tracesplit.c

Location:
lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • lib/format_bpf.c

    rd8b05b7 ra984307  
    430430                ptr = ((struct local_bpf_hdr *)(packet->header));
    431431                replace = ((struct libtrace_bpf_hdr *)(packet->header));
    432                 orig = *ptr;
     432                memcpy(&orig, ptr, sizeof(struct local_bpf_hdr));
    433433
    434434                replace->bh_tstamp.tv_sec = (uint32_t) (orig.bh_tstamp.tv_sec & 0xffffffff);
  • lib/format_dpdk.c

    rd8b05b7 ra984307  
    142142#else
    143143#       define DPDK_USE_LOG_LEVEL 0
     144#endif
     145
     146/* 1.8.0-rc2
     147 * rx/tx_conf thresholds can be set to NULL in rte_eth_rx/tx_queue_setup
     148 * this uses the default values, which are better tuned per device
     149 * See issue #26
     150 */
     151#if RTE_VERSION >= RTE_VERSION_NUM(1, 8, 0, 2)
     152#       define DPDK_USE_NULL_QUEUE_CONFIG 1
     153#else
     154#       define DPDK_USE_NULL_QUEUE_CONFIG 0
    144155#endif
    145156
     
    13421353                                     format_data->nb_tx_buf,
    13431354                                     SOCKET_ID_ANY,
    1344                                      &tx_conf);
     1355                                     DPDK_USE_NULL_QUEUE_CONFIG ? NULL : &tx_conf);
    13451356        if (ret < 0) {
    13461357                snprintf(err, errlen, "Intel DPDK - Cannot configure TX queue"
     
    13901401                                             format_data->nb_rx_buf,
    13911402                                             format_data->nic_numa_node,
    1392                                              &rx_conf,
     1403                                             DPDK_USE_NULL_QUEUE_CONFIG ? NULL: &rx_conf,
    13931404                                             stream->mempool);
    13941405                if (ret < 0) {
  • lib/format_rt.c

    rd8b05b7 ra984307  
    159159                return -1;
    160160        }
    161        
     161
    162162        if (connect_msg.magic != LIBTRACE_RT_MAGIC) {
    163163                trace_set_err(libtrace, TRACE_ERR_INIT_FAILED,
  • lib/libtrace.h.in

    rd391ce0 ra984307  
    17131713/** Create a new packet object
    17141714 *
    1715  * @return A pointer to an initialised libtrace_packet_t object
     1715 * @return A pointer to an initialised libtrace_packet_t object, or NULL if
     1716 * libtrace is unable to allocate space for a new packet.
    17161717 */
    17171718DLLEXPORT libtrace_packet_t *trace_create_packet(void);
  • lib/trace.c

    rf0cb0d4 ra984307  
    55 * New Zealand.
    66 *
    7  * Authors: Daniel Lawson 
     7 * Authors: Daniel Lawson
    88 *          Perry Lorier
    9  *          Shane Alcock 
    10  *         
     9 *          Shane Alcock
     10 *
    1111 * All rights reserved.
    1212 *
    13  * This code has been developed by the University of Waikato WAND 
     13 * This code has been developed by the University of Waikato WAND
    1414 * research group. For further information please see http://www.wand.net.nz/
    1515 *
     
    120120        dest[n]='\0';
    121121}
    122  
     122
    123123static char *xstrndup(const char *src,size_t n)
    124 {       
     124{
    125125        char *ret=(char*)malloc(n+1);
    126126        if (ret==NULL) {
     
    163163}
    164164
    165 /* Prints help information for libtrace 
     165/* Prints help information for libtrace
    166166 *
    167167 * Function prints out some basic help information regarding libtrace,
     
    186186{
    187187        struct libtrace_format_t *tmp;
    188        
     188
    189189        /* Try and guess based on filename */
    190190        for(tmp = formats_list; tmp; tmp=tmp->next) {
     
    208208                }
    209209        }
    210        
     210
    211211        /* No formats matched -- make sure we clean up the IO object we
    212212         * used to probe the file magic */
     
    223223 *  erf:/path/to/erf/file
    224224 *  erf:/path/to/erf/file.gz
    225  *  erf:-                       (stdin)
     225 *  erf:-                       (stdin)
    226226 *  dag:/dev/dagcard
    227  *  pcapint:pcapinterface               (eg: pcapint:eth0)
     227 *  pcapint:pcapinterface               (eg: pcapint:eth0)
    228228 *  pcapfile:/path/to/pcap/file
    229229 *  pcapfile:-
     
    236236 */
    237237DLLEXPORT libtrace_t *trace_create(const char *uri) {
    238         libtrace_t *libtrace = 
     238        libtrace_t *libtrace =
    239239                        (libtrace_t *)malloc(sizeof(libtrace_t));
    240240        char *scan = 0;
    241         const char *uridata = 0;                 
     241        const char *uridata = 0;
    242242
    243243        trace_init();
     
    249249                return NULL;
    250250        }
    251        
     251
    252252        libtrace->err.err_num = TRACE_ERR_NOERROR;
    253253        libtrace->format=NULL;
    254        
     254
    255255        libtrace->event.tdelta = 0.0;
    256256        libtrace->event.packet = NULL;
     
    327327         * libtrace->uridata contains the appropriate data for this
    328328         */
    329        
    330         /* Call the init_input function for the matching capture format */
     329
     330        /* Call the init_input function for the matching capture format */
    331331        if (libtrace->format->init_input) {
    332332                int err=libtrace->format->init_input(libtrace);
    333333                assert (err==-1 || err==0);
    334334                if (err==-1) {
    335                         /* init_input should call trace_set_err to set
    336                          * the error message
     335                        /* init_input should call trace_set_err to set the
     336                         * error message
    337337                         */
    338338                        return libtrace;
     
    343343                return libtrace;
    344344        }
    345        
     345
    346346        if (scan)
    347347                free(scan);
     
    366366
    367367        trace_init();
    368        
     368
    369369        libtrace->err.err_num = TRACE_ERR_NOERROR;
    370370
     
    374374                xstrncpy(scan,uri, (size_t)(uridata - uri));
    375375        }
    376        
     376
    377377        libtrace->err.err_num = TRACE_ERR_NOERROR;
    378378        libtrace->format=NULL;
    379        
     379
    380380        libtrace->event.tdelta = 0.0;
    381381        libtrace->event.packet = NULL;
     
    413413        libtrace->perpkt_cbs = NULL;
    414414        libtrace->reporter_cbs = NULL;
    415        
    416415        for(tmp=formats_list;tmp;tmp=tmp->next) {
    417416                if (strlen(scan) == strlen(tmp->name) &&
     
    434433}
    435434
    436 /* Creates an output trace from a URI. 
     435/* Creates an output trace from a URI.
    437436 *
    438437 * @param uri   the uri string describing the output format and destination
    439  * @returns opaque pointer to a libtrace_output_t 
     438 * @returns opaque pointer to a libtrace_output_t
    440439 *
    441440 *  If an error occured when attempting to open the output trace, NULL is
    442  *  returned and trace_errno is set. 
    443  */
    444        
     441 *  returned and trace_errno is set.
     442 */
     443
    445444DLLEXPORT libtrace_out_t *trace_create_output(const char *uri) {
    446         libtrace_out_t *libtrace = 
     445        libtrace_out_t *libtrace =
    447446                        (libtrace_out_t*)malloc(sizeof(libtrace_out_t));
    448        
     447
    449448        char *scan = 0;
    450449        const char *uridata = 0;
     
    457456        libtrace->format = NULL;
    458457        libtrace->uridata = NULL;
    459        
     458
    460459        /* Parse the URI to determine what capture format we want to write */
    461460
     
    465464                return libtrace;
    466465        }
    467        
     466
    468467        /* Attempt to find the format in the list of supported formats */
    469468        for(tmp=formats_list;tmp;tmp=tmp->next) {
     
    534533
    535534/* Start an output trace */
    536 DLLEXPORT int trace_start_output(libtrace_out_t *libtrace) 
     535DLLEXPORT int trace_start_output(libtrace_out_t *libtrace)
    537536{
    538537        assert(libtrace);
     
    592591
    593592        /* If we get here, either the native configuration failed or the
    594          * format did not support configuration. However, libtrace can 
     593         * format did not support configuration. However, libtrace can
    595594         * deal with some options itself, so give that a go */
    596595        switch(option) {
     
    600599                                trace_get_err(libtrace);
    601600                        }
    602                         if (*(int*)value<0 
     601                        if (*(int*)value<0
    603602                                || *(int*)value>LIBTRACE_PACKET_BUFSIZE) {
    604603                                trace_set_err(libtrace,TRACE_ERR_BAD_STATE,
     
    622621                case TRACE_OPTION_META_FREQ:
    623622                        if (!trace_is_err(libtrace)) {
    624                                 trace_set_err(libtrace, 
     623                                trace_set_err(libtrace,
    625624                                                TRACE_ERR_OPTION_UNAVAIL,
    626625                                                "This format does not support meta-data gathering");
     
    629628                case TRACE_OPTION_EVENT_REALTIME:
    630629                        if (!trace_is_err(libtrace)) {
    631                                 trace_set_err(libtrace, 
     630                                trace_set_err(libtrace,
    632631                                                TRACE_ERR_OPTION_UNAVAIL,
    633632                                                "This format does not support realtime events");
     
    637636                        /* Dealt with earlier */
    638637                        return -1;
    639                        
     638
    640639        }
    641640        if (!trace_is_err(libtrace)) {
     
    671670                trace_option_output_t option,
    672671                void *value) {
    673        
     672
    674673        /* Unlike the input options, libtrace does not natively support any of
    675674         * the output options - the format module must be able to deal with
     
    778777 * @param libtrace      the output trace file to be destroyed
    779778 */
    780 DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace) 
     779DLLEXPORT void trace_destroy_output(libtrace_out_t *libtrace)
    781780{
    782781        assert(libtrace);
     
    792791        libtrace_packet_t *packet =
    793792                (libtrace_packet_t*)calloc((size_t)1,sizeof(libtrace_packet_t));
     793
     794        if (packet == NULL)
     795                return NULL;
    794796
    795797        packet->buf_control=TRACE_CTRL_PACKET;
     
    821823        /* Reset the cache - better to recalculate than try to convert
    822824         * the values over to the new packet */
    823         trace_clear_cache(dest);       
     825        trace_clear_cache(dest);
    824826        /* Ooooh nasty memcpys! This is why we want to avoid copying packets
    825827         * as much as possible */
     
    843845                free(packet->buffer);
    844846        }
    845         packet->buf_control=(buf_control_t)'\0'; 
     847        packet->buf_control=(buf_control_t)'\0';
    846848                                /* A "bad" value to force an assert
    847849                                 * if this packet is ever reused
     
    894896 * block until a packet is read (or EOF is reached).
    895897 *
    896  * @param libtrace      the libtrace opaque pointer
    897  * @param packet        the packet opaque pointer
     898 * @param libtrace      the libtrace opaque pointer
     899 * @param packet        the packet opaque pointer
    898900 * @returns 0 on EOF, negative value on error
    899901 *
     
    908910                return -1;
    909911        }
    910         if (!(packet->buf_control==TRACE_CTRL_PACKET || packet->buf_control==TRACE_CTRL_EXTERNAL)) {
     912        if (!(packet->buf_control==TRACE_CTRL_PACKET
     913                    || packet->buf_control==TRACE_CTRL_EXTERNAL)) {
    911914                trace_set_err(libtrace,TRACE_ERR_BAD_STATE,"Packet passed to trace_read_packet() is invalid\n");
    912915                return -1;
     
    969972 * appropriate capture format header for the format type that the packet is
    970973 * being converted to. This also allows for a packet to be converted into
    971  * just about capture format that is supported by libtrace, provided the 
     974 * just about capture format that is supported by libtrace, provided the
    972975 * format header is present in the buffer.
    973976 *
    974977 * This function is primarily used to convert packets received via the RT
    975978 * protocol back into their original capture format. The RT header encapsulates
    976  * the original capture format header, so after removing it the packet must 
     979 * the original capture format header, so after removing it the packet must
    977980 * have it's header and payload pointers updated and the packet format and type
    978981 * changed, amongst other things.
    979982 *
    980  * Intended only for internal use at this point - this function is not 
     983 * Intended only for internal use at this point - this function is not
    981984 * available through the external libtrace API.
    982985 */
     
    986989        assert(packet);
    987990        assert(trace);
    988        
     991
    989992        /* XXX Proper error handling?? */
    990993        if (buffer == NULL)
     
    995998                return -1;
    996999        }
    997        
     1000
    9981001        packet->trace = trace;
    9991002        pthread_mutex_lock(&trace->libtrace_lock);
    10001003        trace->last_packet = packet;
    10011004        pthread_mutex_unlock(&trace->libtrace_lock);
    1002        
    10031005        /* Clear packet cache */
    10041006        trace_clear_cache(packet);
     
    10081010                                buffer, rt_type, flags);
    10091011        }
    1010         trace_set_err(trace, TRACE_ERR_UNSUPPORTED, 
     1012        trace_set_err(trace, TRACE_ERR_UNSUPPORTED,
    10111013                        "This format does not support preparing packets\n");
    10121014        return -1;
     
    10501052                 * wire lengths to be the "remaining" value. If the packet has
    10511053                 * been padded to increase the capture length, we don't want
    1052                  * to allow subsequent protocol decoders to consider the 
     1054                 * to allow subsequent protocol decoders to consider the
    10531055                 * padding as part of the packet.
    10541056                 *
     
    10601062                 * better off returning an incomplete TCP header in that case.
    10611063                 */
    1062                
     1064
    10631065                cap_len = trace_get_capture_length(packet);
    10641066                wire_len = trace_get_wire_length(packet);
     
    10691071                 * massively negative wire lens. We could assert fail here on
    10701072                 * them, but we could at least try the capture length instead.
    1071                  * 
     1073                 *
    10721074                 * You may still run into problems if you try to write that
    10731075                 * packet, but at least reading should work OK.
     
    10851087
    10861088
    1087 /* Get a pointer to the first byte of the packet payload 
     1089/* Get a pointer to the first byte of the packet payload
    10881090 *
    10891091 * DEPRECATED - use trace_get_packet_buffer() instead */
     
    10921094}
    10931095
    1094 /* Get the current time in DAG time format 
    1095  * @param packet        a pointer to a libtrace_packet structure
     1096/* Get the current time in DAG time format
     1097 * @param packet        a pointer to a libtrace_packet structure
    10961098 * @returns a 64 bit timestamp in DAG ERF format (upper 32 bits are the seconds
    10971099 * past 1970-01-01, the lower 32bits are partial seconds)
    1098  */ 
     1100 */
    10991101DLLEXPORT uint64_t trace_get_erf_timestamp(const libtrace_packet_t *packet) {
    11001102        if (packet->trace->format->get_erf_timestamp) {
     
    11221124                return (uint64_t)0;
    11231125        }
    1124                      
    11251126}
    11261127
     
    11311132 * @author Daniel Lawson
    11321133 * @author Perry Lorier
    1133  */ 
     1134 */
    11341135DLLEXPORT struct timeval trace_get_timeval(const libtrace_packet_t *packet) {
    11351136        struct timeval tv;
     
    11431144                tv.tv_sec = ts >> 32;
    11441145                tv.tv_usec = ((ts&0xFFFFFFFF)*1000000)>>32;
    1145                 if (tv.tv_usec >= 1000000) {
    1146                         tv.tv_usec -= 1000000;
    1147                         tv.tv_sec += 1;
    1148                 }
     1146                if (tv.tv_usec >= 1000000) {
     1147                        tv.tv_usec -= 1000000;
     1148                        tv.tv_sec += 1;
     1149                }
    11491150        } else if (packet->trace->format->get_timespec) {
    11501151                struct timespec ts = packet->trace->format->get_timespec(packet);
     
    11751176                ts.tv_sec = erfts >> 32;
    11761177                ts.tv_nsec = ((erfts&0xFFFFFFFF)*1000000000)>>32;
    1177                 if (ts.tv_nsec >= 1000000000) {
    1178                         ts.tv_nsec -= 1000000000;
    1179                         ts.tv_sec += 1;
    1180                 }
     1178                if (ts.tv_nsec >= 1000000000) {
     1179                        ts.tv_nsec -= 1000000000;
     1180                        ts.tv_sec += 1;
     1181                }
    11811182                return ts;
    11821183        } else if (packet->trace->format->get_timeval) {
     
    12021203
    12031204/* Get the current time in floating point seconds
    1204  * @param packet        a pointer to a libtrace_packet structure
     1205 * @param packet        a pointer to a libtrace_packet structure
    12051206 * @returns time that this packet was seen in 64bit floating point seconds
    1206  */ 
     1207 */
    12071208DLLEXPORT double trace_get_seconds(const libtrace_packet_t *packet) {
    12081209        double seconds = 0.0;
     
    12311232}
    12321233
    1233 DLLEXPORT size_t trace_get_capture_length(const libtrace_packet_t *packet) 
     1234DLLEXPORT size_t trace_get_capture_length(const libtrace_packet_t *packet)
    12341235{
    12351236        /* Cache the capture length */
     
    12381239                        return ~0U;
    12391240                /* Cast away constness because this is "just" a cache */
    1240                 ((libtrace_packet_t*)packet)->capture_length = 
     1241                ((libtrace_packet_t*)packet)->capture_length =
    12411242                        packet->trace->format->get_capture_length(packet);
    12421243        }
     
    12461247        return packet->capture_length;
    12471248}
    1248        
     1249
    12491250/* Get the size of the packet as it was seen on the wire.
    12501251 * @param packet        a pointer to a libtrace_packet structure
     
    12531254 * @note Due to the trace being a header capture, or anonymisation this may
    12541255 * not be the same as the Capture Len.
    1255  */ 
     1256 */
    12561257DLLEXPORT size_t trace_get_wire_length(const libtrace_packet_t *packet){
    1257        
     1258
    12581259        if (packet->wire_length == -1) {
    1259                 if (!packet->trace->format->get_wire_length) 
     1260                if (!packet->trace->format->get_wire_length)
    12601261                        return ~0U;
    1261                 ((libtrace_packet_t *)packet)->wire_length = 
     1262                ((libtrace_packet_t *)packet)->wire_length =
    12621263                        packet->trace->format->get_wire_length(packet);
    12631264        }
     
    12691270
    12701271/* Get the length of the capture framing headers.
    1271  * @param packet        the packet opaque pointer
     1272 * @param packet        the packet opaque pointer
    12721273 * @returns the size of the packet as it was on the wire.
    1273  * @note this length corresponds to the difference between the size of a 
     1274 * @note this length corresponds to the difference between the size of a
    12741275 * captured packet in memory, and the captured length of the packet
    1275  */ 
     1276 */
    12761277DLLEXPORT SIMPLE_FUNCTION
    12771278size_t trace_get_framing_length(const libtrace_packet_t *packet) {
     
    12841285
    12851286/* Get the type of the link layer
    1286  * @param packet        a pointer to a libtrace_packet structure
     1287 * @param packet        a pointer to a libtrace_packet structure
    12871288 * @returns libtrace_linktype_t
    12881289 */
     
    13101311 * which in turn is stored inside the new packet object...
    13111312 */
    1312 DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace, 
     1313DLLEXPORT libtrace_eventobj_t trace_event(libtrace_t *trace,
    13131314                libtrace_packet_t *packet) {
    13141315        libtrace_eventobj_t event = {TRACE_EVENT_IOWAIT,0,0.0,0};
     
    13221323        /* Free the last packet */
    13231324        trace_fin_packet(packet);
    1324        
    13251325        /* Store the trace we are reading from into the packet opaque
    13261326         * structure */
     
    13291329        if (packet->trace->format->trace_event) {
    13301330                /* Note: incrementing accepted, filtered etc. packet
    1331                  * counters is handled by the format-specific 
     1331                 * counters is handled by the format-specific
    13321332                 * function so don't increment them here.
    13331333                 */
     
    13561356        filter->filter.bf_insns = (struct bpf_insn *)
    13571357                malloc(sizeof(struct bpf_insn) * bf_len);
    1358        
     1358
    13591359        memcpy(filter->filter.bf_insns, bf_insns,
    13601360                        bf_len * sizeof(struct bpf_insn));
    1361        
     1361
    13621362        filter->filter.bf_len = bf_len;
    13631363        filter->filterstring = NULL;
    13641364        filter->jitfilter = NULL;
    13651365        /* "flag" indicates that the filter member is valid */
    1366         filter->flag = 1; 
    1367        
     1366        filter->flag = 1;
     1367
    13681368        return filter;
    13691369#endif
     
    13951395                pcap_freecode(&filter->filter);
    13961396#ifdef HAVE_LLVM
    1397         if (filter->jitfilter) 
     1397        if (filter->jitfilter)
    13981398                destroy_program(filter->jitfilter);
    13991399#endif
     
    14131413static int trace_bpf_compile(libtrace_filter_t *filter,
    14141414                const libtrace_packet_t *packet,
    1415                 void *linkptr, 
     1415                void *linkptr,
    14161416                libtrace_linktype_t linktype    ) {
    14171417#ifdef HAVE_BPF_FILTER
     
    14291429                return -1;
    14301430        }
    1431        
     1431
    14321432        if (filter->filterstring && ! filter->flag) {
    14331433                pcap_t *pcap = NULL;
     
    14541454                /* build filter */
    14551455                assert(pcap);
    1456                 if (pcap_compile( pcap, &filter->filter, filter->filterstring, 
     1456                if (pcap_compile( pcap, &filter->filter, filter->filterstring,
    14571457                                        1, 0)) {
    14581458                        trace_set_err(packet->trace,TRACE_ERR_BAD_FILTER,
    1459                                         "Unable to compile the filter \"%s\": %s", 
     1459                                        "Unable to compile the filter \"%s\": %s",
    14601460                                        filter->filterstring,
    14611461                                        pcap_geterr(pcap));
     
    14981498
    14991499        if (linktype == TRACE_TYPE_NONDATA)
    1500                 return 1;       
     1500                return 1;
    15011501
    15021502        if (libtrace_to_pcap_dlt(linktype)==TRACE_DLT_ERROR) {
    1503                
     1503
    15041504                /* If we cannot get a suitable DLT for the packet, it may
    15051505                 * be because the packet is encapsulated in a link type that
     
    15071507                 * popping off headers until we either can find a suitable
    15081508                 * link type or we can't do any more sensible decapsulation. */
    1509                
     1509
    15101510                /* Copy the packet, as we don't want to trash the one we
    15111511                 * were passed in */
     
    15151515                while (libtrace_to_pcap_dlt(linktype) == TRACE_DLT_ERROR) {
    15161516                        if (!demote_packet(packet_copy)) {
    1517                                 trace_set_err(packet->trace, 
     1517                                trace_set_err(packet->trace,
    15181518                                                TRACE_ERR_NO_CONVERSION,
    15191519                                                "pcap does not support this format");
     
    15271527
    15281528        }
    1529        
     1529
    15301530        linkptr = trace_get_packet_buffer(packet_copy,NULL,&clen);
    15311531        if (!linkptr) {
     
    15361536        }
    15371537
    1538         /* We need to compile the filter now, because before we didn't know 
     1538        /* We need to compile the filter now, because before we didn't know
    15391539         * what the link type was
    15401540         */
     
    15851585 * @returns a signed value containing the direction flag, or -1 if this is not supported
    15861586 */
    1587 DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet, 
    1588                 libtrace_direction_t direction) 
     1587DLLEXPORT libtrace_direction_t trace_set_direction(libtrace_packet_t *packet,
     1588                libtrace_direction_t direction)
    15891589{
    15901590        assert(packet);
     
    16031603 * for a special trace.
    16041604 */
    1605 DLLEXPORT libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet) 
     1605DLLEXPORT libtrace_direction_t trace_get_direction(const libtrace_packet_t *packet)
    16061606{
    16071607        assert(packet);
     
    16181618#define DYNAMIC(x) ((49152 < (x)) && ((x) < 65535))
    16191619#define SERVER(x) ROOT_SERVER(x) || NONROOT_SERVER(x)
    1620 #define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x) 
     1620#define CLIENT(x) ROOT_CLIENT(x) || NONROOT_CLIENT(x)
    16211621
    16221622/* Attempt to deduce the 'server' port
     
    16261626 * @returns a hint as to which port is the server port
    16271627 */
    1628 DLLEXPORT int8_t trace_get_server_port(UNUSED uint8_t protocol, 
    1629                 uint16_t source, uint16_t dest) 
     1628DLLEXPORT int8_t trace_get_server_port(UNUSED uint8_t protocol,
     1629                uint16_t source, uint16_t dest)
    16301630{
    16311631        /*
     
    16401640         * * flip a coin.
    16411641         */
    1642        
     1642
    16431643        /* equal */
    16441644        if (source == dest)
     
    16861686                return USE_SOURCE;
    16871687        }
    1688        
     1688
    16891689        /* nonroot client */
    16901690        if (NONROOT_CLIENT(source) && NONROOT_CLIENT(dest)) {
    1691                 if (source < dest) 
     1691                if (source < dest)
    16921692                        return USE_SOURCE;
    16931693                return USE_DEST;
     
    17091709                return USE_SOURCE;
    17101710        /*
    1711         if (SERVER(source) && CLIENT(dest)) 
     1711        if (SERVER(source) && CLIENT(dest))
    17121712                return USE_SOURCE;
    1713        
    1714         if (SERVER(dest) && CLIENT(source)) 
     1713
     1714        if (SERVER(dest) && CLIENT(source))
    17151715                return USE_DEST;
    1716         if (ROOT_SERVER(source) && !ROOT_SERVER(dest)) 
     1716        if (ROOT_SERVER(source) && !ROOT_SERVER(dest))
    17171717                return USE_SOURCE;
    1718         if (ROOT_SERVER(dest) && !ROOT_SERVER(source)) 
     1718        if (ROOT_SERVER(dest) && !ROOT_SERVER(source))
    17191719                return USE_DEST;
    17201720        */
     
    17221722        if (source < dest) {
    17231723                return USE_SOURCE;
    1724         } 
     1724        }
    17251725        return USE_DEST;
    1726        
     1726
    17271727}
    17281728
     
    17531753 *
    17541754 * Returns a pointer to the URI data, but updates the format parameter to
    1755  * point to a copy of the format component. 
     1755 * point to a copy of the format component.
    17561756 */
    17571757
    17581758DLLEXPORT const char * trace_parse_uri(const char *uri, char **format) {
    17591759        const char *uridata = 0;
    1760        
     1760
    17611761        if((uridata = strchr(uri,':')) == NULL) {
    17621762                /* Badly formed URI - needs a : */
     
    17751775        /* Push uridata past the delimiter */
    17761776        uridata++;
    1777        
     1777
    17781778        return uridata;
    17791779}
    17801780
    1781 enum base_format_t trace_get_format(libtrace_packet_t *packet) 
     1781enum base_format_t trace_get_format(libtrace_packet_t *packet)
    17821782{
    17831783        assert(packet);
     
    17851785        return packet->trace->format->type;
    17861786}
    1787        
     1787
    17881788DLLEXPORT libtrace_err_t trace_get_err(libtrace_t *trace)
    17891789{
     
    18831883                }
    18841884                if (trace->format->seek_seconds) {
    1885                         double seconds = 
     1885                        double seconds =
    18861886                                (ts>>32) + ((ts & UINT_MAX)*1.0 / UINT_MAX);
    18871887                        return trace->format->seek_seconds(trace,seconds);
     
    19071907                }
    19081908                if (trace->format->seek_erf) {
    1909                         uint64_t timestamp = 
     1909                        uint64_t timestamp =
    19101910                                ((uint64_t)((uint32_t)seconds) << 32) + \
    19111911                            (uint64_t)(( seconds - (uint32_t)seconds   ) * UINT_MAX);
     
    19701970
    19711971
    1972 /* Creates a libtrace packet from scratch using the contents of the provided 
     1972/* Creates a libtrace packet from scratch using the contents of the provided
    19731973 * buffer as the packet payload.
    19741974 *
    19751975 * Unlike trace_prepare_packet(), the buffer should not contain any capture
    1976  * format headers; instead this function will add the PCAP header to the 
     1976 * format headers; instead this function will add the PCAP header to the
    19771977 * packet record. This also means only PCAP packets can be constructed using
    19781978 * this function.
     
    19961996        /* We need a trace to attach the constructed packet to (and it needs
    19971997         * to be PCAP) */
    1998         if (NULL == deadtrace) 
     1998        if (NULL == deadtrace)
    19991999                deadtrace=trace_create_dead("pcapfile");
    20002000
     
    20142014
    20152015        /* Now fill in the libtrace packet itself */
     2016        assert(deadtrace);
    20162017        packet->trace=deadtrace;
    20172018        size=len+sizeof(hdr);
     2019        if (size < LIBTRACE_PACKET_BUFSIZE)
     2020            size = LIBTRACE_PACKET_BUFSIZE;
    20182021        if (packet->buf_control==TRACE_CTRL_PACKET) {
    2019                 packet->buffer=realloc(packet->buffer,size);
     2022            packet->buffer = realloc(packet->buffer, size);
    20202023        }
    20212024        else {
    2022                 packet->buffer=malloc(size);
     2025                packet->buffer = malloc(size);
    20232026        }
    20242027        packet->buf_control=TRACE_CTRL_PACKET;
    20252028        packet->header=packet->buffer;
    20262029        packet->payload=(void*)((char*)packet->buffer+sizeof(hdr));
    2027        
    2028         /* Ugh, memcpy - sadly necessary */
    2029         memcpy(packet->header,&hdr,sizeof(hdr));
    2030         memcpy(packet->payload,data,(size_t)len);
     2030
     2031        /* Ugh, memmove - sadly necessary, also beware that we might be
     2032         * moving data around within this packet, so ordering is important.
     2033         */
     2034        memmove(packet->payload, data, (size_t)len);
     2035        memmove(packet->header, &hdr, sizeof(hdr));
    20312036        packet->type=pcap_linktype_to_rt(libtrace_to_pcap_linktype(linktype));
    20322037
     
    22982303
    22992304        /* Now, verify that the format has at least the minimum functionality.
    2300          * 
     2305         *
    23012306         * This #if can be changed to a 1 to output warnings about inconsistent
    23022307         * functions being provided by format modules.  This generally is very
    23032308         * noisy, as almost all modules don't implement one or more functions
    2304          * for various reasons.  This is very useful when checking a new 
     2309         * for various reasons.  This is very useful when checking a new
    23052310         * format module is sane.
    2306          */ 
     2311         */
    23072312#if 0
    23082313        if (f->init_input) {
     
    23182323                REQUIRE(get_framing_length);
    23192324                REQUIRE(trace_event);
    2320                 if (!f->get_erf_timestamp 
     2325                if (!f->get_erf_timestamp
    23212326                        && !f->get_seconds
    23222327                        && !f->get_timeval) {
Note: See TracChangeset for help on using the changeset viewer.