From c9be993efdc85c5318658a615d09d67ecaea6ab6 Mon Sep 17 00:00:00 2001 From: Jack Halford Date: Wed, 27 Sep 2017 19:34:04 +0200 Subject: [PATCH] day --- nmap/includes/nmap.h | 3 +-- nmap/srcs/main.c | 4 ++-- nmap/srcs/nmap.c | 13 +++++++++---- nmap/srcs/parser.c | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/nmap/includes/nmap.h b/nmap/includes/nmap.h index 3a4a9c80..a1271171 100644 --- a/nmap/includes/nmap.h +++ b/nmap/includes/nmap.h @@ -54,7 +54,6 @@ struct s_data struct sockaddr source_addr; int ports[USHRT_MAX + 1]; int threads; - int src_port; int scan; }; @@ -79,7 +78,7 @@ enum e_port_status struct s_host { - char *node; // user inputed node (ip or dn) + char *host; // user input host (ip or dn) char *dn; // ai_canonname char ip[INET6_ADDRSTRLEN]; // readable ip address (4 or 6) int sock_tcp; diff --git a/nmap/srcs/main.c b/nmap/srcs/main.c index 96f9e93f..22af1671 100644 --- a/nmap/srcs/main.c +++ b/nmap/srcs/main.c @@ -27,8 +27,8 @@ int main(int ac, char **av) } int port_chan = chmake(sizeof(int)); go(nmap_listener(&data)); - go(nmap_ports(&data, port_chan)); + /* go(nmap_ports(&data, port_chan)); */ /* go(nmap_collector(&data)); */ - nmap(&data); + int chan = nmap(&data); return (0); } diff --git a/nmap/srcs/nmap.c b/nmap/srcs/nmap.c index 64081751..523d6a96 100644 --- a/nmap/srcs/nmap.c +++ b/nmap/srcs/nmap.c @@ -14,17 +14,17 @@ unsigned short cksum(void *b, int len) return (~(sum + (sum >> 16))); } -coroutine void nmap_scan_port(t_data *data, struct iphdr *iph, int port) +coroutine void nmap_scan_node(t_host *host, struct iphdr *iph, int port) { int channel; t_tcp_packet packet; - channel = data.channels[port]; + channel = host.channels[port]; packet.iph = *iph; tcphdr_init(&packet.tcph); packet.tcph.dest = htons(port); - packet.tcph.source = htons(data->src_port); + packet.tcph.source = ; /* packet.tcph.syn = 1; */ packet.tcph.check = cksum(&packet, sizeof(t_tcp_packet)); @@ -58,6 +58,7 @@ void nmap(t_data *data) iph.saddr = *(uint32_t*)&((struct sockaddr_in*)&data->source_addr)->sin_addr; iph.tot_len = htons(sizeof(t_tcp_packet)); + int fan_in = chmake(); for (t_list *list = data->host; list != NULL; list = list->next) { t_host *host = list->content; @@ -65,7 +66,11 @@ void nmap(t_data *data) for (port = 1; port < USHRT_MAX; port++;) { if (data.ports[port]) - go(nmap_scan_port(data, iph, port)); + { + int fan_in_local = hdup(fan_in); + go(nmap_scan_node(data, iph, port, fan_in_local)); + } } } + return (fan_in); } diff --git a/nmap/srcs/parser.c b/nmap/srcs/parser.c index bb1965ac..f0e15e6d 100644 --- a/nmap/srcs/parser.c +++ b/nmap/srcs/parser.c @@ -27,7 +27,7 @@ static int nmap_get_host(char *node, t_data *data) } host.addr = servinfo->ai_addr; host.addrlen = servinfo->ai_addrlen; - host.node = node; + host.host = node; host.dn = servinfo->ai_canonname; void *addr;