View difference between Paste ID: pTzVdVdP and pAB24dPi
SHOW: | | - or go back to the newest paste.
1
#include <sys/socket.h>
2
#include <sys/ioctl.h>
3
#include <sys/time.h>
4
5
#include <asm/types.h>
6
7
#include <math.h>
8
#include <string.h>
9
#include <stdio.h>
10
#include <stdlib.h>
11
#include <unistd.h>
12
#include <signal.h>
13
#include <arpa/inet.h>
14
15
#include <linux/if_packet.h>
16
#include <linux/if_ether.h>
17
#include <linux/if_arp.h>
18
19-
#define DEVICE "eth0"
19+
20
#define DEVICE "eth1"
21
#define ETH_P_NULL 0x0
22
#define ETH_MAC_LEN ETH_ALEN
23
#define	ETH_ARP 0x0806
24
25
int s = 0; /*Socketdescriptor*/
26
void* buffer = NULL;
27
long total_packets = 0;
28
long answered_packets = 0;
29
30
void sigint(int signum);
31
32
struct __attribute__((packed)) arp_header
33-
unsigned short arp_hd;
33+
34-
unsigned short arp_pr;
34+
	unsigned short arp_hd;
35-
unsigned char arp_hdl;
35+
	unsigned short arp_pr;
36-
unsigned char arp_prl;
36+
	unsigned char arp_hdl;
37-
unsigned short arp_op;
37+
	unsigned char arp_prl;
38-
unsigned char arp_sha[6];
38+
	unsigned short arp_op;
39-
unsigned char arp_spa[4];
39+
	unsigned char arp_sha[6];
40-
unsigned char arp_dha[6];
40+
	unsigned char arp_spa[4];
41-
unsigned char arp_dpa[4];
41+
	unsigned char arp_dha[6];
42
	unsigned char arp_dpa[4];
43
};
44-
buffer = (void*)malloc(BUF_SIZE); /*Buffer for Ethernet Frame*/
44+
45-
unsigned char* etherhead = buffer;	/*Pointer to Ethenet Header*/
45+
	buffer = (void*)malloc(BUF_SIZE); /*Buffer for Ethernet Frame*/
46-
struct ethhdr *eh = (struct ethhdr *)etherhead; /*Another pointer to
46+
	unsigned char* etherhead = buffer;	/*Pointer to Ethenet Header*/
47-
ethernet header*/
47+
	struct ethhdr *eh = (struct ethhdr *)etherhead; /*Another pointer to
48-
unsigned char* arphead = buffer + 14;
48+
	                                                  ethernet header*/
49-
struct arp_header *ah;
49+
	unsigned char* arphead = buffer + 14;
50-
unsigned char src_mac[6];	 /*our MAC address*/
50+
	struct arp_header *ah;
51
	unsigned char src_mac[6];	 /*our MAC address*/
52-
struct ifreq ifr;
52+
53-
struct sockaddr_ll socket_address;
53+
	struct ifreq ifr;
54-
int ifindex = 0;	 /*Ethernet Interface index*/
54+
	struct sockaddr_ll socket_address;
55-
int i;
55+
	int ifindex = 0;	 /*Ethernet Interface index*/
56-
int length;	 /*length of received packet*/
56+
	int i;
57-
int sent;
57+
	int length;	 /*length of received packet*/
58
	int sent;
59-
printf("Server started, entering initialiation phase...\n");
59+
60
	printf("Server started, entering initialiation phase...\n");
61-
/*open socket*/
61+
62-
s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
62+
	/*open socket*/
