[Winpcap-users] pcap_fopen_offline not exported?
Gianluca Varenni
gianluca.varenni at cacetech.com
Fri Jul 25 22:27:29 GMT 2008
----- Original Message -----
From: "Fish" <fish at infidels.org>
To: <winpcap-users at winpcap.org>
Sent: Thursday, July 24, 2008 9:36 AM
Subject: RE: [Winpcap-users] pcap_fopen_offline not exported?
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Okraszewski,Marcin wrote:
>
> [...]
>> Maybe Winpcap could export an alternative function which
>> would work on file descriptor?
>
> No. Use Win32 HANDLEs instead, not CRT file descriptors.
>
>
>> This shouldn't have the CRT compatibility issues. It
>> could look like this:
>
> Actually it will. :(
>
>
>> pcap_t* pcap_fdopen_offline(int fd, char *errorbuf) {
>> FILE *file = _fdopen(fd, "rb");
>> if ( file == NULL ) {
>> strerror_s(errorbuf, PCAP_ERRBUF_SIZE, errno);
>> return NULL;
>> }
>> return pcap_fopen_offline(file, errorbuf);
>> }
>>
>> Then also it could override pcap_fopen_offline calls with a macro:
>>
>> #define pcap_fopen_offline(file, errorbuf) \
>> pcap_fdopen_offline(_fileno(file), errorbuf)
>>
>> This together would make it compatible with libpcap.
>
> Actually it won't, but you're on the right track.
>
> Try this instead:
>
>
> pcap_t* pcap_openw32_offline(HANDLE h, char *errorbuf) {
> int fd = _open_osfhandle(h);
> FILE *file = _fdopen(fd, "rb");
> if ( file == NULL ) {
> strerror_s(errorbuf, PCAP_ERRBUF_SIZE, errno);
> return NULL;
> }
> return pcap_fopen_offline(file, errorbuf);
> }
>
>
> (p.s. the're also "_get_osfhandle" too in case you need it)
>
this could work as long as you can get a FILE* handle out of a win32 HANDLE.
I've never tried myself, it looks a bit scary to me...
Have a nice day
GV
> - --
> "Fish" (David B. Trout) - fish(at)infidels.org
> Fight Spam! Join CAUCE! <http://www.cauce.org/>
> (Any HTML email received will be deleted unread)
> PGP key fingerprints:
> RSA: 6B37 7110 7201 9917 9B0D 99E3 55DB 5D58 FADE 4A52
> DH/DSS: 9F9B BAB0 BA7F C458 1A89 FE26 48F5 D7F4 C4EE 3E2A
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGP 8.1
>
> iQA/AwUBSIivb0j11/TE7j4qEQKxGwCg9vkWlLjLy7+uAZc4I+9qCq5DCEQAoPBf
> bdpgKPjKLjBYI09Id3hyr4cN
> =EzOh
> -----END PGP SIGNATURE-----
>
> _______________________________________________
> Winpcap-users mailing list
> Winpcap-users at winpcap.org
> https://www.winpcap.org/mailman/listinfo/winpcap-users
More information about the Winpcap-users
mailing list