What would be the recommended steps to build a Nim binding for a C library like libpcap? Running c2nim 0.9.7 on pcap/pcap.h from libpcap-1.7.3 produces a pcap.nim file (after one minor fix). But I get lots of errors when trying to compile a simple Nim program that imports that module.
Should I try to fix the errors one by one, making changes to the pcap.nim file until everything compiles and works? Or would it be better to first clean up the pcap.nim file, throwing everything away that I do not absolutely need? Or should I create the binding from scratch? How were the existing Nim bindings for C libraries created?
I think bindings for libpcap and libdnet could make it possible to develop high-performance Nim alternatives for Python based packet crafting and sniffing tools like Scapy.
Here is the pcap.nim file generated by c2nim: https://www.dropbox.com/s/xi3lth34re1w0as/pcap.nim?dl=0
The minimal test file I am trying to compile:
from pcap import pcap_open_offline
discard pcap_open_offline("ping.pcap")
Some errors I get:
pcap.nim(39, 3) Error: invalid indentation
pcap.nim(161, 25) Error: invalid indentation
pcap.nim(340, 51) Error: invalid token: _ (\95)
pcap.nim(411, 22) Error: invalid token: _ (\95)
pcap.nim(57, 8) Error: undeclared identifier: 'BPF_RELEASE'
...
(the later ones only after I fix the former ones, of course)Questions:
Resources I have found helpful: