Skip to content

Commit a609fef

Browse files
committed
Added versioning
1 parent 9ec2a92 commit a609fef

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

ipredir.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
//quick way to link with WinDivert.lib without changing project settings
1616
#pragma comment(lib, "WinDivert-1.1.6-MSVC/x86/WinDivert")
1717

18+
const int VERSION_MAJOR = 1;
19+
const int VERSION_MINOR = 0;
20+
const int VERSION_PATCH = 0;
21+
const std::string VERSION_STR = "v" + std::to_string(VERSION_MAJOR) + "." + std::to_string(VERSION_MINOR) + "." + std::to_string(VERSION_PATCH);
22+
1823
//lol global variables!!!
1924
ipmap_t ipmap; //oldip->newip mapping
2025
int dbg = 0; //debug flag
@@ -33,7 +38,7 @@ int main(int argc, char* argv[]) {
3338

3439
//parse args, get ip map and lists of ips. returns debug mode
3540
dbg = parseArgs(args, ipmap, ipsout, ipsin);
36-
41+
3742
//write filter string using ip lists
3843
std::string filter = makeFilter(ipsout, ipsin);
3944

@@ -64,7 +69,7 @@ int main(int argc, char* argv[]) {
6469
}
6570

6671
//wait for keypress
67-
std::cout << "Redirecting...press any key to stop" << std::endl;
72+
std::cout << "Redirecting...press any key to stop" << std::endl;
6873
_getch();
6974

7075
//exit nicely
@@ -126,7 +131,7 @@ DWORD redirThread(LPVOID arg) {
126131

127132
//grab destination ip from header
128133
from = piphdr->DstAddr;
129-
134+
130135
//look it up in redirect map
131136
ipmap_t::iterator iter = ipmap.find(from);
132137
//if not found, inject unmodified packet (shouldn't happen for outgoing packets since
@@ -136,7 +141,7 @@ DWORD redirThread(LPVOID arg) {
136141
goto outputpacket; //goto is best way to "break" nested ifs
137142
}
138143
to = iter->second;
139-
144+
140145
if (dbg) std::cout << DottedIPv4(to) << std::endl;
141146

142147
//replace with new destination ip
@@ -159,7 +164,7 @@ DWORD redirThread(LPVOID arg) {
159164
ptcphdr ? ptcphdr->DstPort : (pudphdr ? pudphdr->DstPort : 0),
160165
ptcphdr ? ptcphdr->SrcPort : (pudphdr ? pudphdr->SrcPort : 0),
161166
};
162-
167+
163168
if (dbg) std::cout << "Rx: " << DisplayTuple(tup) << "->";
164169

165170
//look up tuple in nat map
@@ -196,15 +201,15 @@ std::string makeFilter(std::vector<std::string> ipsout, std::vector<std::string>
196201
std::vector<std::string>::iterator iter;
197202

198203
//"(outbound and (ip.SrcAddr==w.x.y.z or ip.SrcAddr==t.u.v.w or false)) or (inbound and (ip.SrcAddr==a.b.c.d or ip.SrcAddr==e.f.g.h or false))"
199-
204+
200205
std::string filter = "(outbound and (";
201206

202207
for (iter = ipsout.begin(); iter != ipsout.end(); ++iter) {
203208
filter += ("ip.DstAddr == " + *iter + " or ");
204209
}
205210

206211
filter += "false)) or (inbound and (";
207-
212+
208213
for (iter = ipsin.begin(); iter != ipsin.end(); ++iter) {
209214
filter += ("ip.SrcAddr == " + *iter + " or ");
210215
}
@@ -224,7 +229,7 @@ int parseArgs(std::vector<std::string> args, ipmap_t& ipmap, std::vector<std::st
224229
std::vector<std::string>::iterator iter;
225230
for (iter = args.begin(); iter != args.end(); ++iter) {
226231
std::string arg = *iter;
227-
232+
228233
//handle simple debug flag
229234
if (arg == "-d") {
230235
dbg = 1;
@@ -257,7 +262,7 @@ int parseArgs(std::vector<std::string> args, ipmap_t& ipmap, std::vector<std::st
257262
if (WinDivertHelperParseIPv4Address(strfrom.c_str(), &from)) {
258263
from = byteswap(from);
259264
ipmap[from] = to;
260-
265+
261266
//save string form of 'from' ip to add to WinDivert filter
262267
ipsout.push_back(strfrom);
263268
std::cout << "Adding redirect from " << strfrom << " to " << strto << std::endl;
@@ -335,7 +340,7 @@ std::string DisplayTuple(nattuple_t o) {
335340

336341
//show usage/help
337342
void usage(const char* arg) {
338-
std::cout << "ipredir by cybermind" << std::endl;
343+
std::cout << "ipredir " << VERSION_STR << " by cybermind" << std::endl;
339344
std::cout << "Will rewrite outgoing packets to redirect which IP they are headed to." << std::endl;
340345
std::cout << "It will also rewrite the incoming packets back to their original values," << std::endl;
341346
std::cout << "acting as a rudimentary NAT." << std::endl;

0 commit comments

Comments
 (0)