单线程的扫描,多线程待优化
#include "stdio.h"
#include "sys/socket.h"
#include "sys/time.h"
#include "sys/types.h"
#include "string.h"
#include "unistd.h"
#include "netdb.h"
#include "time.h"
#include "netinet/in.h"
#include "arpa/inet.h"
#include "stdlib.h"
#include "fcntl.h"
#define u_8 unsigned char
#define u_16 unsigned short
#define u_32 unsigned int
struct IPHEAD{
u_8 ver_hlen;
u_8 tos;
u_16 dlen;
u_16 id;
u_16 flag_index;
u_8 ttl;
u_8 proto;
u_16 checksum;
u_32 srcip;
u_32 desip;
};
struct TCPHEAD{
u_16 srcport;
u_16 desport;
u_32 seq;
u_32 ack;
u_8 hlen;//only 4 bit
u_8 flag;
u_16 recvwnd;
u_16 checksum;
u_16 ep;
};
struct PTCP{
u_32 srcip;
u_32 desip;
u_8 zero;
u_8 proto;
u_16 tcplen;
};
struct Port{
u_16 port;
Port* next;
};
struct PortScan{
#define BUFSIZE 1024*1024
//var
int sockraw;
hostent *ht;
sockaddr_in addr;
IPHEAD ip;
TCPHEAD tcp;
PTCP ptcp;
Port *ls;
char sendbuf[BUFSIZE],recvbuf[BUFSIZE];
int start,end;
//function
PortScan(int,int,char*);
int scan();
int fill_ip();
int fill_tcp();
int fill_ptcp();
int packet(int);
int unpacket(int);
u_16 checksum(u_16*,int);
int trav();
int append(int);
~PortScan();
};
u_16 PortScan::checksum(u_16*s,int size){
int i,sum=0;
for(i=