Download | Plain Text | No Line Numbers
- /*
- * Copyright (C) 2004 Pawel Foremski <pjf@asn.pl>
- *
- * 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 (at your option) 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.
- *
- ***
- *
- * Implements tarpitting
- *
- * Compile with: gcc -O2 -s -o tarpit ./tarpit.c
- * Set in tcprules: TARPITCOUNT=n,TARPITDELAY={n, NORMAL, MEDIUM, HARD}
- *
- */
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
-
- #ifndef MIN
- #define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
- #endif
-
- int main()
- {
- char *tcount, *tdelay, *rcount, *sender, *tmax, *rok;
- int tc, rc;
- /* some servers have a smtp command timeout of 60 seconds so let's be on
- * the safe side and make a default tarpit maximum of 50 seconds
- */
- int max_err = 50, max_ok = 10;
- int max;
-
-
-
-
- if (rc < tc) return 0; /* under limit */
-
-
- if (rc == tc)
-
- switch (*tdelay) {
- case 'N': /* NORMAL */
- sleep(MIN((rc - tc + 1) * 2, max));
- break;
- case 'M': /* MEDIUM */
- sleep(MIN((rc - tc + 1) * 5, max));
- break;
- case 'H': /* HARD */
- sleep(MIN((rc - tc + 1) * (rc - tc + 1), max));
- break;
- default:
- break;
- }
-
- return 0;
- }
-