45int main(
int argc,
char **argv)
53 if ((conf = fopen(
"mangler.cfg",
"r")) ==
NULL) {
54 cout <<
"Cannot open mangler.cfg for reading." << endl;
60 else if( argc == 2 && (strcmp(argv[1],
"help") == 0 || strcmp(argv[1],
"?") == 0 ||
61 strcmp(argv[1],
"-h") == 0) )
66 if ((conf = fopen(argv[1],
"r")) ==
NULL) {
67 cout <<
"Cannot open " << argv[1] <<
" for reading." << endl;
76 Wstring output_file(
"mangler.log");
79 backup_file = output_file;
80 backup_file +=
".bak";
81 rename(output_file.
get(),backup_file.
get());
88 if (htonl(0x12345678) == 0x12345678)
90 INFMSG(
"Host is network-byte-order");
94 INFMSG(
"Host is Intel-byte-order");
100 WORD verReq = MAKEWORD(2, 2);
103 int err = WSAStartup(verReq, &wsadata);
105 ERRMSG(
"Winsock Init failed.");
109 if ((LOBYTE(wsadata.wVersion) != 2) || (HIBYTE(wsadata.wVersion) !=2)) {
110 ERRMSG(
"Winsock DLL is not 2.2");
112 ERRMSG(
"Winsock Init failed.");
115 INFMSG(
"Winsock Init done.");
127 config.
getInt(
"PORT", port);
135 INFMSG(
"Binding to "<<hostIPStr.
get()<<
":"<<port<<
"-"<<(port+3));
136 localIP = ntohl(inet_addr(hostIPStr.
get()));
140 INFMSG(
"Binding to localhost:"<<port<<
"-"<<(port+3));
149 ERRMSG(
"Couldn't bind - error " << retval);
153 unsigned char buf[1024];
154 struct sockaddr_in addr;
156 INFMSG(
"sizeof(packet) == " << packet_size);
157 unsigned char *theAddr;
161 retval = udp.
Wait(15, 0, fdset);
166 retval = udp.
Read(buf, packet_size, &addr);
170 theAddr = (
unsigned char *)&(addr.sin_addr.s_addr);
171 if (retval != packet_size)
173 WRNMSG(
"Recieved mis-sized packet (" << retval <<
" bytes) from " << theAddr[0] <<
"." << theAddr[1] <<
"." << theAddr[2] <<
"." << theAddr[3] <<
":" << addr.sin_port);
179 WRNMSG(
"Recieved a bad packet - good length!");
189 INFMSG(
"Packet ID = " << packet->packetID);
191 udp.
Write(buf,packet_size,ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port));
192 INFMSG(
"Saw " << (
int)theAddr[0] <<
"." << (
int)theAddr[1] <<
"." << (
int)theAddr[2] <<
"." << (
int)theAddr[3] <<
":" << ntohs(addr.sin_port) << ((blitz)?
" Blitzed":
"") );
196 udp2.
Write(buf,packet_size,ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port)+1);
197 udp3.
Write(buf,packet_size,ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port)+2);
198 udp4.
Write(buf,packet_size,ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port)+3);
OutputDevice * output_device