Search code examples
chping

How to use hping natively or with fork in C?


Searched via google a lot about this question but I can't figure out a solution for this. I am trying to implement an MPI portscanner using the gnu c hping library. Only problem is, the hping homepage is down, and the usage is for shell only. I want to use hping to check if a port is open or closed (three-way-tcp handshake successful or not).

Are there any examples for this?


Solution

  • You can execute hping and parse its output. Algorythm is simple:

    1. Use pipe() to create one-directional pipe
    2. Use fork() to create another process
    3. In child process:
    4. Use dup2() to substitute stdout by output end of pipe. Don't forget to close input end of pipe.
    5. Use execlp() to execute hping
    6. In parent process:
    7. hping output would be available in input end of pipe. Don't forget to close output end of pipe.