Assign a pcap_t* File Descriptor to a Chunk of Memory?

强颜欢笑 提交于 2021-01-29 07:06:12

问题


I’ve written a C program which write a valid PCAP file into a malloc’ed chunk of memory:

u_char* myPCAP = writePCAP( ... );

The program works wonderfully, and if I write myPCAP to a file, I can read that file in Wireshark and everything. So I know that everything is working. But now, I want to assign myPCAP a pcap_t* file descriptor and pass that FD to another program. (nDPI, for those who are curious.) How could I do this? I was hoping this would work:

pcap_t* pcap = fdopen( ((int*)myPCAP), "r" );

But:

me@ubuntu:/home/me#  make all
gcc -g -fPIC -DPIC -I../src/include -g -O2 -c MyCode.c -o MyCode.o
MyCode.c: In function ‘msgHandler’:
MyCode.c:750:34: warning: passing argument 1 of ‘fdopen’ makes integer from pointer without a cast [-Wint-conversion]
  pcap_t* pcap = (pcap_t*)fdopen( ((int*)myPCAP), "r" );
                                  ^
In file included from MyCode.c:16:0:
/usr/include/stdio.h:265:14: note: expected ‘int’ but argument is of type ‘int *’
 extern FILE *fdopen (int __fd, const char *__modes) __THROW __wur;
              ^~~~~~
g++ -g -fPIC -DPIC -I../src/include -g -O2 MyCode.o libndpiReader.a -o ndpiReader ../src/lib/libndpi.a -lpcap  -lpthread -lm
me@ubuntu:/home/me#  

Anyone see a solution? There’s got to be a way, right? Thank you.

来源:https://stackoverflow.com/questions/63784671/assign-a-pcap-t-file-descriptor-to-a-chunk-of-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!