From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,914d0af6079eec4b X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!feeder.news-service.com!cyclone01.ams2.highwinds-media.com!news.highwinds-media.com!npeersf01.ams.highwinds-media.com!newsfe30.ams2.POSTED!40385e62!not-for-mail From: Per Sandberg User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: WinPCap/LibPCap Wrappers? References: <1ula95l72bdd6vn2ct4p2gjg5e3r4008n8@4ax.com> In-Reply-To: <1ula95l72bdd6vn2ct4p2gjg5e3r4008n8@4ax.com> Content-Type: multipart/mixed; boundary="------------000002070204070700010103" Message-ID: X-Complaints-To: abuse@WWWSpace.NET NNTP-Posting-Date: Wed, 26 Aug 2009 20:23:04 UTC Date: Wed, 26 Aug 2009 21:20:14 +0200 Xref: g2news2.google.com comp.lang.ada:8008 Date: 2009-08-26T21:20:14+02:00 List-Id: This is a multi-part message in MIME format. --------------000002070204070700010103 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit If it helps her is an embryo for automatic generation of Low_Level Ada-bindings from header files. This one is specialized for pcap (to give a hint) but it is fairly simple to tweak for other targets. Just put it in a rewsonable directory and update the getRawSpecs function to reference the include dir. This is the quick hack version. /Per John McCabe wrote: > Hi > > Sorry to have to ask this here, but a web search was a bit fruitless! > > Does anyone know of an Ada wrapper to the WinPCap and/or libpcap > libraries? > > I'd like to be able to read in files created by Wireshark and > manipulate the data in a sensible way. I guess I could do it with C++, > but I'd much rather use Ada :-) > > Thanks > John --------------000002070204070700010103 Content-Type: text/plain; name="generate.py" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="generate.py" from subprocess import call from glob import glob; from os.path import * toRemove=[] renamePackages=[ # src Pac package Target Package ["pcap_h", "Pcap.Low_Level.Impl"], ["pcap_bpf_h", "Pcap.Low_Level.BPF"] ] renameTypedefs=[ # src type Target Type ["winsock2_h.u_short", "Interfaces.C.unsigned_short"], ["pcap_bpf_h.bpf_u_int32", "Interfaces.C.unsigned"], ["winsock2_h.u_int", "Interfaces.C.unsigned"], ["pcap_bpf_h.bpf_int32", "Interfaces.C.int"], ["winsock2_h.u_char", "Interfaces.C.unsigned_char"], ] withRemovals=[ # File import ["pcap_bpf_h", "winsock2_h"], ["pcap_h", "winsock2_h"] ] lineRemovals=[ "subtype pcap_if_t is pcap_if;", "subtype pcap_addr_t is pcap_addr;" ] def getRawSpecs(): call(["rm", "-rf", "*_h.ads"]) f=open("generate.h","w") f.write("#include \n") f.close() call(["g++", "-I", "../Include", "generate.h", "-fdump-ada-spec"]) call(["rm", "-rf", "*.gch", "generate.h"]) for i in toRemove: call(["rm",i]) def renameSimple(buffer): for i in renamePackages: buffer=buffer.replace(" " + i[0]+ " ", " " + i[1]+ " ") buffer=buffer.replace(" " + i[0]+ ";", " " + i[1]+ ";") buffer=buffer.replace(" " + i[0]+ ".", " " + i[1]+ ".") for i in renameTypedefs: buffer=buffer.replace(i[0],i[1]) for i in lineRemovals: buffer=buffer.replace(i,"-- " + i); return buffer def doRenameAll(): for i in glob("*_h.ads"): f=open(i) buffer=f.read() f.close() buffer=renameSimple(buffer) f=open(i + ".out","w") for tryRemove in withRemovals: if splitext(i)[0] == tryRemove[0]: for name in tryRemove[1:]: buffer=buffer.replace("with "+name + ";", "-- with "+name + ";") f.write(buffer) f.close() call(["gnatchop","-w",i+".out"]) def addRootpackages(packages): for i in packages: fname=i.lower().replace(".","-") + ".ads" if not exists(fname): f=open(fname,"w") f.write("package %(name)s is \n" + "end %(name)s;\n" % {"name" : i}) f.close() def cleanUp(): call(["rm" ,"*_h.ads", "*.out"]) projectTemplate="""project %(name)s is for Object_Dir use "obj"; package Builder is for Default_Switches ("ada") use ("-k", "-j4", "-g"); end Builder; package Compiler is for Default_Switches ("ada") use ("-g", "-gnatQ", "-gnatf", "-gnat05"); end Compiler; end %(name); """ def addProject(name): fname=name.lower().replace(".","-") + ".gpr" if not exists(fname): f=open(fname,"w") f.write(projectTemplate % {"name" : name}) f.close() # getRawSpecs() doRenameAll() # addRootpackages(["PCap","PCap.Low_Level"]) # addProject("PCap") --------------000002070204070700010103--