Exemplo n.º 1
0
Arquivo: divert.c Projeto: bave/prison
int main(int argc, char *argv[])
{
    int fd;

    if (argc < 2) {
        printf("usage: ./a.out port\n");
        return -1;
    }

    fd = open_divert(atoi(argv[1]));
    if (fd < 0)
        return -1;

    read_loop(fd);

    return 0;
}
Exemplo n.º 2
0
int
main(int argc, char *argv[])
{
        int n;
        int begin, end;
        int port;
        nat_type     type;
        time_t       ttl;


        int          ch;
        extern char *optarg;
        extern int   optind;

        progname = argv[0];

        begin = 0;
        end   = 65535;
        ttl   = 300;
        type  = full_cone;
        port  = 0;

        while ((ch = getopt(argc, argv, "p:b:e:t:n:v")) != -1){
                switch (ch){
                case 'p':
                        port = atoi(optarg);
                        break;
                case 'b':
                        begin = atoi(optarg);
                        break;
                case 'e':
                        end = atoi(optarg);
                        break;
                case 't':
                        ttl = atoi(optarg);
                        break;
                case 'n':
                        n = atoi(optarg);
                        if (n == 0) {
                                type = full_cone;
                        } else if (n == 1) {
                                type = restricted_cone;
                        } else if (n == 2) {
                                type = port_restricted_cone;
                        }
                        break;
                case 'v':
                        verbose = true;
                        break;
                default:
                        usage();
                        return -1;
                }
        }
        argc -= optind;
        argv += optind;


        if (port == 0) {
                std::cerr << "please use -p option for divert socket"
                          << std::endl;
                usage();
                return -1;
        }


        filter f(begin, end, type, ttl);
        int fd;

        fd = open_divert(port);
        if (fd < 0) {
                return -1;
        }

        read_loop(fd, f);

        return 0;
}