Closed Wojtek242 closed 2 years ago
I think the Result<Options<Device>, Error>
return type makes more sense to me, especially since it matches what libpcap does. I'm not sure about a prettier way to do it, but the end result type works for me.
In this PR I remove wstr_to_string
as the need for it came from a bug in the now obsolete pcap_lookupdev
:
In WinPcap and Npcap, this function may return a UTF-16 string rather than an ASCII or UTF-8 string. From https://npcap.com/guide/wpcap/pcap_lookupdev.html
This does not seem to apply to pcap_findalldevs
on Windows: https://npcap.com/guide/wpcap/pcap_findalldevs.html
Therefore, this also closes #165.
Turns out there's already an example of using
findalldevs
inpcap
. It was in the function belowlist
.However, by removing
lookupdev
I realised that the case of no default device was not handled at all. I've currently handled this by returning aResults<Option<Device>, Error>
as opposed to aResult<Device, Error>
.A possible alternative would be to translate the null option to an error, but that would be semantically different from what libpcap does which does not consider the null case to be an error.
Currently a draft PR, because I want to have a think if there's a slightly prettier solution.
Closes #158