Changeset c8171e5


Ignore:
Timestamp:
01/21/19 09:48:57 (22 months ago)
Author:
Jacob Van Walraven <jcv9@…>
Branches:
develop
Children:
b27ed21
Parents:
66ffac4
Message:

Add specific ERF meta-api functions trace_get_erf_dag_card_model, trace_get_erf_dag_version, trace_get_erf_dag_fw_version

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pktmeta.c

    r66ffac4 rc8171e5  
    9999        return space;
    100100}
     101
    101102/* Get the interface MAC address/s for a meta packet.
    102103 * Must be destroyed with trace_destroy_meta().
     
    238239 * @returns Pointer to the character buffer containing the ipv4 address string or NULL.
    239240 */
     241/* UNTESTED */
    240242char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, char *space, int spacelen,
    241243        int index) {
     
    245247
    246248        char *addrstr = inet_ntoa(*(struct in_addr *)&addr);
    247         memcpy(space, addrstr, strlen(addrstr));
     249        memcpy(space, addrstr, spacelen);
    248250        return space;
    249251}
     
    306308 * @returns Pointer to the character buffer containing the ipv6 address string or NULL.
    307309 */
     310/* UNTESTED */
    308311char *trace_get_interface_ipv6_string(libtrace_packet_t *packet, char *space, int spacelen,
    309312        int index) {
    310313
    311         return NULL;
     314        if (spacelen < INET6_ADDRSTRLEN) {
     315                return NULL;
     316        }
     317
     318        void *addr = calloc(1, 16);
     319        void *r = trace_get_interface_ipv6(packet, addr, 16, index);
     320
     321        if (r == NULL) {
     322                return NULL;
     323        }
     324
     325        inet_ntop(AF_INET6, addr, space, INET6_ADDRSTRLEN);
     326        free(addr);
     327
     328        return space;
    312329}
    313330
     
    443460}
    444461
    445 /* Get the hardware description
    446  * Must be destroyed with trace_destroy_meta()
    447  *
    448  * @params libtrace_packet_t meta packet
    449  * @returns Pointer to libtrace_meta_t structure or NULL
    450  */
    451 libtrace_meta_t *trace_get_interface_hardware_description_meta(libtrace_packet_t *packet) {
    452         if (trace_meta_check_input(packet, "trace_get_interface_hardware_description()")<0) {
    453                 return NULL;
    454         }
    455 
    456         if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    457                 return packet->trace->format->get_meta_section_option(packet,
    458                         PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_HARDWARE);
    459         }
    460         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    461                 return packet->trace->format->get_meta_section_option(packet,
    462                         ERF_PROV_SECTION_MODULE, ERF_PROV_MODEL);
    463         }
    464 
    465         return NULL;
    466 }
    467 /* Get the hardware description for a meta packet.
    468  *
    469  * @params libtrace_packet_t meta packet to extract the hardware description from.
    470  * @params A pointer to a character buffer to store the hardware description in.
    471  * @params The size of the buffer passed in.
    472  * @returns Pointer to the character buffer containing the hardware description or NULL.
    473  */
    474 char *trace_get_interface_hardware_description(libtrace_packet_t *packet, char *space,
    475         int spacelen) {
    476 
    477         libtrace_meta_t *r = trace_get_interface_hardware_description_meta(packet);
    478         if (r == NULL) { return NULL; }
    479         if (r->items[0].len > spacelen) {
    480                 memcpy(space, r->items[0].data, spacelen);
    481         } else {
    482                 memcpy(space, r->items[0].data, r->items[0].len);
    483         }
    484         trace_destroy_meta(r);
    485         return space;
    486 }
    487 
    488462/* Get any interface comments for a meta packet
    489463 * Must be destroyed with trace_destroy_meta()
     
    607581        return packet->trace->format->get_meta_section(packet, section_code);
    608582}
     583
     584
     585
     586/* ERF specific function */
     587/* Get the DAG card model from a meta packet.
     588 *
     589 * @params libtrace_packet_t meta packet to extract the DAG model from.
     590 * @params A pointer to a character buffer to store the DAG model in.
     591 * @params The size of the buffer passed in.
     592 * @returns Pointer to the character buffer containing the DAG model or NULL.
     593 */
     594char *trace_get_erf_dag_card_model(libtrace_packet_t *packet, char *space, int spacelen) {
     595        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
     596                ERF_PROV_MODEL);
     597
     598        if (r == NULL) { return NULL; }
     599        if (r->items[0].len > spacelen) {
     600                memcpy(space, r->items[0].data, spacelen);
     601        } else {
     602                memcpy(space, r->items[0].data, r->items[0].len);
     603        }
     604        trace_destroy_meta(r);
     605        return space;
     606}
     607/* Get the host DAG software version for a meta packet.
     608 *
     609 * @params libtrace_packet_t meta packet to extract the hosts DAG verion from.
     610 * @params A pointer to a character buffer to store the DAG version in.
     611 * @params The size of the buffer passed in.
     612 * @returns Pointer to the character buffer containing the DAG version or NULL.
     613 */
     614char *trace_get_erf_dag_version(libtrace_packet_t *packet, char *space, int spacelen) {
     615        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
     616                ERF_PROV_DAG_VERSION);
     617
     618        if (r == NULL) { return NULL; }
     619
     620        if (r->items[0].len > spacelen) {
     621                memcpy(space, r->items[0].data, spacelen);
     622        } else {
     623                memcpy(space, r->items[0].data, r->items[0].len);
     624        }
     625        trace_destroy_meta(r);
     626        return space;
     627}
     628/* Get the firmware version for a DAG module from a meta packet.
     629 *
     630 * @params libtrace_packet_t meta packet to extract the FW version from.
     631 * @params A pointer to a character buffer to store the FW version in.
     632 * @params The size of the buffer passed in.
     633 * @returns Pointer to the character buffer containing the FW version or NULL.
     634 */
     635char *trace_get_erf_dag_fw_version(libtrace_packet_t *packet, char *space, int spacelen) {
     636        libtrace_meta_t *r = trace_get_section_option(packet, ERF_PROV_SECTION_MODULE,
     637                ERF_PROV_FW_VERSION);
     638
     639        if (r == NULL) { return NULL; }
     640
     641        if (r->items[0].len > spacelen) {
     642                memcpy(space, r->items[0].data, spacelen);
     643        } else {
     644                memcpy(space, r->items[0].data, r->items[0].len);
     645        }
     646        trace_destroy_meta(r);
     647        return space;
     648}
     649
  • lib/libtrace.h.in

    r66ffac4 rc8171e5  
    37803780DLLEXPORT uint32_t trace_get_interface_fcslen(libtrace_packet_t *packet, int index);
    37813781
    3782 DLLEXPORT libtrace_meta_t *trace_get_interface_hardware_description_meta(libtrace_packet_t *packet);
    3783 
    3784 DLLEXPORT char *trace_get_interface_hardware_description(libtrace_packet_t *packet, char *space,
    3785         int spacelen);
    3786 
    37873782DLLEXPORT libtrace_meta_t *trace_get_interface_comment_meta(libtrace_packet_t *packet);
    37883783
     
    37993794DLLEXPORT libtrace_meta_t *trace_get_section(libtrace_packet_t *packet, uint32_t section_code);
    38003795
     3796DLLEXPORT char *trace_get_erf_dag_card_model(libtrace_packet_t *packet, char *space,
     3797        int spacelen);
     3798
     3799DLLEXPORT char *trace_get_erf_dag_version(libtrace_packet_t *packet, char *space,
     3800        int spacelen);
     3801
     3802DLLEXPORT char *trace_get_erf_dag_fw_version(libtrace_packet_t *packet, char *space,
     3803        int spacelen);
    38013804
    38023805#ifdef __cplusplus
Note: See TracChangeset for help on using the changeset viewer.