**ptr and ptr or *ptr and &ptr?
Ehlo.
I came back to programming in C after more than a few years and there's a piece of code I'm not sure I understand correctly. It's a couple of lines of code regarding libpcap. What it does it runs a pcap function to get the list of available devices:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <pcap.h>
int main(void) {
char ebuf[PCAP_ERRBUF_SIZE];
pcap_if_t *devs;
pcap_findalldevs(&devs, ebuf);
exit(EXIT_SUCCESS);
}
This is the way it's supposed to be done. However, when I first saw this function's prototype:
int pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf);
I assumed that this code would work as well:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <pcap.h>
int main(void) {
char ebuf[PCAP_ERRBUF_SIZE];
pcap_if_t **devs;
pcap_findalldevs(devs, ebuf);
exit(EXIT_SUCCESS);
}
It does compile but segfaults on execution. I think I know why but I don't want to suggest any particular point of view so, if you know the answer then....well, answer. :)
Cheers.