Ignore:
Timestamp:
02/05/19 15:12:49 (2 years ago)
Author:
Jacob Van Walraven <jcv9@…>
Branches:
develop
Children:
4e5a51f
Parents:
7b4f5e2
Message:

Move function descriptions to the correct header file, Revert trace_get_interface_ipv4 changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pktmeta.c

    r7b4f5e2 r58c226e  
    2121}
    2222
    23 /* API functions to retrieve interface related packet data */
    24 
    25 /* Destroy libtrace_meta_t structure
    26  *
    27  * @params libtrace_meta_t structure
    28  * returns 1 on success, -1 on failure
    29  */
    30 int trace_destroy_meta(libtrace_meta_t *result) {
    31         int i;
    32         if (!result) { return -1; }
    33 
    34         for (i=0;i<result->num;i++) {
    35                 if(result->items[i].data != NULL) {
    36                         free(result->items[i].data);
    37                 }
    38         }
    39         if (result->items) {
    40                 free(result->items);
    41         }
    42         if (result) {
    43                 free(result);
    44         }
    45 
    46         return 1;
    47 }
    48 
    49 libtrace_meta_t *trace_get_meta_option(libtrace_packet_t *packet, uint32_t section,
     23static libtrace_meta_t *trace_get_meta_option(libtrace_packet_t *packet, uint32_t section,
    5024        uint32_t option) {
    5125
     
    12094}
    12195
    122 /* Get the interface name/s for a meta packet.
    123  * Must be destroyed with trace_destroy_meta().
    124  *
    125  * @params libtrace_packet_t meta packet.
    126  * @returns Pointer to libtrace_meta_t structure containing all found interface names
    127  * or NULL.
    128  */
     96
     97/* API FUNCTIONS */
     98
     99int trace_destroy_meta(libtrace_meta_t *result) {
     100        int i;
     101        if (!result) { return -1; }
     102
     103        for (i=0;i<result->num;i++) {
     104                if(result->items[i].data != NULL) {
     105                        free(result->items[i].data);
     106                }
     107        }
     108        if (result->items) {
     109                free(result->items);
     110        }
     111        if (result) {
     112                free(result);
     113        }
     114
     115        return 1;
     116}
     117
    129118libtrace_meta_t *trace_get_interface_name_meta(libtrace_packet_t *packet) {
    130119        if (trace_meta_check_input(packet, "trace_get_interface_name()")<0) {
     
    144133        return r;
    145134}
    146 /* Get the interface name for a meta packet.
    147  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    148  * specify the interface index.
    149  *
    150  * @params libtrace_packet_t meta packet to extract the interface name from.
    151  * @params A pointer to a character buffer to store the interface name in.
    152  * @params The size of the buffer passed in.
    153  * @params The interface index within the meta packet.
    154  * @returns Pointer to the character buffer containing the interface name or NULL.
    155  */
     135
    156136char *trace_get_interface_name(libtrace_packet_t *packet, char *space, int spacelen,
    157137        int index) {
     
    177157}
    178158
    179 /* Get the interface MAC address/s for a meta packet.
    180  * Must be destroyed with trace_destroy_meta().
    181  *
    182  * @params libtrace_packet_t meta packet.
    183  * @returns Pointer to libtrace_meta_t structure containing all found interface mac
    184  * addresses or NULL.
    185  */
    186159libtrace_meta_t *trace_get_interface_mac_meta(libtrace_packet_t *packet) {
    187160        if (trace_meta_check_input(packet, "trace_get_interface_mac()")<0) {
     
    200173        return r;
    201174}
    202 /* Get the interface MAC address for a meta packet.
    203  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    204  * specify the interface index.
    205  *
    206  * @params libtrace_packet_t meta packet to extract the MAC address from.
    207  * @params A pointer to a character buffer to store the MAC address in.
    208  * @params The size of the buffer passed in.
    209  * @params The interface index within the meta packet.
    210  * @returns Pointer to the character buffer containing the MAC address or NULL.
    211  */
     175
    212176char *trace_get_interface_mac(libtrace_packet_t *packet, char *space, int spacelen,
    213177        int index) {
     
    230194}
    231195
    232 /* Get the interface speed/s from a meta packet.
    233  * Must be destroyed with trace_destroy_meta().
    234  *
    235  * @params libtrace_packet_t packet.
    236  * @returns Pointer to libtrace_meta_t structure containing all found interface
    237  * speeds or NULL.
    238  */
    239196libtrace_meta_t *trace_get_interface_speed_meta(libtrace_packet_t *packet) {
    240197        if (trace_meta_check_input(packet, "trace_get_interface_speed()")<0) {
     
    253210        return r;
    254211}
    255 /* Get the interface speed for a meta packet.
    256  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    257  * specify the interface index.
    258  *
    259  * @params libtrace_packet_t meta packet to extract the interface speed from.
    260  * @params The interface index within the meta packet.
    261  * @returns uint64_t interface speed or NULL.
    262  */
     212
    263213uint64_t trace_get_interface_speed(libtrace_packet_t *packet, int index) {
    264214        libtrace_meta_t *r = trace_get_interface_speed_meta(packet);
     
    275225}
    276226
    277 /* Get the interface ipv4 address/s for a meta packet.
    278  * Must be destroyed with trace_destroy_meta().
    279  *
    280  * @params libtrace_packet_t meta packet.
    281  * @returns Pointer to libtrace_meta_t structure containing all found ipv4 addresses
    282  * or NULL
    283  */
    284227libtrace_meta_t *trace_get_interface_ipv4_meta(libtrace_packet_t *packet) {
    285228        if (trace_meta_check_input(packet, "trace_get_interface_ip4()")<0) {
     
    298241        return r;
    299242}
    300 /* Get the interface ipv4 address for a meta packet.
    301  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    302  * specify the interface index.
    303  *
    304  * @params libtrace_packet_t meta packet to extract the ipv4 address from.
    305  * @params The interface index within the meta packet.
    306  * @returns uint32_t ipv4 address or 0.
    307  */
     243
    308244uint32_t trace_get_interface_ipv4(libtrace_packet_t *packet, int index) {
    309245        libtrace_meta_t *r = trace_get_interface_ipv4_meta(packet);
     
    317253        return data;
    318254}
    319 /* Get the interface ipv4 address string for a meta packet.
    320  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    321  * specify the interface index.
    322  *
    323  * @params libtrace_packet_t meta packet to extract the ipv4 address from.
    324  * @params The interface index within the meta packet.
    325  * @returns Pointer to the character buffer containing the ipv4 address string or NULL.
    326  */
     255
    327256/* UNTESTED */
    328 char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, int index) {
    329         struct in_addr ip;
    330         uint32_t addr;
    331 
    332         addr = trace_get_interface_ipv4(packet, index);
    333         if (addr == 0) { return NULL; }
    334 
    335         ip.s_addr = addr;
    336 
    337         return inet_ntoa(ip);
    338 }
    339 
    340 /* Get the interface ipv6 address/s for a meta packet.
    341  * Must be destroyed with trace_destroy_meta().
    342  *
    343  * @params libtrace_packet_t meta packet.
    344  * @returns Pointer to libtrace_meta_t structure containing all found ipv6 addresses
    345  * or NULL.
    346  */
     257char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, char *space, int spacelen,
     258        int index) {
     259
     260        if (spacelen < INET_ADDRSTRLEN) {
     261                return NULL;
     262        }
     263
     264        uint32_t addr = trace_get_interface_ipv4(packet, index);
     265        if (addr == 0) {
     266                return NULL;
     267        }
     268
     269        /* get the string representation, store in space */
     270        inet_ntop(AF_INET, &addr, space, INET_ADDRSTRLEN);
     271
     272        return space;
     273}
     274
    347275libtrace_meta_t *trace_get_interface_ipv6_meta(libtrace_packet_t *packet) {
    348276        if (trace_meta_check_input(packet, "trace_get_interface_ip6()")<0) {
     
    361289        return r;
    362290}
    363 /* Get the interface ipv6 address for a meta packet.
    364  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    365  * specify the interface index.
    366  *
    367  * @params libtrace_packet_t meta packet to extract the ipv6 address from.
    368  * @params A pointer to a character buffer to store the ipv6 address in.
    369  * @params The size of the buffer passed in.
    370  * @params The interface index within the meta packet.
    371  * @returns Pointer to the buffer containing the ipv6 address or NULL.
    372  */
     291
    373292void *trace_get_interface_ipv6(libtrace_packet_t *packet, void *space, int spacelen,
    374293        int index) {
     
    388307        return space;
    389308}
    390 /* Get the interface ipv6 address string for a meta packet.
    391  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    392  * specify the interface index.
    393  *
    394  * @params libtrace_packet_t meta packet to extract the ipv6 address from.
    395  * @params A pointer to a character buffer to store the ipv6 address in.
    396  * @params The size of the buffer passed in.
    397  * @params The interface index within the meta packet.
    398  * @returns Pointer to the character buffer containing the ipv6 address string or NULL.
    399  */
     309
    400310/* UNTESTED */
    401311char *trace_get_interface_ipv6_string(libtrace_packet_t *packet, char *space, int spacelen,
     
    414324        }
    415325
    416         /* get the string representation */
     326        /* get the string representation, store in space */
    417327        inet_ntop(AF_INET6, &(sa.sin6_addr), space, INET6_ADDRSTRLEN);
    418328
     
    420330}
    421331
    422 
    423 /* Get the interface description/s for a meta packet.
    424  * Must be destroyed with trace_destroy_meta().
    425  *
    426  * @params libtrace_packet_t meta packet.
    427  * @returns Pointer to libtrace_meta_t structure containing all found interface
    428  * descriptions or NULL.
    429  */
    430332libtrace_meta_t *trace_get_interface_description_meta(libtrace_packet_t *packet) {
    431333        if (trace_meta_check_input(packet, "trace_get_interface_description()")<0) {
     
    444346        return r;
    445347}
    446 /* Get the interface description for a meta packet.
    447  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    448  * specify the interface index.
    449  *
    450  * @params libtrace_packet_t meta packet to extract the interface description from.
    451  * @params A pointer to a character buffer to store the interface description in.
    452  * @params The size of the buffer passed in.
    453  * @params The interface index within the meta packet.
    454  * @returns Pointer to the character buffer containing the interface description or NULL.
    455  */
     348
    456349char *trace_get_interface_description(libtrace_packet_t *packet, char *space, int spacelen,
    457350        int index) {
     
    474367}
    475368
    476 
    477 /* Get the host OS for a meta packet.
    478  * Must be destroyed with trace_destroy_meta().
    479  *
    480  * @params libtrace_packet_t meta packet.
    481  * @returns Pointer to libtrace_meta_t structure containing the host OS or NULL.
    482  */
    483369libtrace_meta_t *trace_get_host_os_meta(libtrace_packet_t *packet) {
    484370        if (trace_meta_check_input(packet, "trace_get_host_os()")<0) {
     
    497383        return r;
    498384}
    499 /* Get the host OS for a meta packet.
    500  *
    501  * @params libtrace_packet_t meta packet to extract the host OS from.
    502  * @params A pointer to a character buffer to store the host OS in.
    503  * @params The size of the buffer passed in.
    504  * @returns Pointer to the character buffer containing the host OS or NULL.
    505  */
     385
    506386char *trace_get_host_os(libtrace_packet_t *packet, char *space, int spacelen) {
    507387        libtrace_meta_t *r = trace_get_host_os_meta(packet);
     
    518398}
    519399
    520 /* Get the interface frame check sequence length for a meta packet.
    521  * Must be destroyed with trace_destroy_meta().
    522  *
    523  * @params libtrace_packet_t meta packet.
    524  * @returns Pointer to libtrace_meta_t structure containing all found frame check
    525  * sequence lengths or NULL.
    526  */
    527400libtrace_meta_t *trace_get_interface_fcslen_meta(libtrace_packet_t *packet) {
    528401        if (trace_meta_check_input(packet, "trace_get_interface_frame_check_sequence_length()")<0) {
     
    541414        return r;
    542415}
    543 /* Get the interface frame check sequence length for a meta packet.
    544  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    545  * specify the interface index.
    546  *
    547  * @params libtrace_packet_t meta packet to extract the interface fcslen from.
    548  * @params The interface index within the meta packet.
    549  * @returns uint32_t frame check sequence length or 0.
    550  */
     416
    551417uint32_t trace_get_interface_fcslen(libtrace_packet_t *packet, int index) {
    552418        libtrace_meta_t *r = trace_get_interface_fcslen_meta(packet);
     
    561427}
    562428
    563 /* Get any interface comments for a meta packet
    564  * Must be destroyed with trace_destroy_meta()
    565  *
    566  * @params libtrace_packet_t packet
    567  * @returns Pointer to libtrace_meta_t structure or NULL
    568  */
    569429libtrace_meta_t *trace_get_interface_comment_meta(libtrace_packet_t *packet) {
    570430        if (trace_meta_check_input(packet, "trace_get_interface_comment()")<0) {
     
    583443        return r;
    584444}
    585 /* Get the interface comment for a meta packet.
    586  * Note: ERF packets can contain multiple interfaces per meta packet. Use index to
    587  * specify the interface ID.
    588  *
    589  * @params libtrace_packet_t meta packet to extract the interface comment from.
    590  * @params A pointer to a character buffer to store the interface description in.
    591  * @params The size of the buffer passed in.
    592  * @params The interface number within the meta packet.
    593  * @returns Pointer to the character buffer containing the hardware description or NULL.
    594  */
     445
    595446char *trace_get_interface_comment(libtrace_packet_t *packet, char *space, int spacelen,
    596447        int index) {
     
    613464}
    614465
    615 /* Get the capture application for a meta packet
    616  * Must be destroyed with trace_destroy_meta()
    617  *
    618  * @params libtrace_packet_t packet
    619  * @returns Pointer to libtrace_meta_t structure or NULL
    620  */
    621466libtrace_meta_t *trace_get_capture_application_meta(libtrace_packet_t *packet) {
    622467        if (trace_meta_check_input(packet, "trace_get_interface_comment()")<0) {
     
    635480        return r;
    636481}
    637 /* Get the capture application for a meta packet.
    638  *
    639  * @params libtrace_packet_t meta packet to extract the application name from.
    640  * @params A pointer to a character buffer to store the application name in.
    641  * @params The size of the buffer passed in.
    642  * @returns Pointer to the character buffer containing the application name or NULL.
    643  */
     482
    644483char *trace_get_capture_application(libtrace_packet_t *packet, char *space, int spacelen) {
    645484        libtrace_meta_t *r = trace_get_capture_application_meta(packet);
     
    656495}
    657496
    658 /* Get a meta section option from a meta packet
    659  * Must be destroyed with trace_destroy_meta()
    660  *
    661  * @params libtrace_packet_t packet
    662  * @params Section code
    663  * @params Option code
    664  * @returns Pointer to libtrace_meta_t structure or NULL
    665  */
    666497libtrace_meta_t *trace_get_section_option(libtrace_packet_t *packet, uint32_t section_code,
    667498        uint16_t option_code) {
     
    674505}
    675506
    676 /* Get a section from a meta packet
    677  * Must be destroyed with trace_destroy_meta()
    678  *
    679  * @params libtrace_packet_t packet
    680  * @params Section code
    681  * @returns Pointer to libtrace_meta_t structure or NULL
    682  */
    683507libtrace_meta_t *trace_get_section(libtrace_packet_t *packet, uint32_t section_code) {
    684508        if (trace_meta_check_input(packet, "trace_get_section()")<0) {
     
    689513}
    690514
    691 /* ERF specific function */
    692 /* Get the DAG card model from a meta packet.
    693  *
    694  * @params libtrace_packet_t meta packet to extract the DAG model from.
    695  * @params A pointer to a character buffer to store the DAG model in.
    696  * @params The size of the buffer passed in.
    697  * @returns Pointer to the character buffer containing the DAG model or NULL.
    698  */
    699515char *trace_get_erf_dag_card_model(libtrace_packet_t *packet, char *space, int spacelen) {
    700516        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
     
    712528        return space;
    713529}
    714 /* Get the host DAG software version for a meta packet.
    715  *
    716  * @params libtrace_packet_t meta packet to extract the hosts DAG verion from.
    717  * @params A pointer to a character buffer to store the DAG version in.
    718  * @params The size of the buffer passed in.
    719  * @returns Pointer to the character buffer containing the DAG version or NULL.
    720  */
     530
    721531char *trace_get_erf_dag_version(libtrace_packet_t *packet, char *space, int spacelen) {
    722532        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
     
    735545        return space;
    736546}
    737 /* Get the firmware version for a DAG module from a meta packet.
    738  *
    739  * @params libtrace_packet_t meta packet to extract the FW version from.
    740  * @params A pointer to a character buffer to store the FW version in.
    741  * @params The size of the buffer passed in.
    742  * @returns Pointer to the character buffer containing the FW version or NULL.
    743  */
     547
    744548char *trace_get_erf_dag_fw_version(libtrace_packet_t *packet, char *space, int spacelen) {
    745549        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
Note: See TracChangeset for help on using the changeset viewer.