Skip to content

Commit a30ad57

Browse files
author
hyperion
committed
initial code upload
1 parent e82cd55 commit a30ad57

34 files changed

Lines changed: 2209 additions & 0 deletions

CVS/Entries

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/algo_V04.vsd/1.1.1.1/Mon Jul 21 19:35:17 2003//
2+
/diagram_v03.vsd/1.1.1.1/Mon Jul 21 19:35:17 2003//
3+
/functions.vsd/1.1.1.1/Mon Jul 21 19:35:17 2003//
4+
/getif_ip.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
5+
/getif_name.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
6+
/getout_ip.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
7+
/icmp.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
8+
/listen.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
9+
/lookup.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
10+
/makefile/1.1.1.1/Mon Jul 21 19:35:17 2003//
11+
/neti.conf/1.1.1.1/Mon Jul 21 19:35:17 2003//
12+
/parse.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
13+
/tcp.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
14+
/udp.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
15+
/utils.c/1.1.1.1/Mon Jul 21 19:35:17 2003//
16+
D/scripts////
17+
/promisc.c/1.2/Mon Jul 21 19:50:03 2003//
18+
/main.c/1.2/Fri Aug 29 18:59:05 2003//
19+
/neti/1.2/Fri Aug 29 18:59:27 2003//
20+
/neti.h/1.2/Fri Aug 29 18:53:14 2003//

CVS/Repository

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NETINJECTOR

CVS/Root

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/home/data/cvs/

algo_V04.vsd

53 KB
Binary file not shown.

diagram_v03.vsd

38 KB
Binary file not shown.

functions.vsd

34.5 KB
Binary file not shown.

getif_ip.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
/*
3+
* name: getif_ip.c
4+
* this file is part of the "Net-Injector" project. It defines the getif_ip_by_name() function
5+
* Copyright (C) 2002 by Jean Philippe GUILLEMIN <jp.guillemin@free.fr>
6+
* license: This software is under GPL license
7+
* date: 04 17 2003
8+
* rev: 0.8
9+
*/
10+
11+
#include "neti.h"
12+
13+
14+
int getif_ip_by_name(char *ip, u_int32_t *inet_ip, char *ifname){
15+
16+
struct ifreq ifr;
17+
struct sockaddr_in *addr;
18+
int sock;
19+
20+
addr = (struct sockaddr_in *) &ifr.ifr_addr;
21+
memset(&ifr, 0, IFREQ_SIZE);
22+
23+
if ((sock = socket(AF_INET, SOCK_STREAM, 0)) >= 0) {
24+
strncpy(ifr.ifr_name, ifname, 32);
25+
26+
if (ioctl(sock, SIOCGIFADDR, &ifr) == 0){
27+
memcpy (inet_ip, &addr->sin_addr.s_addr, sizeof(addr->sin_addr.s_addr));
28+
strncpy(ip, inet_ntoa(addr->sin_addr), 32);
29+
/* fprintf(stdout, "%s\n", inet_ntoa(addr->sin_addr)); debug */
30+
}else{
31+
fprintf(stderr, "Error : (getif_ip) in call to ioctl() !\n");
32+
close(sock);
33+
}
34+
}else {
35+
fprintf(stderr, "Error : (getif_ip) cannot get src address !\n");
36+
return EXIT_FAILURE;
37+
}
38+
39+
return EXIT_SUCCESS;
40+
}
41+
42+
43+

