I have a callback function called got_packet:
void got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) {
WMShark *shark = (WMShark *)args;
WMPacket *foundPacket = [[WMPacket alloc] init];
foundPacket.packetNumber = [[shark capturedPackets] count];
foundPacket.timeStamp = header.ts; // <-- PROBLEM IS HERE
...
NSLog(@"%@: %s", shark, packet);
}
I get a compile error error: request for member 'ts' in something not a structure or union on the line foundPacket.timeStamp = header.ts;.
The documentation says:
…
a const struct pcap_pkthdr pointer to a structure with the following mem-bers:
- ts — a struct timeval containing the time when the packet was captured
…
How can I access ts? Thanks.
For the die-hard C-developers, the square brackets are used in Objective-C, a superset of C. You can ignore this, they’re initializers in this case.
As you’ve the pointer to the struct, use the
->operator instead of.: