How to embed C code in a python program?

I want to write a program using multi-threaded, raw sockets to scan ports in python I have C code to insert a raw socket. I want to do an ACK check, so I need a raw socket.

So please help me.

Thank you

+4
source share
2 answers

Please view Cython . This makes porting C easy.

This is due to the documentation when calling external C functions :

cdef extern from "math.h": double sin(double) def pysin(x): return sin(x) 

Then you can call pysin from the compiled module, just like a regular Python module.

+4
source

I would definitely go with boost.python , which provides even cleaner wrappers. If you don't like the idea of ​​using C ++, then Cython is a good alternative.

0
source

All Articles