Skip to content Skip to sidebar Skip to footer

How To Embed C Code In Python Program?

i want to write a program using multi-threading, raw sockets, to scan the ports in python i have a C code for injection of raw socket. i want to perform a ACK scan so need a raw so

Solution 1:

Please check out Cython. It makes it very easy to wrap C code.

This is adapted from the documentation on calling external C functions:

cdef extern from "math.h":
    doublesin(double)

def pysin(x):
    returnsin(x)

You could then call pysin from the compiled module like a normal Python module.

Solution 2:

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

Post a Comment for "How To Embed C Code In Python Program?"