[Winpcap-users] pcap_fopen_offline not exported?

Fish fish at infidels.org
Thu Jul 24 16:36:00 GMT 2008


 
-----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)

- -- 
"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-----



More information about the Winpcap-users mailing list