* WinPCap/LibPCap Wrappers?
@ 2009-08-26 15:43 John McCabe
2009-08-26 19:20 ` Per Sandberg
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: John McCabe @ 2009-08-26 15:43 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: WinPCap/LibPCap Wrappers?
2009-08-26 15:43 WinPCap/LibPCap Wrappers? John McCabe
@ 2009-08-26 19:20 ` Per Sandberg
2009-08-26 20:17 ` Björn
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Per Sandberg @ 2009-08-26 19:20 UTC (permalink / raw)
[-- Attachment #1: Type: text/plain, Size: 722 bytes --]
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
[-- Attachment #2: generate.py --]
[-- Type: text/plain, Size: 3037 bytes --]
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 <pcap.h>\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")
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: WinPCap/LibPCap Wrappers?
2009-08-26 15:43 WinPCap/LibPCap Wrappers? John McCabe
2009-08-26 19:20 ` Per Sandberg
@ 2009-08-26 20:17 ` Björn
2009-08-27 4:04 ` Steve D
2009-08-27 13:57 ` John McCabe
3 siblings, 0 replies; 5+ messages in thread
From: Björn @ 2009-08-26 20:17 UTC (permalink / raw)
On 26 Aug, 17:43, John McCabe <j...@nospam.assen.demon.co.uk> wrote:
> Does anyone know of an Ada wrapper to the WinPCap and/or libpcap
> libraries?
The following might be of help (only tested with libpcap):
http://www.mediafire.com/?sharekey=b27d9dbe9e00e3f4e62ea590dc5e5dbbe04e75f6e8ebb871
Regards,
Björn
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: WinPCap/LibPCap Wrappers?
2009-08-26 15:43 WinPCap/LibPCap Wrappers? John McCabe
2009-08-26 19:20 ` Per Sandberg
2009-08-26 20:17 ` Björn
@ 2009-08-27 4:04 ` Steve D
2009-08-27 13:57 ` John McCabe
3 siblings, 0 replies; 5+ messages in thread
From: Steve D @ 2009-08-27 4:04 UTC (permalink / raw)
"John McCabe" <john@nospam.assen.demon.co.uk> wrote in message
news:1ula95l72bdd6vn2ct4p2gjg5e3r4008n8@4ax.com...
> 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
The files are kind of big, but I have had wireshark dump the files as XML
(one of the options). It made it relatively easy to sift through data.
Regards,
Steve
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: WinPCap/LibPCap Wrappers?
2009-08-26 15:43 WinPCap/LibPCap Wrappers? John McCabe
` (2 preceding siblings ...)
2009-08-27 4:04 ` Steve D
@ 2009-08-27 13:57 ` John McCabe
3 siblings, 0 replies; 5+ messages in thread
From: John McCabe @ 2009-08-27 13:57 UTC (permalink / raw)
On Wed, 26 Aug 2009 16:43:16 +0100, John McCabe
<john@nospam.assen.demon.co.uk> 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 :-)
Thank you all for your help. I'll see what I can do with the
information you've supplied.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-08-27 13:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-26 15:43 WinPCap/LibPCap Wrappers? John McCabe
2009-08-26 19:20 ` Per Sandberg
2009-08-26 20:17 ` Björn
2009-08-27 4:04 ` Steve D
2009-08-27 13:57 ` John McCabe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox