Changeset 7b4f5e2
- Timestamp:
- 02/05/19 14:41:55 (2 years ago)
- Branches:
- develop
- Children:
- 58c226e
- Parents:
- a0e5b65
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/format_pktmeta.c
ra0e5b65 r7b4f5e2 322 322 * 323 323 * @params libtrace_packet_t meta packet to extract the ipv4 address from. 324 * @params A pointer to a character buffer to store the ipv4 address string in.325 * @params The size of the buffer passed in.326 324 * @params The interface index within the meta packet. 327 325 * @returns Pointer to the character buffer containing the ipv4 address string or NULL. 328 326 */ 329 327 /* UNTESTED */ 330 char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, char *space, int spacelen, 331 int index) { 332 333 uint32_t addr = htonl(trace_get_interface_ipv4(packet, index)); 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); 334 333 if (addr == 0) { return NULL; } 335 334 336 char *addrstr = inet_ntoa(*(struct in_addr *)&addr); 337 memcpy(space, addrstr, spacelen); 338 space[spacelen] = '\0'; 339 return space; 335 ip.s_addr = addr; 336 337 return inet_ntoa(ip); 340 338 } 341 339 … … 404 402 int index) { 405 403 404 /* Ensure we have enough space */ 406 405 if (spacelen < INET6_ADDRSTRLEN) { 407 406 return NULL; 408 407 } 409 408 410 void *addr = calloc(1, 16);411 void *r = trace_get_interface_ipv6(packet, addr, 16, index); 412 409 struct sockaddr_in6 sa; 410 411 void *r = trace_get_interface_ipv6(packet, &(sa.sin6_addr), 16, index); 413 412 if (r == NULL) { 414 413 return NULL; 415 414 } 416 415 417 inet_ntop(AF_INET6, addr, space, INET6_ADDRSTRLEN);418 free(addr);416 /* get the string representation */ 417 inet_ntop(AF_INET6, &(sa.sin6_addr), space, INET6_ADDRSTRLEN); 419 418 420 419 return space; -
lib/libtrace.h.in
re0f2dca r7b4f5e2 3749 3749 DLLEXPORT uint32_t trace_get_interface_ipv4(libtrace_packet_t *packet, int index); 3750 3750 3751 DLLEXPORT char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, char *space, int spacelen, 3752 int index); 3751 DLLEXPORT char *trace_get_interface_ipv4_string(libtrace_packet_t *packet, int index); 3753 3752 3754 3753 DLLEXPORT libtrace_meta_t *trace_get_interface_ipv6_meta(libtrace_packet_t *packet);
Note: See TracChangeset
for help on using the changeset viewer.