27.06.2013 Views

Untitled

Untitled

Untitled

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

IP number (for example Ox7FOOOOO I is 127.0.0. 1). So how do we convert the result in host->h3ddr<br />

given by gethostbyname(3)? Easy, we'll just cast the host->h_addr with *(long *)(host->h_addr). Fi­<br />

nally, don't fo rget to use the htons(3) to convert it to revers byte order on x86. And the addrlen argu­<br />

ment is just sizeof(sockaddr). We will have to cast our sockaddr_in variable to a sockaddr struct when<br />

passing it to connect(2). And of course, one final thing, don't forget to close down your socket. Use<br />

close(2) with your socket as argument. Like: close(s) (The definition of close(2) is found in<br />

.)<br />

Writing The Code<br />

Now when your fingertips are itching to get down to business don't let me hold you back. Yo u<br />

should without problem be able to write a portscanner or anything else - only your imagination sets the<br />

limit. No guide is complete without that final piece of source code, so here it is:<br />

portscan. c<br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#include <br />

#defi ne START<br />

#define STOP 1024<br />

void main(int argc, char " argv) {<br />

tnt 5,port;<br />

struct hostent 'host;<br />

struct sockaddr_in victim;<br />

printf("PortScan v1.0 - By darknite[@kurir.net]\n");<br />

printfC"For his socket-programming article in 1998\n");<br />

if (argc

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!