"Fossies" - the Fresh Open Source Software Archive

Member "rblchk-1.1/rblchk.c" (15 Jan 2007, 2320 Bytes) of package /linux/privat/old/rblchk-1.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "rblchk.c" see the Fossies "Dox" file reference documentation.

    1 /*  Copyright (C) 2005-2007 Eugene Kurmanin <me@kurmanin.info>
    2  *
    3  *  This program is free software; you can redistribute it and/or modify
    4  *  it under the terms of the GNU General Public License as published by
    5  *  the Free Software Foundation; either version 2 of the License, or
    6  *  (at your option) any later version.
    7  *
    8  *  This program is distributed in the hope that it will be useful,
    9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11  *  GNU General Public License for more details.
   12  *
   13  *  You should have received a copy of the GNU General Public License
   14  *  along with this program; if not, write to the Free Software
   15  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   16  */
   17 
   18 #include <arpa/inet.h>
   19 #include <netdb.h>
   20 #include <stdio.h>
   21 
   22 int check_rbl(const char *lookup_addr, const char *rbl) {
   23     char lookup_name[64];
   24     struct addrinfo *ai = NULL;
   25 
   26     snprintf(lookup_name, sizeof(lookup_name), "%s.%s.", lookup_addr, rbl);
   27     if (getaddrinfo(lookup_name, NULL, NULL, &ai)) {
   28     if (ai) freeaddrinfo(ai);
   29     return 0;
   30     }
   31     freeaddrinfo(ai);
   32     return 1;
   33 }
   34 
   35 int main(int argc, char *argv[]) {
   36     char addr[16];
   37     unsigned long address;
   38 
   39     printf("RBLchk v1.1 (C) 2005-2007 Eugene Kurmanin - http://smfs.sf.net/\n\n");
   40     if (argc == 1) {
   41     printf("Usage: rblchk 127.0.0.2\n");
   42     return -1;
   43     }
   44     address = inet_addr(argv[1]);
   45     snprintf(addr, sizeof(addr), "%lu.%lu.%lu.%lu",
   46     (address & 0xff000000) >> 24,
   47     (address & 0x00ff0000) >> 16,
   48     (address & 0x0000ff00) >> 8,
   49     (address & 0x000000ff) >> 0);
   50     if (check_rbl(addr, "cbl.abuseat.org"))
   51     printf("CBL\tListed, look at http://cbl.abuseat.org/lookup.cgi?ip=%s\n", argv[1]);
   52     else
   53     printf("CBL\tNot listed\n");
   54     if (check_rbl(addr, "sbl.spamhaus.org"))
   55     printf("SBL\tListed, look at http://www.spamhaus.org/query/bl?ip=%s\n", argv[1]);
   56     else
   57     printf("SBL\tNot listed\n");
   58     if (check_rbl(addr, "combined.njabl.org"))
   59     printf("NJABL\tListed, look at http://njabl.org/cgi-bin/lookup.cgi?query=%s\n", argv[1]);
   60     else
   61     printf("NJABL\tNot listed\n");
   62     if (check_rbl(addr, "bl.spamcop.net"))
   63     printf("SPAMCOP\tListed, look at http://www.spamcop.net/bl.shtml?%s\n", argv[1]);
   64     else
   65     printf("SPAMCOP\tNot listed\n");
   66     return 0;
   67 }
   68