Bill Fischofer(Bill-Fischofer-Linaro) replied on github web page:

platform/linux-generic/odp_packet_io.c
line 76
@@ -89,6 +96,274 @@ int odp_pktio_init_local(void)
        return odp_pktio_ops_init_local(true);
 }
 
+static int write_pcapng_hdr(pktio_entry_t *entry, int qidx)
+{
+       size_t len;
+       pcapng_section_hdr_block_t shb;
+       pcapng_interface_description_block_s idb;
+       int fd = entry->s.pcapng_info.pcapng_fd[qidx];
+
+       memset(&shb, 0, sizeof(shb));
+       memset(&idb, 0, sizeof(idb));
+
+       shb.block_type = PCAPNG_BLOCK_TYPE_SHB;
+       shb.block_total_length = sizeof(shb);
+       shb.block_total_length2 = sizeof(shb);
+       shb.magic = PCAPNG_ENDIAN_MAGIC;
+       shb.version_major = 0x1;
+       shb.version_minor = 0x0;
+       shb.section_len = -1;
+
+       len = write(fd, &shb, sizeof(shb));
+       fsync(fd);
+       /* fail to write shb/idb means the pcapng is unreadable */
+       if (!len) {
+               ODP_ERR("Failed to write pcapng section hdr\n");
+               close(fd);
+               return -1;
+       }
+
+       idb.block_type = PCAPNG_BLOCK_TYPE_IDB;
+       idb.block_total_length = sizeof(idb);
+       idb.block_total_length2 = sizeof(idb);
+       idb.linktype = 0x1; /* LINKTYPE_ETHERNET */
+       idb.snaplen = 0x0; /* unlimited */
+       len = write(fd, &idb, sizeof(idb));
+       if (!len) {
+               ODP_ERR("Failed to write pcapng interface description\n");
+               close(fd);
+               return -1;
+       }
+       fsync(fd);
+
+       entry->s.pcapng_info.state[qidx] = PCAPNG_WR_HDR;
+
+       return 0;
+}
+
+static int write_pcapng_pkts(pktio_entry_t *entry, int qidx,
+                            const odp_packet_t packets[], int num)
+{
+       int i = 0;
+       struct iovec packet_iov[3 * num];
+       pcapng_enhanced_packet_block_t epb;
+       int iovcnt = 0;
+       ssize_t len = 0;
+       int fd = entry->s.pcapng_info.pcapng_fd[qidx];
+
+       for (i = 0; i < num; i++) {
+               odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(packets[i]);
+               uint32_t pkt_len = _odp_packet_len(packets[i]);
+               char *buf = (char *)odp_packet_data(packets[i]);


Comment:
This fails for multi-segment packets. `odp_packet_data(pkt)` is shorthand for 
`odp_packet_offset(pkt, 0, NULL, NULL)` so you don't know how long the first 
segment really is. First cut would be to only dump the first segment, so 
correct code is:
```
uint32_t seg_len;
char *buf = (char *)odp_packet_offset(packets[i], 0, &seg_len, NULL);
```
And use `seg_len` rather than `pkt_len` in this routine.

> Bill Fischofer(Bill-Fischofer-Linaro) wrote:
> Does pcapng not supply a `.h` file for these "magic numbers" and associated 
> structs?


>> Ilias Apalodimas(apalos) wrote:
>> Will fix. This will also remove the requirement of manually deleting the 
>> fifos


>>> muvarov wrote
>>> odp_global_data_s->main_pid needs to be here.


https://github.com/Linaro/odp/pull/435#discussion_r165547875
updated_at 2018-02-02 03:09:47

Reply via email to