我正在使用C++中的pcap
库到sniff
网络流量。 在pcap
库pcap_if_t
是struct
如下:在C++中将pcap_if_t *转换为pcap_if_t **
struct pcap_if {
struct pcap_if *next;
char *name; /* name to hand to "pcap_open_live()" */
char *description; /* textual description of interface, or NULL */
struct pcap_addr *addresses;
bpf_u_int32 flags; /* PCAP_IF_ interface flags */
};
typedef struct pcap_if pcap_if_t;
现在,我感到困惑在int pcap_findalldevs(pcap_if_t **, char *);
原型使用&alldevs
值作为在波纹管代码中的第一个值。而pcap_if_t *alldevs
是一个指针,与pcap_if_t **
参数(它是指向另一个指针的指针)不匹配。
pcap_if_t *alldevs;
char errbuf[PCAP_ERRBUF_SIZE];
/* Retrieve the device list from the local machine */
if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
exit(1);
}
例如甚至,i相int **arr
语句来测试“指针指针”(指针的链)。我定义int **arr
作为matrix
:
int **arr = new int*[5];
for(int i = 0; i < 5; i++)
{
arr[i] = new int[3];
}
然后定义void print_arr(int **arr, int r, int c)
功能,由于打印matrix
值,并给它的两个不同参数(arr
和&arr2
):
int *arr2 = static_cast<int*>(*arr);
print_arr(arr, 5, 3); // arr defined in top
print_arr(&arr2, 5, 4); // arr2 is a pointer as *arr2
不管提供示例的,c++
如何与此转换行为?它有一些含糊不清的意识。
'&'得到的*地址*什么东西(指向它)...这应该包括在任何初学者级别的C++书籍或教程... – Dmitri