-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcis.c
164 lines (127 loc) · 3.3 KB
/
concis.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* auteur : John-Nathan HILL
* brief :
*/
#include <stdio.h>
#include <stdlib.h>
#include <pcap.h>
#include <errno.h>
#include <arpa/inet.h>
#include <netinet/if_ether.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include "concis.h"
#include "port.h"
void parse_port_concis(short source, short dest)
{
int port = 0;
switch(source){
case FTPC: printf("FTP:Client "); break;
case FTPS: printf("FTP:Serveur "); break;
case HTTP: printf("HTTP "); break;
case HTTPS: printf("HTTPS "); break;
case DNS: printf("DNS "); break;
case SMTP: printf("SMTP "); break;
case SMTPS: printf("SMTPS "); break;
case TELNET: printf("TELNET "); break;
case BOOTPS: printf("BOOTP:Serveur "); break;
case BOOTPC: printf("BOOTP:client "); break;
default: port++; break;
}
switch(dest){
case FTPC: printf("FTP:Client "); break;
case FTPS: printf("FTP:Serveur "); break;
case HTTP: printf("HTTP "); break;
case HTTPS: printf("HTTPS "); break;
case DNS: printf("DNS "); break;
case SMTP: printf("SMTP "); break;
case SMTPS: printf("SMTPS "); break;
case TELNET: printf("TELNET "); break;
case BOOTPS: printf("BOOTP:Serveur "); break;
case BOOTPC: printf("BOOTP:client "); break;
default: port++; break;
}
if (port==2)
printf("Port Applicatif non reconnu ");
}
void parse_udp_concis(const u_char *packet)
{
struct udphdr *udp_header = (struct udphdr *) packet;
short source = ntohs(udp_header->uh_sport);
short dest = ntohs(udp_header->uh_dport);
printf("UDP ");
parse_port_concis(source, dest);
}
void parse_tcp_concis(const u_char *packet)
{
struct tcphdr *tcp_header = (struct tcphdr *) packet;
int size = sizeof(struct ip);
int offset = (int)tcp_header->th_off;
short source = ntohs(tcp_header->th_sport);
short dest = ntohs(tcp_header->th_dport);
printf("TCP {");
if (tcp_header->th_flags & TH_FIN)
printf(" FIN");
if (tcp_header->th_flags & TH_SYN)
printf(" SYN");
if (tcp_header->th_flags & TH_RST)
printf(" RST");
if (tcp_header->th_flags & TH_PUSH)
printf(" PUSH");
if (tcp_header->th_flags & TH_ACK)
printf(" ACK");
if (tcp_header->th_flags & TH_URG)
printf(" URG");
printf(" } ");
parse_port_concis(source, dest);
}
void parse_ip_concis(const u_char *packet)
{
int i;
struct ip *ip_header = (struct ip *) packet;
int size = sizeof(struct ip);
printf("IPv%x ",ip_header->ip_v);
for (i=0;i<size;i++)
packet++;
char *ip = inet_ntoa(ip_header->ip_src);
printf("%s -> ",ip);
ip = inet_ntoa(ip_header->ip_dst);
printf("%s ",ip);
switch (ip_header->ip_p){
case UDP:
parse_udp_concis(packet);
break;
case TCP:
parse_tcp_concis(packet);
break;
default:
printf("ni TCP ni UDP ");
break;
}
}
void packet_reader_concis(u_char *useless, const struct pcap_pkthdr* pkthdr, const u_char* packet)
{
static int count = 1;
printf("[%d] ",count);
printf("\tlength: %d ",pkthdr->len);
int i;
struct ether_header *eth_header = (struct ether_header *) packet;
int size = sizeof(struct ether_header);
for (i=0;i<size;i++)
packet++;
switch(ntohs(eth_header->ether_type)){
case ETHERTYPE_IP:
parse_ip_concis(packet);
break;
case ETHERTYPE_ARP:
printf("ARP ");
break;
default:
printf("ni IP ni ARP ");
break;
}
count++;
printf("\n");
fflush(stdout);
}