getif_name.c

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
/*
3+
* name: getif_name.c
4+
* this file is part of the "Net-Injector" project. It defines the getif_name_by_ip() function
5+
* Adapted from Salvatore Sanfilippo <antirez@invece.org>
6+
* license: This software is under GPL license
7+
* date: 04 17 2003
8+
* rev: 0.8
9+
*/
10+
11+
#include "neti.h"
12+
13+
14+
int getif_name_by_ip(char *ifname, u_int32_t *inet_ip){
15+
16+
int sock;
17+
struct ifconf ifc;
18+
struct ifreq ibuf[16], ifr, *ifrp, *ifend;
19+
struct sockaddr_in if_sockaddr;
20+
21+
if ( (sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
22+
fprintf(stderr, "Error : (getif_name) socket(AF_INET, SOCK_DGRAM, 0) !\n");
23+
return EXIT_FAILURE;
24+
}
25+
26+
memset(ibuf, 0, sizeof(struct ifreq)*16);
27+
ifc.ifc_len = sizeof ibuf;
28+
ifc.ifc_buf = (caddr_t) ibuf;
29+
30+
/* gets interfaces list */
31+
if ( ioctl(sock, SIOCGIFCONF, (char*)&ifc) == -1 ||
32+
ifc.ifc_len < sizeof(struct ifreq) ) {
33+
fprintf(stderr, "Error : (getif_name) ioctl(SIOCGIFCONF) !\n");
34+
close(sock);
35+
return EXIT_FAILURE;
36+
}
37+
38+
/* ifrp points to buffer and ifend points to buffer's end */
39+
ifrp = ibuf;
40+
ifend = (struct ifreq*) ((char*)ibuf + ifc.ifc_len);
41+
42+
for (; ifrp < ifend; ifrp++) {
43+
strncpy(ifr.ifr_name, ifrp->ifr_name, sizeof(ifr.ifr_name));
44+
45+
if ( ioctl(sock, SIOCGIFFLAGS, (char*)&ifr) == -1) {
46+
fprintf(stderr, "Error : (getif_name) ioctl(SIOCGIFFLAGS) !\n");
47+
continue;
48+
}
49+
50+
/* Check if down */
51+
if ( !(ifr.ifr_flags & IFF_UP) ) continue;
52+
53+
/* Get the interface address */
54+
if (ioctl(sock, SIOCGIFADDR, (char*)&ifr) == -1) {
55+
fprintf(stderr, "Error : (getif_name) ioctl(SIOCGIFADDR) !\n");
56+
continue;
57+
}
58+
59+
/* Copy it */
60+
memcpy(&if_sockaddr, &ifr.ifr_addr, sizeof(struct sockaddr_in));
61+
62+
/* Check if it is what we are locking for */
63+
if (if_sockaddr.sin_addr.s_addr != *inet_ip) continue;
64+
65+
/* interface found, save if name */
66+
strncpy(ifname, ifr.ifr_name, 32);
67+
close(sock);
68+
return EXIT_SUCCESS;
69+
}
70+
close(sock);
71+
return EXIT_FAILURE;
72+
}
73+

getout_ip.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
/*
3+
* name: getout_ip.c
4+
* this file is part of the "Net-Injector" project. It defines the getout_ip() function
5+
* Adapted from R.Stevens
6+
* license: This software is under GPL license
7+
* date: 04 17 2003
8+
* rev: 0.8
9+
*/
10+
11+
#include "neti.h"
12+
13+
14+
/* Finds the IP address of the output interface from OS routing table */
15+
16+
int getout_ip(struct sockaddr_in *if_addr, struct sockaddr_in *dest){
17+
18+
int sock_rt, len, one=1;
19+
struct sockaddr_in found_if_addr;
20+
21+
memset(&found_if_addr, 0, sizeof(found_if_addr));
22+
sock_rt = socket(AF_INET, SOCK_DGRAM, 0 );
23+
24+
dest->sin_port = htons(53);
25+
if (setsockopt(sock_rt, SOL_SOCKET, SO_BROADCAST, &one, sizeof(one))
26+
== -1) {
27+
fprintf(stderr, "Error : (getout_ip) in setsockopt !\n");
28+
close(sock_rt);
29+
return EXIT_FAILURE;
30+
}
31+
32+
if (connect(sock_rt, (struct sockaddr*)dest, sizeof(struct sockaddr_in))
33+
== -1 ) {
34+
fprintf(stderr, "Error : (getout_ip) bad IP address !\n");
35+
close(sock_rt);
36+
return EXIT_FAILURE;
37+
}
38+
39+
len = sizeof(found_if_addr);
40+
if (getsockname(sock_rt, (struct sockaddr *)&found_if_addr, &len) == -1 ) {
41+
fprintf(stderr, "Error : (getout_ip) in getsockname !\n");
42+
close(sock_rt);
43+
return EXIT_FAILURE;
44+
}
45+
close(sock_rt);
46+
if (found_if_addr.sin_addr.s_addr == 0)
47+
return EXIT_FAILURE;
48+
memcpy(if_addr, &found_if_addr, sizeof(struct sockaddr_in));
49+
return EXIT_SUCCESS;
50+
}
51+

icmp.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
/*
3+
* name: icmp.c
4+
* this file is part of the "Net-Injector" project. It defines the write_icmp() function
5+
* Copyright (C) 2002 by Jean Philippe GUILLEMIN <jp.guillemin@free.fr>
6+
* license: This software is under GPL license
7+
* date: 04 17 2003
8+
* rev: 0.8
9+
10+
0 ______________________15-16________________________31
11+
| | Message ICMP (xb) |
12+
| ID. |____________________________________________ |
13+
| | | | | |
14+
| |Type(8b)| Code(8b)|Checksum(16b)|sequence(xb)|
15+
|_______|________|_________|_____________|____________|
16+
*/
17+
18+
#include "neti.h"
19+
20+
/* function that create the ICMP header and data field
21+
the result is a pointer (*icmp_packet) to the begining of ICMP header
22+
*/
23+
24+
int write_icmp(char *icmp_packet, int size){
25+
26+
struct icmphdr *icmph;
27+
struct icmp_timestamp *tstamp;
28+
struct timeval tv;
29+
30+
31+
icmph = (struct icmphdr*) (icmp_packet); /* address of icmp-header */
32+
data = (char*) (icmp_packet + ICMPHDR_SIZE); /* address of begining of payload */
33+
34+
memset(data, 0, myhdr->data_size);
35+
memset(icmp_packet, 0, size);
36+
37+
38+
/*filling ICMP header */
39+
icmph->type = myhdr->icmp_type;
40+
icmph->code = myhdr->icmp_code;
41+
if ( (myhdr->icmp_type == 8) || (myhdr->icmp_type == 8)) {
42+
icmph->un.echo.id = htons (myhdr->icmp_echo_id);
43+
icmph->un.echo.sequence = htons(myhdr->icmp_echo_sequence);
44+
}
45+
if (myhdr->icmp_type == 5) {
46+
icmph->un.gateway = inet_addr (myhdr->icmp_redirect_gateway);
47+
}
48+
if (myhdr->icmp_type == 13) {
49+
tstamp = (struct icmp_timestamp*) (data);
50+
gettimeofday(&tv, NULL);
51+
tstamp->originate = htonl((tv.tv_sec % 86400) * 1000 + tv.tv_usec / 1000);
52+
tstamp->receive = 0;
53+
tstamp->transmit = 0;
54+
}
55+
56+
icmph->checksum=0;
57+
58+
59+
icmph->checksum = sum((u_int16_t *) icmp_packet, size);
60+
61+
return EXIT_SUCCESS;
62+
}

0 commit comments

Comments
 (0)