-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
94 lines (66 loc) · 1.79 KB
/
utils.c
File metadata and controls
94 lines (66 loc) · 1.79 KB
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
/*
* name: utils.c
* this file is part of the "Net-Injector" project. It defines small usefull functions
* Copyright (C) 2002 by Jean Philippe GUILLEMIN <jp.guillemin@free.fr>
* license: This software is under GPL license
* date: 04 17 2003
* rev: 0.8
*/
#include "neti.h"
/****************************/
/* trap SIGINT */
/****************************/
void catch_sig(int sig){
fprintf(stdout, "Neti stoped by user - goodby...\n");
if (be_promiscuous == 1) unset_promisc(*so_send);
close(so_udp);
close(so_tcp);
close(so_icmp);
exit(EXIT_SUCCESS);
}
/*****************************************/
/* find the max socket id for select() */
/*****************************************/
int max(int a, int b, int c) {
if (b > a) a=b;
if (c > a) a=c;
return a;
}
/*****************************************/
/* close sockets */
/*****************************************/
void close_sockets(void){
if (be_promiscuous == 1) unset_promisc(*so_send);
close(so_udp);
close(so_tcp);
close(so_icmp);
exit(EXIT_SUCCESS);
}
/*****************************************/
/* calculate all checksums */
/*****************************************/
u_int16_t sum(u_int16_t *buf, int nbytes){
u_int32_t sum;
u_int16_t byte;
sum = 0;
while (nbytes > 1) {
sum += *buf++;
nbytes -= 2;
}
if (nbytes == 1) {
byte = 0;
*((u_int16_t *) &byte) = *(unsigned char *) buf;
sum += byte;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
return (u_int16_t) ~sum;
} /* end sum */
/*****************************************/
/* debug everywhere */
/*****************************************/
int debug() {
fprintf(stdout, "last_address = %s\n", last_address);
fprintf(stdout, "last_name = %s\n", last_name);
return EXIT_SUCCESS;
}