63-
if (s == -1) {
63+
	s = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
64-
perror("socket():");
64+
	if (s == -1) {
65-
exit(1);
65+
		perror("socket():");
66
		exit(1);
67-
printf("Successfully opened socket: %i\n", s);
67+
	}
68
	printf("Successfully opened socket: %i\n", s);
69-
/*retrieve ethernet interface index*/
69+
70-
strncpy(ifr.ifr_name, DEVICE, IFNAMSIZ);
70+
	/*retrieve ethernet interface index*/
71-
if (ioctl(s, SIOCGIFINDEX, &ifr) == -1) {
71+
	strncpy(ifr.ifr_name, DEVICE, IFNAMSIZ);
72-
perror("SIOCGIFINDEX");
72+
	if (ioctl(s, SIOCGIFINDEX, &ifr) == -1) {
73-
exit(1);
73+
		perror("SIOCGIFINDEX");
74
		exit(1);
75-
ifindex = ifr.ifr_ifindex;
75+
	}
76-
printf("Successfully got interface index: %i\n", ifindex);
76+
	ifindex = ifr.ifr_ifindex;
77
	printf("Successfully got interface index: %i\n", ifindex);
78-
/*retrieve corresponding MAC*/
78+
79-
if (ioctl(s, SIOCGIFHWADDR, &ifr) == -1) {
79+
	/*retrieve corresponding MAC*/
80-
perror("SIOCGIFINDEX");
80+
	if (ioctl(s, SIOCGIFHWADDR, &ifr) == -1) {
81-
exit(1);
81+
		perror("SIOCGIFINDEX");
82
		exit(1);
83-
for (i = 0; i < 6; i++) {
83+
	}
84-
src_mac[i] = ifr.ifr_hwaddr.sa_data[i];
84+
	for (i = 0; i < 6; i++) {
85
		src_mac[i] = ifr.ifr_hwaddr.sa_data[i];
86-
printf("Successfully got our MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
86+
	}
87-
src_mac[0],src_mac[1],src_mac[2],src_mac[3],src_mac[4],src_mac[5]);
87+
	printf("Successfully got our MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
88
	       src_mac[0],src_mac[1],src_mac[2],src_mac[3],src_mac[4],src_mac[5]);
89-
/*prepare sockaddr_ll*/
89+
90-
socket_address.sll_family = PF_PACKET;
90+
	/*prepare sockaddr_ll*/
91-
socket_address.sll_protocol = htons(ETH_P_IP);
91+
	socket_address.sll_family = PF_PACKET;
92-
socket_address.sll_ifindex = ifindex;
92+
	socket_address.sll_protocol = htons(ETH_P_ARP);
93-
socket_address.sll_hatype = ARPHRD_ETHER;
93+
	socket_address.sll_ifindex = ifindex;
94-
socket_address.sll_pkttype = PACKET_OTHERHOST;
94+
	socket_address.sll_hatype = ARPHRD_ETHER;
95-
socket_address.sll_halen = 0;
95+
	socket_address.sll_pkttype = 0; //PACKET_OTHERHOST;
96-
socket_address.sll_addr[6] = 0x00;
96+
	socket_address.sll_halen = 0;
97-
socket_address.sll_addr[7] = 0x00;
97+
	socket_address.sll_addr[6] = 0x00;
98-
/*establish signal handler*/
98+
	socket_address.sll_addr[7] = 0x00;
99-
signal(SIGINT, sigint);
99+
	/*establish signal handler*/
100-
printf("Successfully established signal handler for SIGINT\n");
100+
	signal(SIGINT, sigint);
101-
printf("We are in production state, waiting for incoming packets....\n");
101+
	printf("Successfully established signal handler for SIGINT\n");
102
	printf("We are in production state, waiting for incoming packets....\n");
103-
while (1) {
103+
104-
/*Wait for incoming packet...*/
104+
	while (1) {
105-
length = recvfrom(s, buffer, BUF_SIZE, 0, NULL, NULL);
105+
		/*Wait for incoming packet...*/
106-
if (length == -1)
106+
		length = recvfrom(s, buffer, BUF_SIZE, 0, NULL, NULL);
107
		if (length == -1)
108-
perror("recvfrom():");
108+
			{
109-
exit(1);
109+
				perror("recvfrom():");
110
				exit(1);
111-
if(htons(eh->h_proto) == 0x806)
111+
			}
112
		if(ntohs(eh->h_proto) == ETH_P_ARP)
113
			{
114-
unsigned char buf_arp_dha[6];
114+
115-
unsigned char buf_arp_dpa[4];
115+
				unsigned char buf_arp_dha[6];
116
				unsigned char buf_arp_dpa[4];
117-
ah = (struct arp_header *)arphead;
117+
118-
if(htons(ah->arp_op) != 0x0001)
118+
				ah = (struct arp_header *)arphead;
119-
continue;
119+
				if(ntohs(ah->arp_op) != ARPOP_REQUEST)
120-
printf("buffer is---------------- %s \n",(char*)ah);
120+
					continue;
121-
printf("H/D TYPE : %x PROTO TYPE : %x \n",ah->arp_hd,ah->arp_pr);
121+
				printf("buffer is---------------- %s \n",(char*)ah);
122-
printf("H/D leng : %x PROTO leng : %x \n",ah->arp_hdl,ah->arp_prl);
122+
				printf("H/D TYPE : %x PROTO TYPE : %x \n",ah->arp_hd,ah->arp_pr);
123-
printf("OPERATION : %x \n", ah->arp_op);
123+
				printf("H/D leng : %x PROTO leng : %x \n",ah->arp_hdl,ah->arp_prl);
124-
printf("SENDER MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
124+
				printf("OPERATION : %x \n", ah->arp_op);
125-
ah->arp_sha[0],
125+
				printf("SENDER MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
126-
ah->arp_sha[1],
126+
				       ah->arp_sha[0],
127-
ah->arp_sha[2],
127+
				       ah->arp_sha[1],
128-
ah->arp_sha[3],
128+
				       ah->arp_sha[2],
129-
ah->arp_sha[4],
129+
				       ah->arp_sha[3],
130-
ah->arp_sha[5]
130+
				       ah->arp_sha[4],
131-
);
131+
				       ah->arp_sha[5]
132-
printf("SENDER IP address: %02d:%02d:%02d:%02d\n",
132+
				       );
133-
ah->arp_spa[0],
133+
				printf("SENDER IP address: %02d:%02d:%02d:%02d\n",
134-
ah->arp_spa[1],
134+
				       ah->arp_spa[0],
135-
ah->arp_spa[2],
135+
				       ah->arp_spa[1],
136-
ah->arp_spa[3]
136+
				       ah->arp_spa[2],
137-
);
137+
				       ah->arp_spa[3]
138-
if(ah->arp_spa[0]==10&&ah->arp_spa[1]==00&&ah->arp_spa[2]==00&&ah->arp_spa[3]==01)
138+
				       );
139
				#if 0
140-
printf("Sender ip is .............bam bam..........................................\n");
140+
				if(ah->arp_spa[0]==10&&ah->arp_spa[1]==00&&ah->arp_spa[2]==00&&ah->arp_spa[3]==01)
141-
system("sudo arp -s 10.0.0.1  00:1e:73:91:04:0d");
141+
					{
142
						printf("Sender ip is .............bam bam..........................................\n");
143-
printf("TARGET MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
143+
						system("sudo arp -s 10.0.0.1  00:1e:73:91:04:0d");
144-
ah->arp_dha[0],
144+
					}
145-
ah->arp_dha[1],
145+
				#endif
146-
ah->arp_dha[2],
146+
				printf("TARGET MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
147-
ah->arp_dha[3],
147+
				       ah->arp_dha[0],
148-
ah->arp_dha[4],
148+
				       ah->arp_dha[1],
149-
ah->arp_dha[5]
149+
				       ah->arp_dha[2],
150-
);
150+
				       ah->arp_dha[3],
151-
printf("TARGET IP address: %02d:%02d:%02d:%02d\n",
151+
				       ah->arp_dha[4],
152-
ah->arp_dpa[0],
152+
				       ah->arp_dha[5]
153-
ah->arp_dpa[1],
153+
				       );
154-
ah->arp_dpa[2],
154+
				printf("TARGET IP address: %02d:%02d:%02d:%02d\n",
155-
ah->arp_dpa[3]
155+
				       ah->arp_dpa[0],
156-
);
156+
				       ah->arp_dpa[1],
157
				       ah->arp_dpa[2],
158-
printf("+++++++++++++++++++++++++++++++++++++++\n" );
158+
				       ah->arp_dpa[3]
159-
printf("ETHER DST MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
159+
				       );
160-
eh->h_dest[0],
160+
161-
eh->h_dest[1],
161+
				printf("+++++++++++++++++++++++++++++++++++++++\n" );
162-
eh->h_dest[2],
162+
				printf("ETHER DST MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
163-
eh->h_dest[3],
163+
				       eh->h_dest[0],
164-
eh->h_dest[4],
164+
				       eh->h_dest[1],
165-
eh->h_dest[5]
165+
				       eh->h_dest[2],
166-
);
166+
				       eh->h_dest[3],
167-
printf("ETHER SRC MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
167+
				       eh->h_dest[4],
168-
eh->h_source[0],
168+
				       eh->h_dest[5]
169-
eh->h_source[1],
169+
				       );
170-
eh->h_source[2],
170+
				printf("ETHER SRC MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
171-
eh->h_source[3],
171+
				       eh->h_source[0],
172-
eh->h_source[4],
172+
				       eh->h_source[1],
173-
eh->h_source[5]
173+
				       eh->h_source[2],
174-
);
174+
				       eh->h_source[3],
175-
memcpy( (void*)etherhead, (const void*)(etherhead+ETH_MAC_LEN),
175+
				       eh->h_source[4],
176-
ETH_MAC_LEN);
176+
				       eh->h_source[5]
177-
memcpy( (void*)(etherhead+ETH_MAC_LEN), (const void*)src_mac,
177+
				       );
178-
ETH_MAC_LEN);
178+
				memcpy( (void*)etherhead, (const void*)(etherhead+ETH_MAC_LEN),
179-
eh->h_proto = ETH_ARP;
179+
				        ETH_MAC_LEN);
180-
printf("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& \n");
180+
				memcpy( (void*)(etherhead+ETH_MAC_LEN), (const void*)src_mac,
181-
printf("ETHER DST MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
181+
				        ETH_MAC_LEN);
182-
eh->h_dest[0],
182+
				eh->h_proto = htons(ETH_P_ARP);
183-
eh->h_dest[1],
183+
				printf("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& \n");
184-
eh->h_dest[2],
184+
				printf("ETHER DST MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
185-
eh->h_dest[3],
185+
				       eh->h_dest[0],
186-
eh->h_dest[4],
186+
				       eh->h_dest[1],
187-
eh->h_dest[5]
187+
				       eh->h_dest[2],
188-
);
188+
				       eh->h_dest[3],
189-
printf("ETHER SRC MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
189+
				       eh->h_dest[4],
190-
eh->h_source[0],
190+
				       eh->h_dest[5]
191-
eh->h_source[1],
191+
				       );
192-
eh->h_source[2],
192+
				printf("ETHER SRC MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
193-
eh->h_source[3],
193+
				       eh->h_source[0],
194-
eh->h_source[4],
194+
				       eh->h_source[1],
195-
eh->h_source[5]
195+
				       eh->h_source[2],
196-
);
196+
				       eh->h_source[3],
197-
ah->arp_hd = ntohs(ah->arp_hd);
197+
				       eh->h_source[4],
198-
ah->arp_pr = ntohs(ah->arp_pr);
198+
				       eh->h_source[5]
199
				       );
200-
ah->arp_op = 0x0002;
200+
				//ah->arp_hd = ntohs(ah->arp_hd);
201
				//ah->arp_pr = ntohs(ah->arp_pr);
202-
buf_arp_dpa[0] = ah->arp_dpa[0];
202+
203-
buf_arp_dpa[1] = ah->arp_dpa[1];
203+
				ah->arp_op = htons(ARPOP_REPLY);
204-
buf_arp_dpa[2] = ah->arp_dpa[2];
204+
205-
buf_arp_dpa[3] = ah->arp_dpa[3];
205+
				buf_arp_dpa[0] = ah->arp_dpa[0];
206
				buf_arp_dpa[1] = ah->arp_dpa[1];
207-
ah->arp_dha[0] = ah->arp_sha[0];
207+
				buf_arp_dpa[2] = ah->arp_dpa[2];
208-
ah->arp_dha[1] = ah->arp_sha[1];
208+
				buf_arp_dpa[3] = ah->arp_dpa[3];
209-
ah->arp_dha[2] = ah->arp_sha[2];
209+
210-
ah->arp_dha[3] = ah->arp_sha[3];
210+
				ah->arp_dha[0] = ah->arp_sha[0];
211-
ah->arp_dha[4] = ah->arp_sha[4];
211+
				ah->arp_dha[1] = ah->arp_sha[1];
212-
ah->arp_dha[5] = ah->arp_sha[5];
212+
				ah->arp_dha[2] = ah->arp_sha[2];
213
				ah->arp_dha[3] = ah->arp_sha[3];
214-
ah->arp_dpa[0] = ah->arp_spa[0];
214+
				ah->arp_dha[4] = ah->arp_sha[4];
215-
ah->arp_dpa[1] = ah->arp_spa[1];
215+
				ah->arp_dha[5] = ah->arp_sha[5];
216-
ah->arp_dpa[2] = ah->arp_spa[2];
216+
217-
ah->arp_dpa[3] = ah->arp_spa[3];
217+
				ah->arp_dpa[0] = ah->arp_spa[0];
218
				ah->arp_dpa[1] = ah->arp_spa[1];
219-
ah->arp_spa[0] = buf_arp_dpa[0];
219+
				ah->arp_dpa[2] = ah->arp_spa[2];
220-
ah->arp_spa[1] = buf_arp_dpa[1];
220+
				ah->arp_dpa[3] = ah->arp_spa[3];
221-
ah->arp_spa[2] = buf_arp_dpa[2];
221+
222-
ah->arp_spa[3] = buf_arp_dpa[3];
222+
				ah->arp_spa[0] = buf_arp_dpa[0];
223-
//change the sender mac address
223+
				ah->arp_spa[1] = buf_arp_dpa[1];
224-
ah->arp_sha[0] = 0x00;
224+
				ah->arp_spa[2] = buf_arp_dpa[2];
225-
ah->arp_sha[1] = 0x1e;
225+
				ah->arp_spa[3] = buf_arp_dpa[3];
226-
ah->arp_sha[2] = 0x73;
226+
				//change the sender mac address
227-
ah->arp_sha[3] = 0x78;
227+
				ah->arp_sha[0] = 0x00;
228-
ah->arp_sha[4] = 0x9a;
228+
				ah->arp_sha[1] = 0x1e;
229-
ah->arp_sha[5] = 0x0d;
229+
				ah->arp_sha[2] = 0x73;
230
				ah->arp_sha[3] = 0x78;
231-
socket_address.sll_addr[0] = eh->h_dest[0];
231+
				ah->arp_sha[4] = 0x9a;
232-
socket_address.sll_addr[1] = eh->h_dest[1];
232+
				ah->arp_sha[5] = 0x0d;
233-
socket_address.sll_addr[2] = eh->h_dest[2];
233+
234-
socket_address.sll_addr[3] = eh->h_dest[3];
234+
				socket_address.sll_addr[0] = eh->h_dest[0];
235-
socket_address.sll_addr[4] = eh->h_dest[4];
235+
				socket_address.sll_addr[1] = eh->h_dest[1];
236-
socket_address.sll_addr[5] = eh->h_dest[5];
236+
				socket_address.sll_addr[2] = eh->h_dest[2];
237-
printf("=======================================\n" );
237+
				socket_address.sll_addr[3] = eh->h_dest[3];
238-
printf("SENDER MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
238+
				socket_address.sll_addr[4] = eh->h_dest[4];
239-
ah->arp_sha[0],
239+
				socket_address.sll_addr[5] = eh->h_dest[5];
240-
ah->arp_sha[1],
240+
				printf("=======================================\n" );
241-
ah->arp_sha[2],
241+
				printf("SENDER MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
242-
ah->arp_sha[3],
242+
				       ah->arp_sha[0],
243-
ah->arp_sha[4],
243+
				       ah->arp_sha[1],
244-
ah->arp_sha[5]
244+
				       ah->arp_sha[2],
245-
);
245+
				       ah->arp_sha[3],
246-
printf("SENDER IP address: %02d:%02d:%02d:%02d\n",
246+
				       ah->arp_sha[4],
247-
ah->arp_spa[0],
247+
				       ah->arp_sha[5]
248-
ah->arp_spa[1],
248+
				       );
249-
ah->arp_spa[2],
249+
				printf("SENDER IP address: %02d:%02d:%02d:%02d\n",
250-
ah->arp_spa[3]
250+
				       ah->arp_spa[0],
251-
);
251+
				       ah->arp_spa[1],
252-
if((ah->arp_spa[0]==10 && ah->arp_spa[1]==0 && ah->arp_spa[2]==0 && ah->arp_spa[3]==1))
252+
				       ah->arp_spa[2],
253-
printf("------------------------------------------10.0.0.1-----------------------------------------\n");
253+
				       ah->arp_spa[3]
254-
printf("TARGET MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
254+
				       );
255-
ah->arp_dha[0],
255+
				if((ah->arp_spa[0]==10 && ah->arp_spa[1]==0 && ah->arp_spa[2]==0 && ah->arp_spa[3]==1))
256-
ah->arp_dha[1],
256+
					printf("------------------------------------------10.0.0.1-----------------------------------------\n");
257-
ah->arp_dha[2],
257+
				printf("TARGET MAC address: %02X:%02X:%02X:%02X:%02X:%02X\n",
258-
ah->arp_dha[3],
258+
				       ah->arp_dha[0],
259-
ah->arp_dha[4],
259+
				       ah->arp_dha[1],
260-
ah->arp_dha[5]
260+
				       ah->arp_dha[2],
261-
);
261+
				       ah->arp_dha[3],
262-
printf("TARGET IP address: %02d:%02d:%02d:%02d\n",
262+
				       ah->arp_dha[4],
263-
ah->arp_dpa[0],
263+
				       ah->arp_dha[5]
264-
ah->arp_dpa[1],
264+
				       );
265-
ah->arp_dpa[2],
265+
				printf("TARGET IP address: %02d:%02d:%02d:%02d\n",
266-
ah->arp_dpa[3]
266+
				       ah->arp_dpa[0],
267-
);
267+
				       ah->arp_dpa[1],
268-
printf("H/D TYPE : %x PROTO TYPE : %x \n",ah->arp_hd,ah->arp_pr);
268+
				       ah->arp_dpa[2],
269-
printf("H/D leng : %x PROTO leng : %x \n",ah->arp_hdl,ah->arp_prl);
269+
				       ah->arp_dpa[3]
270-
printf("OPERATION : %x \n", ah->arp_op);
270+
				       );
271
				printf("H/D TYPE : %x PROTO TYPE : %x \n",ah->arp_hd,ah->arp_pr);
272-
sent = sendto(s, buffer, BUF_SIZE, 0, (struct
272+
				printf("H/D leng : %x PROTO leng : %x \n",ah->arp_hdl,ah->arp_prl);
273-
sockaddr*)&socket_address, sizeof(socket_address));
273+
				printf("OPERATION : %x \n", ah->arp_op);
274-
if (sent == -1)
274+
275
				sent = sendto(s, buffer, BUF_SIZE, 0, (struct
276-
perror("sendto():");
276+
				                                       sockaddr*)&socket_address, sizeof(socket_address));
277-
exit(1);
277+
				if (sent == -1)
278
					{
279
						perror("sendto():");
280-
answered_packets++;
280+
						exit(1);
281
					}
282
283
				answered_packets++;
284-
total_packets++;
284+
285
			}
286
287
		total_packets++;
288
289-
/*Clean up.......*/
289+
	}
290
}
291-
struct ifreq ifr;
291+
292
	/*Clean up.......*/
293-
if (s == -1)
293+
294-
return;
294+
	struct ifreq ifr;
295
296-
strncpy(ifr.ifr_name, DEVICE, IFNAMSIZ);
296+
	if (s == -1)
297-
ioctl(s, SIOCGIFFLAGS, &ifr);
297+
		return;
298-
ifr.ifr_flags &= ~IFF_PROMISC;
298+
299-
ioctl(s, SIOCSIFFLAGS, &ifr);
299+
	strncpy(ifr.ifr_name, DEVICE, IFNAMSIZ);
300-
close(s);
300+
	ioctl(s, SIOCGIFFLAGS, &ifr);
301
	ifr.ifr_flags &= ~IFF_PROMISC;
302-
free(buffer);
302+
	ioctl(s, SIOCSIFFLAGS, &ifr);
303
	close(s);
304-
printf("Server terminating....\n");
304+
305
	free(buffer);
306-
printf("Totally received: %ld packets\n", total_packets);
306+
307-
printf("Answered %ld packets\n", answered_packets);
307+
	printf("Server terminating....\n");
308-
exit(0);
308+
309
	printf("Totally received: %ld packets\n", total_packets);
310
	printf("Answered %ld packets\n", answered_packets);
311
	exit(0);
312
}