简体   繁体   中英

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 socket.

So please help me.

thank you

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":
    double sin(double)

def pysin(x):
    return sin(x)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM