Ignore:
Timestamp:
01/16/19 13:52:38 (2 years ago)
Author:
Jacob Van Walraven <jcv9@…>
Branches:
develop
Children:
d51e5d0
Parents:
629b19b
Message:

add abilty to get custom option from meta packets, add abilty to get entire section from meta packet, meta api now returns libtrace_meta_t structure

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/format_pktmeta.c

    r629b19b ref5ba20  
    2525/* API functions to retrieve interface related packet data */
    2626
    27 /* Reads the interface name for a packet
    28  *
    29  * @params libtrace_packet_t packet
    30  * @returns A pointer to a NULL terminated string containing the interface name or NULL
    31  */
    32 char *trace_get_interface_name(libtrace_packet_t *packet) {
     27/* Destroy libtrace_meta_t structure
     28 *
     29 * @params libtrace_meta_t structure
     30 * returns 1 on success, -1 on failure
     31 */
     32int trace_destroy_meta(libtrace_meta_t *result) {
     33        int i;
     34        if (!result) { return -1; }
     35
     36        for (i=0;i<result->num;i++) {
     37                if(result->items[i].data) {
     38                        free(result->items[i].data);
     39                }
     40        }
     41        if (result->items) {
     42                free(result->items);
     43        }
     44        if (result) {
     45                free(result);
     46        }
     47
     48        return 1;
     49}
     50
     51/* Get the interface name/s
     52 * Must be destroyed with trace_destroy_meta()
     53 *
     54 * @params libtrace_packet_t meta packet
     55 * @returns Pointer to libtrace_meta_t structure or NULL
     56 */
     57libtrace_meta_t *trace_get_interface_name(libtrace_packet_t *packet) {
    3358        if (trace_meta_check_input(packet, "trace_get_interface_name()")<0) {
    3459                return NULL;
    3560        }
    3661
    37         void *ptr = NULL;
    38 
    39         /* cleanup any old results */
    40         if (packet->meta.interface_name != NULL) {
    41                 free(packet->meta.interface_name);
    42                 packet->meta.interface_name = NULL;
    43         }
    44 
    4562        /* get the result */
    4663        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    47                 ptr = packet->trace->format->get_meta_data(packet,
     64                return packet->trace->format->get_meta_section_item(packet,
    4865                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_NAME);
    4966        }
    5067        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    51                 ptr = packet->trace->format->get_meta_data(packet,
     68                return packet->trace->format->get_meta_section_item(packet,
    5269                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_NAME);
    5370        }
    5471
    55         /* If a result was found */
    56         if (ptr != NULL) {
    57                 libtrace_meta_result_t *result = (libtrace_meta_result_t *)ptr;
    58 
    59                 /* store this result against the packet itself */
    60                 packet->meta.interface_name = malloc(ntohs(result->len)+1);
    61                 /* add NULL terminator to string */
    62                 packet->meta.interface_name[ntohs(result->len)] = '\0';
    63                 /* copy result over */
    64                 memcpy(packet->meta.interface_name, ptr+sizeof(libtrace_meta_result_t),
    65                         ntohs(result->len));
    66 
    67                 return packet->meta.interface_name;
    68         }
    69 
    70         return NULL;
    71 }
    72 
    73 /* Gets the interface MAC address from a meta packet
    74  *
    75  * @params libtrace_packet_t packet
    76  * @returns A pointer to a MAC address within the packet or NULL
    77  */
    78 void *trace_get_interface_mac(libtrace_packet_t *packet) {
     72        return NULL;
     73}
     74
     75/* Get the interface MAC address/s
     76 * Must be destroyed with trace_destroy_meta()
     77 *
     78 * @params libtrace_packet_t meta packet
     79 * @returns Pointer to libtrace_meta_t structure or NULL
     80 */
     81libtrace_meta_t *trace_get_interface_mac(libtrace_packet_t *packet) {
    7982        if (trace_meta_check_input(packet, "trace_get_interface_mac()")<0) {
    8083                return NULL;
    8184        }
    8285
    83         void *ptr = NULL;
    84 
    85         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    86                 ptr = packet->trace->format->get_meta_data(packet,
     86        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     87                return packet->trace->format->get_meta_section_item(packet,
    8788                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_MAC);
    8889        }
    8990        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    90                 ptr = packet->trace->format->get_meta_data(packet,
     91                return packet->trace->format->get_meta_section_item(packet,
    9192                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_MAC);
    9293        }
    9394
    94         if (ptr != NULL) {
    95                 packet->meta.interface_mac = ptr+sizeof(libtrace_meta_result_t);
    96                 return packet->meta.interface_mac;
    97         }
    98 
    99         return NULL;
    100 }
    101 
    102 /* Gets the interface speed from a meta packet
    103  *
    104  * @params libtrace_packet_t packet
    105  * @returns A pointer to the uint64_t interface speed within the packet or NULL
    106  */
    107 uint64_t *trace_get_interface_speed(libtrace_packet_t *packet) {
     95        return NULL;
     96}
     97
     98/* Get the interface speed/s from a meta packet
     99 * Must be destroyed with trace_destroy_meta()
     100 *
     101 * @params libtrace_packet_t packet
     102 * @returns Pointer to libtrace_meta_t structure or NULL
     103 */
     104libtrace_meta_t *trace_get_interface_speed(libtrace_packet_t *packet) {
    108105        if (trace_meta_check_input(packet, "trace_get_interface_speed()")<0) {
    109106                return NULL;
    110107        }
    111108
    112         void *ptr = NULL;
    113 
    114         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    115                 ptr = packet->trace->format->get_meta_data(packet,
     109        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     110                return packet->trace->format->get_meta_section_item(packet,
    116111                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_SPEED);
    117112        }
    118113        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    119                 ptr = packet->trace->format->get_meta_data(packet,
     114                return packet->trace->format->get_meta_section_item(packet,
    120115                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_SPEED);
    121116        }
    122117
    123         if (ptr != NULL) {
    124                 uint64_t *intspeed = (uint64_t *)(ptr+sizeof(libtrace_meta_result_t));
    125                 packet->meta.interface_speed = *intspeed;
    126                 return &packet->meta.interface_speed;
    127         }
    128 
    129         return NULL;
    130 }
    131 
    132 /* Gets the interface ipv4 address from a meta packet
    133  *
    134  * @params libtrace_packet_t packet
    135  * @returns A pointer to the IP4 address field within the packet or NULL
    136  */
    137 uint32_t *trace_get_interface_ip4(libtrace_packet_t *packet) {
     118        return NULL;
     119}
     120
     121/* Get the interface ipv4 address/s
     122 * Must be destroyed with trace_destroy_meta()
     123 *
     124 * @params libtrace_packet_t meta packet
     125 * @returns Pointer to libtrace_meta_t structure or NULL
     126 */
     127libtrace_meta_t *trace_get_interface_ip4(libtrace_packet_t *packet) {
    138128        if (trace_meta_check_input(packet, "trace_get_interface_ip4()")<0) {
    139129                return NULL;
    140130        }
    141131
    142         void *ptr = NULL;
    143 
    144         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    145                 ptr = packet->trace->format->get_meta_data(packet,
     132        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     133                return packet->trace->format->get_meta_section_item(packet,
    146134                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_IPV4);
    147135        }
    148136        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    149                 ptr = packet->trace->format->get_meta_data(packet,
     137                return packet->trace->format->get_meta_section_item(packet,
    150138                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_IP4);
    151139        }
    152140
    153         if (ptr != NULL) {
    154                 uint32_t *intip4 = (uint32_t *)(ptr+sizeof(libtrace_meta_result_t));
    155                 packet->meta.interface_ipv4 = *intip4;
    156                 return &packet->meta.interface_ipv4;
    157         }
    158 
    159         return NULL;
    160 }
    161 uint32_t *trace_get_interface_ipv4(libtrace_packet_t *packet) {
     141        return NULL;
     142}
     143libtrace_meta_t *trace_get_interface_ipv4(libtrace_packet_t *packet) {
    162144        return trace_get_interface_ip4(packet);
    163145}
    164146
    165 void *trace_get_interface_ip6(libtrace_packet_t *packet) {
     147/* Get the interface ipv6 address/s
     148 * Must be destroyed with trace_destroy_meta()
     149 *
     150 * @params libtrace_packet_t meta packet
     151 * @returns Pointer to libtrace_meta_t structure or NULL
     152 */
     153libtrace_meta_t *trace_get_interface_ip6(libtrace_packet_t *packet) {
    166154        if (trace_meta_check_input(packet, "trace_get_interface_ip6()")<0) {
    167155                return NULL;
    168156        }
    169157
    170         void *ptr = NULL;
    171 
    172         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    173                 ptr = packet->trace->format->get_meta_data(packet,
     158        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     159                return packet->trace->format->get_meta_section_item(packet,
    174160                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_IPV4);
    175161        }
    176162        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    177                 ptr = packet->trace->format->get_meta_data(packet,
     163                return packet->trace->format->get_meta_section_item(packet,
    178164                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_IP4);
    179165        }
    180166
    181         if (ptr != NULL) {
    182                 packet->meta.interface_ipv6 = ptr+sizeof(libtrace_meta_result_t);
    183                 return packet->meta.interface_ipv6;
    184         }
    185 
    186         return NULL;
    187 }
    188 void *trace_get_interface_ipv6(libtrace_packet_t *packet) {
     167        return NULL;
     168}
     169libtrace_meta_t *trace_get_interface_ipv6(libtrace_packet_t *packet) {
    189170        return trace_get_interface_ip6(packet);
    190171}
    191172
    192 /* Gets the interface description for a packet
    193  *
    194  * @params libtrace_packet_t packet
    195  * @returns A pointer to a NULL terminated interface description string or NULL
    196  */
    197 char *trace_get_interface_description(libtrace_packet_t *packet) {
     173/* Get the interface description/s
     174 * Must be destroyed with trace_destroy_meta()
     175 *
     176 * @params libtrace_packet_t meta packet
     177 * @returns Pointer to libtrace_meta_t structure or NULL
     178 */
     179libtrace_meta_t *trace_get_interface_description(libtrace_packet_t *packet) {
    198180        if (trace_meta_check_input(packet, "trace_get_interface_description()")<0) {
    199181                return NULL;
    200182        }
    201183
    202         if (packet->meta.interface_description != NULL) {
    203                 free(packet->meta.interface_description);
    204                 packet->meta.interface_description = NULL;
    205         }
    206 
    207         void *ptr = NULL;
    208 
    209         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    210                 ptr = packet->trace->format->get_meta_data(packet,
     184        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     185                return packet->trace->format->get_meta_section_item(packet,
    211186                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_DESCR);
    212187        }
    213188        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    214                 ptr = packet->trace->format->get_meta_data(packet,
     189                return packet->trace->format->get_meta_section_item(packet,
    215190                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_DESCR);
    216191        }
    217192
    218         if (ptr != NULL) {
    219                 libtrace_meta_result_t *result = (libtrace_meta_result_t *)ptr;
    220                 packet->meta.interface_description = malloc(ntohs(result->len)+1);
    221                 packet->meta.interface_description[ntohs(result->len)] = '\0';
    222                 memcpy(packet->meta.interface_description, ptr+sizeof(libtrace_meta_result_t),
    223                         ntohs(result->len));
    224 
    225                 return packet->meta.interface_description;
    226         }
    227 
    228         return NULL;
    229 }
    230 
    231 /* Gets the interface number for the packet
    232  *
    233  * @params libtrace_packet_t packet
    234  * @returns A void pointer to the beginning of a uint32_t interface number;
    235  */
    236 uint32_t *trace_get_interface_num(libtrace_packet_t *packet) {
     193        return NULL;
     194}
     195
     196/* Get the interface number/s
     197 * Must be destroyed with trace_destroy_meta()
     198 *
     199 * @params libtrace_packet_t meta packet
     200 * @returns Pointer to libtrace_meta_t structure or NULL
     201 */
     202libtrace_meta_t *trace_get_interface_num(libtrace_packet_t *packet) {
    237203        if (trace_meta_check_input(packet, "trace_get_interface_num()")<0) {
    238204                return NULL;
    239205        }
    240206
    241         void *ptr = NULL;
    242 
    243         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    244                 ptr = packet->trace->format->get_meta_data(packet,
     207        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     208                return packet->trace->format->get_meta_section_item(packet,
    245209                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_IF_NUM);
    246210        }
    247211        /* Note: pcapng doesnt provide this */
    248212
    249         if (ptr != NULL) {
    250                 uint32_t *intnum = (uint32_t *)(ptr+sizeof(libtrace_meta_result_t));
    251                 packet->meta.interface_num = *intnum;
    252                 return &packet->meta.interface_num;
    253         }
    254 
    255         return NULL;
    256 }
    257 
    258 /* Gets the host OS from a packets originating interface
    259  *
    260  * @params libtrace_packet_t packet
    261  * @returns A pointer to a NULL terminated string or NULL
    262  */
    263 char *trace_get_host_os(libtrace_packet_t *packet) {
     213        return NULL;
     214}
     215
     216/* Get the host OS
     217 * Must be destroyed with trace_destroy_meta()
     218 *
     219 * @params libtrace_packet_t meta packet
     220 * @returns Pointer to libtrace_meta_t structure or NULL
     221 */
     222libtrace_meta_t *trace_get_host_os(libtrace_packet_t *packet) {
    264223        if (trace_meta_check_input(packet, "trace_get_host_os()")<0) {
    265224                return NULL;
    266225        }
    267226
    268         if (packet->meta.host_os != NULL) {
    269                 free(packet->meta.host_os);
    270                 packet->meta.host_os = NULL;
    271         }
    272 
    273         void *ptr = NULL;
    274 
    275         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    276                 ptr = packet->trace->format->get_meta_data(packet,
     227        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     228                return packet->trace->format->get_meta_section_item(packet,
    277229                        ERF_PROV_SECTION_HOST, ERF_PROV_OS);
    278230        }
    279231        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    280                 ptr = packet->trace->format->get_meta_data(packet,
     232                return packet->trace->format->get_meta_section_item(packet,
    281233                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_OS);
    282234        }
    283235
    284         if (ptr != NULL) {
    285                 libtrace_meta_result_t *result = (libtrace_meta_result_t *)ptr;
    286                 packet->meta.host_os = malloc(ntohs(result->len)+1);
    287                 packet->meta.host_os[ntohs(result->len)] = '\0';
    288                 memcpy(packet->meta.host_os, ptr+sizeof(libtrace_meta_result_t),
    289                         ntohs(result->len));
    290 
    291                 return packet->meta.host_os;
    292         }
    293 
    294         return NULL;
    295 }
    296 
    297 /* Gets the frame check sequence length from a packets originating interface
    298  *
    299  * @params libtrace_packet_t packet
    300  * @returns A uint32_t pointer containing the fcslen or NULL
    301  */
    302 uint32_t *trace_get_interface_frame_check_sequence_length(libtrace_packet_t *packet) {
     236        return NULL;
     237}
     238
     239/* Get the frame check sequence length
     240 * Must be destroyed with trace_destroy_meta()
     241 *
     242 * @params libtrace_packet_t meta packet
     243 * @returns Pointer to libtrace_meta_t structure or NULL
     244 */
     245libtrace_meta_t *trace_get_interface_frame_check_sequence_length(libtrace_packet_t *packet) {
    303246        if (trace_meta_check_input(packet, "trace_get_interface_frame_check_sequence_length()")<0) {
    304247                return NULL;
    305248        }
    306249
    307         void *ptr = NULL;
    308 
    309         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    310                 ptr = packet->trace->format->get_meta_data(packet,
     250        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     251                return packet->trace->format->get_meta_section_item(packet,
    311252                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_FCS_LEN);
    312253        }
    313254        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    314                 ptr = packet->trace->format->get_meta_data(packet,
     255                return packet->trace->format->get_meta_section_item(packet,
    315256                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_FCSLEN);
    316257        }
    317258
    318         if (ptr != NULL) {
    319 
    320                 if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    321                         uint32_t *val = (uint32_t *)(ptr+sizeof(libtrace_meta_result_t));
    322                         packet->meta.interface_fcslen = *val;
    323                 } else if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    324                         uint8_t *val = (uint8_t *)(ptr+sizeof(libtrace_meta_result_t));
    325                         packet->meta.interface_fcslen = *val;
    326                 }
    327                 return &packet->meta.interface_fcslen;
    328         }
    329 
    330         return NULL;
    331 }
    332 
    333 char *trace_get_interface_hardware_description(libtrace_packet_t *packet) {
     259        return NULL;
     260}
     261
     262/* Get the hardware description
     263 * Must be destroyed with trace_destroy_meta()
     264 *
     265 * @params libtrace_packet_t meta packet
     266 * @returns Pointer to libtrace_meta_t structure or NULL
     267 */
     268libtrace_meta_t *trace_get_interface_hardware_description(libtrace_packet_t *packet) {
    334269        if (trace_meta_check_input(packet, "trace_get_interface_hardware_description()")<0) {
    335270                return NULL;
    336271        }
    337272
    338         if (packet->meta.interface_hardware_desc != NULL) {
    339                 free(packet->meta.interface_hardware_desc);
    340                 packet->meta.interface_hardware_desc = NULL;
    341         }
    342 
    343         void *ptr = NULL;
    344 
    345273        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    346                 ptr = packet->trace->format->get_meta_data(packet,
     274                return packet->trace->format->get_meta_section_item(packet,
    347275                        PCAPNG_INTERFACE_TYPE, PCAPNG_META_IF_HARDWARE);
    348276        }
    349277        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    350                 ptr = packet->trace->format->get_meta_data(packet,
     278                return packet->trace->format->get_meta_section_item(packet,
    351279                        ERF_PROV_SECTION_MODULE, ERF_PROV_MODEL);
    352280        }
    353281
    354         if (ptr != NULL) {
    355                 libtrace_meta_result_t *result = (libtrace_meta_result_t *)ptr;
    356                 packet->meta.interface_hardware_desc = malloc(ntohs(result->len)+1);
    357                 packet->meta.interface_hardware_desc[ntohs(result->len)] = '\0';
    358                 memcpy(packet->meta.interface_hardware_desc, ptr+sizeof(libtrace_meta_result_t),
    359                         ntohs(result->len));
    360 
    361                 return packet->meta.interface_hardware_desc;
    362         }
    363 
    364         return NULL;
    365 }
    366 
    367 char *trace_get_interface_comment(libtrace_packet_t *packet) {
     282        return NULL;
     283}
     284
     285/* Get any interface comments for a meta packet
     286 * Must be destroyed with trace_destroy_meta()
     287 *
     288 * @params libtrace_packet_t packet
     289 * @returns Pointer to libtrace_meta_t structure or NULL
     290 */
     291libtrace_meta_t *trace_get_interface_comment(libtrace_packet_t *packet) {
    368292        if (trace_meta_check_input(packet, "trace_get_interface_comment()")<0) {
    369293                return NULL;
    370294        }
    371295
    372         if (packet->meta.interface_comment != NULL) {
    373                 free(packet->meta.interface_comment);
    374                 packet->meta.interface_comment = NULL;
    375         }
    376 
    377         void *ptr = NULL;
    378 
    379         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    380                 ptr = packet->trace->format->get_meta_data(packet,
     296        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     297                return packet->trace->format->get_meta_section_item(packet,
    381298                        ERF_PROV_SECTION_INTERFACE, ERF_PROV_COMMENT);
    382299        }
    383300        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    384                 ptr = packet->trace->format->get_meta_data(packet,
     301                return packet->trace->format->get_meta_section_item(packet,
    385302                        PCAPNG_INTERFACE_TYPE, PCAPNG_OPTION_COMMENT);
    386303        }
    387304
    388         if (ptr != NULL) {
    389                 libtrace_meta_result_t *result = (libtrace_meta_result_t *)ptr;
    390                 packet->meta.interface_comment = malloc(ntohs(result->len)+1);
    391                 packet->meta.interface_comment[ntohs(result->len)] = '\0';
    392                 memcpy(packet->meta.interface_comment, ptr+sizeof(libtrace_meta_result_t),
    393                         ntohs(result->len));
    394 
    395                 return packet->meta.interface_comment;
    396         }
    397 
    398         return NULL;
    399 }
    400 
    401 char *trace_get_capture_application(libtrace_packet_t *packet) {
     305        return NULL;
     306}
     307
     308/* Get the capture application for a meta packet
     309 * Must be destroyed with trace_destroy_meta()
     310 *
     311 * @params libtrace_packet_t packet
     312 * @returns Pointer to libtrace_meta_t structure or NULL
     313 */
     314libtrace_meta_t *trace_get_capture_application(libtrace_packet_t *packet) {
    402315        if (trace_meta_check_input(packet, "trace_get_interface_comment()")<0) {
    403316                return NULL;
    404317        }
    405318
    406         if (packet->meta.capture_application != NULL) {
    407                 free(packet->meta.capture_application);
    408                 packet->meta.capture_application = NULL;
    409         }
    410 
    411         void *ptr = NULL;
    412 
    413         if (packet->trace->format->type == TRACE_FORMAT_ERF) {
    414                 ptr = packet->trace->format->get_meta_data(packet,
     319        if (packet->trace->format->type == TRACE_FORMAT_ERF) {
     320                return packet->trace->format->get_meta_section_item(packet,
    415321                        ERF_PROV_SECTION_CAPTURE, ERF_PROV_APP_NAME);
    416322        }
    417323        if (packet->trace->format->type == TRACE_FORMAT_PCAPNG) {
    418                 ptr = packet->trace->format->get_meta_data(packet,
     324                return packet->trace->format->get_meta_section_item(packet,
    419325                        PCAPNG_SECTION_TYPE, PCAPNG_META_SHB_USERAPPL);
    420326        }
    421327
    422         if (ptr != NULL) {
    423                 libtrace_meta_result_t *result = (libtrace_meta_result_t *)ptr;
    424                 packet->meta.capture_application = malloc(ntohs(result->len)+1);
    425                 packet->meta.capture_application[ntohs(result->len)] = '\0';
    426                 memcpy(packet->meta.capture_application, ptr+sizeof(libtrace_meta_result_t),
    427                         ntohs(result->len));
    428 
    429                 return packet->meta.capture_application;
    430         }
    431 
    432328        return NULL;
    433329}
    434330
    435 
     331/* Get meta section option from a meta packet
     332 * Must be destroyed with trace_destroy_meta()
     333 *
     334 * @params libtrace_packet_t packet
     335 * @params Section code
     336 * @params Option code
     337 * @returns Pointer to libtrace_meta_t structure or NULL
     338 */
     339libtrace_meta_t *trace_get_section_option(libtrace_packet_t *packet, uint32_t section_code,
     340        uint16_t option_code) {
     341
     342        if (trace_meta_check_input(packet, "trace_get_custom_meta()")<0) {
     343                return NULL;
     344        }
     345
     346        return packet->trace->format->get_meta_section_item(packet,
     347                section_code, option_code);
     348}
     349
     350/* Get a section from a meta packet
     351 * Must be destroyed with trace_destroy_meta()
     352 *
     353 * @params libtrace_packet_t packet
     354 * @params Section code
     355 * @returns Pointer to libtrace_meta_t structure or NULL
     356 */
     357libtrace_meta_t *trace_get_section(libtrace_packet_t *packet, uint32_t section_code) {
     358        if (trace_meta_check_input(packet, "trace_get_section()")<0) {
     359                return NULL;
     360        }
     361
     362        return packet->trace->format->get_meta_section(packet, section_code);
     363}
Note: See TracChangeset for help on using the changeset viewer.