/* A portforwarding program Copyright (C) 2004 Kasper Dupont This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or with permission from the author any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define PORTNUMBER 7197 #define TARGETPORT 21877 #define ASSTRING2(_) #_ #define ASSTRING(_) ASSTRING2(_) static inline void errstop(const char *s) { perror(s); exit(1); } void forward(int src_fd,int dst_fd) { char buf[4096]; int r; fprintf(stderr,"%d => %d\n",src_fd,dst_fd); switch(fork()) { case 0: break; case -1: errstop("fork()"); default: return; } dup2(src_fd,0); dup2(dst_fd,1); close(src_fd); close(dst_fd); while ((r=read(0,buf,4096))>0) { int i=0,w; while (i