How to use hping natively or with fork in C?

130 Views Asked by At

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?

1

There are 1 best solutions below

5
On BEST ANSWER

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.