Für alle die nicht nur TCP für was es RINETD gibt sondern auch UDP Traffic umleiten wollen.
/* http://www.brokestream.com/udp_redirect.html Build: gcc -o udp_redirect udp_redirect.c udp_redirect.c Version 2008-11-09 Copyright (C) 2007 Ivan Tikhonov This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Ivan Tikhonov, kefeer@brokestream.com */ #include #include #include #include #include int main(int argc, char *argv[]) { if (argc!=5) { printf("Usage: %s our-ip our-port first-mirror-ip second-mirror-ip\n",argv[0]); exit(1); } int osck=socket(PF_INET,SOCK_DGRAM,IPPROTO_IP); struct sockaddr_in sadr_bnd; sadr_bnd.sin_family=AF_INET; sadr_bnd.sin_addr.s_addr=inet_addr(argv[1]); sadr_bnd.sin_port=htons(atoi(argv[2])); if( bind(osck,(struct sockaddr *)&sadr_bnd,sizeof(sadr_bnd)) == -1) { printf("Can't bind our address (%s:%s)\n", argv[1], argv[2]); exit(1); } struct sockaddr_in sadr_one; sadr_one.sin_family=AF_INET; sadr_one.sin_addr.s_addr=inet_addr(argv[3]); sadr_one.sin_port=htons(atoi(argv[2])); struct sockaddr_in sadr_two; sadr_two.sin_family=AF_INET; sadr_two.sin_addr.s_addr=inet_addr(argv[4]); sadr_two.sin_port=htons(atoi(argv[2])); struct sockaddr_in sa; struct sockaddr_in da; da.sin_addr.s_addr=0; while(1) { char buf[65535]; int sn=sizeof(sa); int n=recvfrom(osck,buf,sizeof(buf),0,(struct sockaddr *)&sa,&sn); if(n<=0) continue; //printf("data from %s:%u\n", inet_ntoa(sa.sin_addr), ntohs(sa.sin_port)); /* inet_ntoa needs #include*/ if ((sa.sin_addr.s_addr==sadr_one.sin_addr.s_addr) || (sa.sin_addr.s_addr==sadr_two.sin_addr.s_addr)) { if(sa.sin_addr.s_addr==sadr_one.sin_addr.s_addr) { sendto(osck,buf,n,0,(struct sockaddr *)&sadr_two,sizeof(sadr_two)); //printf("sendto (one2two) %s:%u\n", inet_ntoa(sadr_two.sin_addr), ntohs(sadr_two.sin_port)); } if(sa.sin_addr.s_addr==sadr_two.sin_addr.s_addr) { sendto(osck,buf,n,0,(struct sockaddr *)&sadr_one,sizeof(sadr_one)); //printf("sendto (two2one) %s:%u\n", inet_ntoa(sadr_one.sin_addr), ntohs(sadr_one.sin_port)); } /* } else { //if(da.sin_addr.s_addr) sendto(osck,buf,n,0,(struct sockaddr *)&da,sizeof(da)); printf("nosendto (da) %s:%u\n", inet_ntoa(da.sin_addr), ntohs(da.sin_port)); printf("nosendto (sa) %s:%u\n", inet_ntoa(sa.sin_addr), ntohs(sa.sin_port)); */ } } }