Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 28

Discussione: make e warning

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2008
    Messaggi
    50

    make e warning

    Sono neofita della programmazione linux e stavo compilando un file col comando make...quando mi è comparsa la lista di alcuni errori.
    Facendo una ricerca in rete ho scoperto che questi errori compaiono se le funzioni e i tipi di dati usati non sono stati dichiarati negli headers dei file sorgenti relativi.
    Se è giusto, sapreste aiutarmi a risolvere il problema????
    Grazie.javascript:void(0)

    PER FAVOREEEEEEEE..AIUTOOOOOOOO!!!

    trinity@trinity-laptop:~/Mozilla_file/a-saodv$ make
    gcc -Wall -pthread -g -DDEBUG -c -o main.o main.c
    In file included from main.c:33:
    /usr/include/linux/wireless.h:660: error: expected specifier-qualifier-list before ‘__s32’
    /usr/include/linux/wireless.h:673: error: expected specifier-qualifier-list before ‘__u16’
    /usr/include/linux/wireless.h:687: error: expected specifier-qualifier-list before ‘__s32’
    /usr/include/linux/wireless.h:698: error: expected specifier-qualifier-list before ‘__u8’
    /usr/include/linux/wireless.h:714: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:727: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:754: error: expected specifier-qualifier-list before ‘__u8’
    /usr/include/linux/wireless.h:816: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:830: error: expected specifier-qualifier-list before ‘__u16’
    /usr/include/linux/wireless.h:844: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:852: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:861: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:873: error: expected specifier-qualifier-list before ‘__u16’
    /usr/include/linux/wireless.h:896: error: ‘IFNAMSIZ’ undeclared here (not in a function)
    /usr/include/linux/wireless.h:911: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:955: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:1059: error: expected specifier-qualifier-list before ‘__u32’
    /usr/include/linux/wireless.h:1077: error: expected specifier-qualifier-list before ‘__u16’
    main.c: In function ‘get_if_info’:
    main.c:265: error: storage size of ‘ifr’ isn’t known
    main.c:265: warning: unused variable ‘ifr’
    main.c:281: warning: control reaches end of non-void function
    main.c: In function ‘host_init’:
    main.c:369: error: storage size of ‘ifc’ isn’t known
    main.c:370: error: storage size of ‘ifreq’ isn’t known
    main.c:392: error: invalid application of ‘sizeof’ to incomplete type ‘struct ifreq’
    main.c:392: error: increment of pointer to unknown structure
    main.c:392: error: arithmetic on pointer to an incomplete type
    main.c:395: error: ‘struct iwreq’ has no member named ‘ifr_name’
    main.c:395: error: dereferencing pointer to incomplete type
    main.c:397: error: dereferencing pointer to incomplete type
    main.c:370: warning: unused variable ‘ifreq’
    main.c:369: warning: unused variable ‘ifc’
    make: *** [main.o] Error 1
    trinity@trinity-laptop:~/Mozilla_file/a-saodv$

  2. #2

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2008
    Messaggi
    50
    Originariamente inviato da menphisx
    Posta il contenuto di main.c.
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/stat.h>
    #include <linux/sockios.h>
    #include <linux/wireless.h>
    #include <getopt.h>
    #include <ctype.h>
    #include <pthread.h>

    #include <gcrypt.h>
    GCRY_THREAD_OPTION_PTHREAD_IMPL;

    #include "defs.h"
    #include "debug.h"
    #include "timer_queue.h"
    #include "params.h"
    #include "aodv_socket.h"
    #include "aodv_timeout.h"
    #include "k_route.h"
    #include "routing_table.h"
    #include "aodv_hello.h"
    #include "packet_input.h"
    #include "packet_queue.h"
    #include "key.h"
    #include "crypto.h"
    #include "hash.h"
    #include "saodv_adapt.h"

    #ifdef LLFEEDBACK
    #include "llf.h"
    #endif

    /* Global variables: */
    int log_to_file = 0;
    int rt_log_interval = 0; /* msecs between routing table logging 0=off */
    int unidir_hack = 0;
    int rreq_gratuitous = 0;
    int expanding_ring_search = 1;
    int internet_gw_mode = 0;
    int local_repair = 0;
    int receive_n_hellos = 0;
    int hello_jittering = 1;
    int optimized_hellos = 0;
    int ratelimit = 1; /* Option for rate limiting RREQs and RERRs. */
    char *progname;
    int wait_on_reboot = 0;
    int hello_qual_threshold = 0;
    int llfeedback = 0;
    int gw_prefix = 1;
    struct timer worb_timer; /* Wait on reboot timer */
    u_int8_t my_hash_function = HASH_FUNC_SHA1;
    u_int8_t my_hash_function_sign = HASH_FUNC_SIGN_SHA1;
    u_int8_t my_sign_meth;
    int double_sign = 1;

    /* Dynamic configuration values */
    int active_route_timeout = ACTIVE_ROUTE_TIMEOUT_HELLO;
    int ttl_start = TTL_START_HELLO;
    int delete_period = DELETE_PERIOD_HELLO;

    static void cleanup();

    static void store_seqno();
    static void load_seqno();

    struct option longopts[] = {
    {"interface", required_argument, NULL, 'i'},
    {"hello-jitter", no_argument, NULL, 'j'},
    {"log", no_argument, NULL, 'l'},
    {"n-hellos", required_argument, NULL, 'n'},
    {"daemon", no_argument, NULL, 'd'},
    {"force-gratuitous", no_argument, NULL, 'g'},
    {"opt-hellos", no_argument, NULL, 'o'},
    {"quality-threshold", required_argument, NULL, 'q'},
    {"log-rt-table", required_argument, NULL, 'r'},
    {"unidir_hack", no_argument, NULL, 'u'},
    {"gateway-mode", no_argument, NULL, 'w'},
    {"help", no_argument, NULL, 'h'},
    {"no-expanding-ring", no_argument, NULL, 'x'},
    {"worb", no_argument, NULL, 'D'},
    {"local-repair", no_argument, NULL, 'L'},
    {"rate-limit", no_argument, NULL, 'R'},
    {"version", no_argument, NULL, 'V'},
    {"llfeedback", no_argument, NULL, 'f'},
    {"mdalg", required_argument, NULL, 'm'},
    {"mdalg-sign", required_argument, NULL, 's'},
    {"double-sign", no_argument, NULL, 'S'},
    {0}
    };

    void usage(int status)
    {
    if (status != 0) {
    fprintf(stderr, "Try `%s --help' for more information.\n", progname);
    exit(status);
    }

    printf
    ("\nUsage: %s [-dghjlouwxLDRSV] [-i if0,if1,..] [-r N] [-n N] [-q THR] [-m MDALG] [-s MDALG]\n\n"
    "-d, --daemon Daemon mode, i.e. detach from the console.\n"
    "-g, --force-gratuitous Force the gratuitous flag to be set on all RREQ's.\n"
    "-h, --help This information.\n"
    "-i, --interface Network interfaces to attach to. Defaults to first\n"
    " wireless interface.\n"
    "-j, --hello-jitter Toggle hello jittering (default ON).\n"
    "-l, --log Log debug output to %s.\n"
    "-o, --opt-hellos Send HELLOs only when forwarding data (experimental).\n"
    "-r, --log-rt-table Log routing table to %s every N secs.\n"
    "-n, --n-hellos Receive N hellos from host before treating as neighbor.\n"
    "-u, --unidir-hack Detect and avoid unidirectional links (experimental).\n"
    "-w, --gateway-mode Enable experimental Internet gateway support.\n"
    "-x, --no-expanding-ring Disable expanding ring search for RREQs.\n"
    "-D, --worb Enable 15 seconds wait on reboot delay.\n"
    "-L, --local-repair Enable local repair.\n"
    "-f, --llfeedback Enable link layer feedback.\n"
    "-R, --rate-limit Toggle rate limiting of RREQs and RERRs (default ON).\n"
    "-q, --quality-threshold Set a minimum signal quality threshold for control packets.\n"
    "-m, --mdalg Message digest algorithm for hash chain (default sha1).\n"
    "-s, --mdalg-sign Message digest algorithm for signature (default sha1). \n"
    "-S, --double-sign Toggle saodv with/without double signature (default ON), if double signature is disabled set rreq flag destination only also. \n"
    "-V, --version Show version.\n\n"
    "Adaptive SAODV: to modify saodv adaptive threshold echo $new_threshold > %s, "
    "default is to answer always if double signature is enabled.\n"
    "See docs for more information \n\n"
    "Francesco Dolcini, <francesco.dolcini@students.cefriel.it> \n"
    "Erik Nordström, <erik.nordstrom@it.uu.se>\n\n",
    progname, AODV_LOG_PATH, AODV_RT_LOG_PATH, SAODV_ADAPT_FIFO);

    exit(status);
    }

    int set_kernel_options()
    {
    int i, fd = -1;
    char on = '1';
    char off = '0';
    char command[64];

    if ((fd = open("/proc/sys/net/ipv4/ip_forward", O_WRONLY)) < 0)
    return -1;
    if (write(fd, &on, sizeof(char)) < 0)
    return -1;
    close(fd);

    if ((fd = open("/proc/sys/net/ipv4/route/max_delay", O_WRONLY)) < 0)
    return -1;
    if (write(fd, &off, sizeof(char)) < 0)
    return -1;
    close(fd);

    if ((fd = open("/proc/sys/net/ipv4/route/min_delay", O_WRONLY)) < 0)
    return -1;
    if (write(fd, &off, sizeof(char)) < 0)
    return -1;
    close(fd);

    /* Disable ICMP redirects on all interfaces: */

    for (i = 0; i < MAX_NR_INTERFACES; i++) {
    if (!DEV_NR(i).enabled)
    continue;

    memset(command, '\0', 64);
    sprintf(command, "/proc/sys/net/ipv4/conf/%s/send_redirects",
    DEV_NR(i).ifname);
    if ((fd = open(command, O_WRONLY)) < 0)
    return -1;
    if (write(fd, &off, sizeof(char)) < 0)
    return -1;
    close(fd);
    memset(command, '\0', 64);
    sprintf(command, "/proc/sys/net/ipv4/conf/%s/accept_redirects",
    DEV_NR(i).ifname);
    if ((fd = open(command, O_WRONLY)) < 0)
    return -1;
    if (write(fd, &off, sizeof(char)) < 0)
    return -1;
    close(fd);
    }
    memset(command, '\0', 64);
    sprintf(command, "/proc/sys/net/ipv4/conf/all/send_redirects");
    if ((fd = open(command, O_WRONLY)) < 0)
    return -1;
    if (write(fd, &off, sizeof(char)) < 0)
    return -1;
    close(fd);


    memset(command, '\0', 64);
    sprintf(command, "/proc/sys/net/ipv4/conf/all/accept_redirects");
    if ((fd = open(command, O_WRONLY)) < 0)
    return -1;
    if (write(fd, &off, sizeof(char)) < 0)
    return -1;
    close(fd);

    return 0;
    }

    int find_default_gw(void)
    {
    FILE *route;
    char buf[100], *l;

    route = fopen("/proc/net/route", "r");

    if (route == NULL) {
    perror("open /proc/net/route");
    exit(-1);
    }

    while (fgets(buf, sizeof(buf), route)) {
    l = strtok(buf, " \t");
    l = strtok(NULL, " \t");
    if (l != NULL) {
    if (strcmp("00000000", l) == 0) {
    l = strtok(NULL, " \t");
    l = strtok(NULL, " \t");
    if (strcmp("0003", l) == 0) {
    fclose(route);
    return 1;
    }
    }
    }
    }
    fclose(route);
    return 0;
    }

    /*
    * Returns information on a network interface given its name...
    */
    struct sockaddr_in *get_if_info(char *ifname, int type)
    {
    int skfd;
    struct sockaddr_in *ina;
    static struct ifreq ifr;

    /* Get address of interface... */
    skfd = socket(AF_INET, SOCK_DGRAM, 0);

    strcpy(ifr.ifr_name, ifname);
    if (ioctl(skfd, type, &ifr) < 0) {
    alog(LOG_ERR, errno, __FUNCTION__,
    "Could not get address of %s ", ifname);
    close(skfd);
    return NULL;
    } else {
    ina = (struct sockaddr_in *) &ifr.ifr_addr;
    close(skfd);
    return ina;
    }
    }

    /* This will limit the number of handler functions we can have for
    sockets and file descriptors and so on... */
    #define CALLBACK_FUNCS 5
    static struct callback {
    int fd;
    callback_func_t func;
    } callbacks[CALLBACK_FUNCS];

    static int nr_callbacks = 0;

    int attach_callback_func(int fd, callback_func_t func)
    {
    if (nr_callbacks >= CALLBACK_FUNCS) {
    fprintf(stderr, "callback attach limit reached!!\n");
    exit(-1);
    }
    callbacks[nr_callbacks].fd = fd;
    callbacks[nr_callbacks].func = func;
    nr_callbacks++;
    return 0;
    }

    /* Here we find out how to load the kernel modules... If the modules
    are located in the current directory. use those. Otherwise fall
    back to modprobe. */

    void load_modules(char *ifname)
    {
    struct stat st;
    char buf[1024], *l = NULL;
    int found = 0;
    FILE *m;

    memset(buf, '\0', 64);

    sprintf(buf, "/sbin/modprobe ip_queue &>/dev/null");

    system(buf);

    memset(buf, '\0', 64);

    if (stat("./kaodv.ko", &st) == 0)
    sprintf(buf, "/sbin/insmod kaodv.ko ifname=%s qual_th=%d &>/dev/null",
    ifname, hello_qual_threshold);
    else if (stat("./kaodv.o", &st) == 0)
    sprintf(buf, "/sbin/insmod kaodv.o ifname=%s qual_th=%d &>/dev/null",
    ifname, hello_qual_threshold);
    else
    sprintf(buf, "/sbin/modprobe kaodv ifname=%s qual_th=%d &>/dev/null",
    ifname, hello_qual_threshold);

    system(buf);

    /* Check result */
    m = fopen("/proc/modules", "r");
    while (fgets(buf, sizeof(buf), m)) {
    l = strtok(buf, " \t");
    if (!strcmp(l, "kaodv"))
    found++;
    if (!strcmp(l, "ip_queue"))
    found++;
    if (!strcmp(l, "ipchains")) {
    fprintf(stderr,
    "The ipchains kernel module is loaded and prevents AODV-UU from functioning properly.\n");
    exit(-1);
    }
    }
    fclose(m);
    if (found != 2) {
    fprintf(stderr,
    "A kernel module could not be loaded, check your installation...\n");
    exit(-1);
    }
    }

  4. #4
    Utente di HTML.it
    Registrato dal
    Jul 2008
    Messaggi
    50

    seconda parte di main.c

    void remove_modules(void)
    {
    system("/sbin/rmmod kaodv &>/dev/null");
    system("/sbin/rmmod ip_queue &>/dev/null");
    }

    void host_init(char *ifname)
    {
    struct sockaddr_in *ina;
    char buf[1024], tmp_ifname[IFNAMSIZ],
    ifnames[(IFNAMSIZ + 1) * MAX_NR_INTERFACES], *iface;
    struct ifconf ifc;
    struct ifreq ifreq, *ifr;
    int i, iw_sock, if_sock = 0;

    memset(&this_host, 0, sizeof(struct host_info));
    memset(dev_indices, 0, sizeof(unsigned int) * MAX_NR_INTERFACES);

    /* Intitialize the local sequence number an rreq_id to zero */
    this_host.seqno = 1;
    this_host.rreq_id = 0;
    /* load the seqno from file if present */
    load_seqno();

    if (!ifname) {
    /* No interface was given... search for first wireless. */
    iw_sock = socket(PF_INET, SOCK_DGRAM, 0);
    ifc.ifc_len = sizeof(buf);
    ifc.ifc_buf = buf;
    if (ioctl(iw_sock, SIOCGIFCONF, &ifc) < 0) {
    fprintf(stderr, "Could not get wireless info\n");
    exit(-1);
    }
    ifr = ifc.ifc_req;
    for (i = ifc.ifc_len / sizeof(struct ifreq); i >= 0; i--, ifr++) {
    struct iwreq req;

    strcpy(req.ifr_name, ifr->ifr_name);
    if (ioctl(iw_sock, SIOCGIWNAME, &req) >= 0) {
    strcpy(tmp_ifname, ifr->ifr_name);
    break;
    }
    }
    /* Did we find a wireless interface? */
    if (!strlen(tmp_ifname)) {
    fprintf(stderr, "\nCould not find a wireless interface!\n");
    fprintf(stderr, "Use -i <interface> to override...\n\n");
    exit(-1);
    }
    strcpy(ifreq.ifr_name, tmp_ifname);
    if (ioctl(iw_sock, SIOCGIFINDEX, &ifreq) < 0) {
    alog(LOG_ERR, errno, __FUNCTION__,
    "Could not get index of %s", tmp_ifname);
    close(if_sock);
    exit(-1);
    }
    close(iw_sock);

    ifname = tmp_ifname;

    alog(LOG_NOTICE, 0, __FUNCTION__,
    "Attaching to %s, override with -i <if1,if2,...>.", tmp_ifname);
    }

    strcpy(ifnames, ifname);

    /* Zero interfaces enabled so far... */
    this_host.nif = 0;

    gettimeofday(&this_host.bcast_time, NULL);

    /* Find the indices of all interfaces to broadcast on... */
    if_sock = socket(AF_INET, SOCK_DGRAM, 0);

    iface = strtok(ifname, ",");

    /* OK, now lookup interface information, and store it... */
    do {
    strcpy(ifreq.ifr_name, iface);
    if (ioctl(if_sock, SIOCGIFINDEX, &ifreq) < 0) {
    alog(LOG_ERR, errno, __FUNCTION__, "Could not get index of %s",
    iface);
    close(if_sock);
    exit(-1);
    }
    this_host.devs[this_host.nif].ifindex = ifreq.ifr_ifindex;

    dev_indices[this_host.nif++] = ifreq.ifr_ifindex;

    strcpy(DEV_IFINDEX(ifreq.ifr_ifindex).ifname, iface);

    /* Get IP-address of interface... */
    ina = get_if_info(iface, SIOCGIFADDR);
    if (ina == NULL)
    exit(-1);

    DEV_IFINDEX(ifreq.ifr_ifindex).ipaddr = ina->sin_addr;

    /* Get netmask of interface... */
    ina = get_if_info(iface, SIOCGIFNETMASK);
    if (ina == NULL)
    exit(-1);

    DEV_IFINDEX(ifreq.ifr_ifindex).netmask = ina->sin_addr;

    ina = get_if_info(iface, SIOCGIFBRDADDR);
    if (ina == NULL)
    exit(-1);

    DEV_IFINDEX(ifreq.ifr_ifindex).broadcast = ina->sin_addr;

    DEV_IFINDEX(ifreq.ifr_ifindex).enabled = 1;

    if (this_host.nif >= MAX_NR_INTERFACES)
    break;

    } while ((iface = strtok(NULL, ",")));

    close(if_sock);

    /* Load kernel modules */
    load_modules(ifnames);

    /* Enable IP forwarding and set other kernel options... */
    if (set_kernel_options() < 0) {
    fprintf(stderr, "Could not set kernel options!\n");
    exit(-1);
    }
    }
    static void load_seqno() {
    FILE *seqno_fd;
    char buffer[15];
    if ( (seqno_fd = fopen(SEQNO_FILE,"r")) == NULL ) {
    alog(LOG_INFO,0,__FUNCTION__,
    "unable to open file: %s, setting seqno = 1",
    SEQNO_FILE);
    return;
    }
    if ( fgets(buffer,15,seqno_fd) == NULL) {
    fprintf(stderr,"error reading file %s",SEQNO_FILE);
    exit(-1);
    }


    this_host.seqno = atoi(buffer);
    if (this_host.seqno == 0) {
    alog(LOG_DEBUG,0,__FUNCTION__,"seqno=0 not allowed, using 1");
    this_host.seqno = 1;
    }

    DEBUG(LOG_DEBUG,0,"Loaded sequence number %lu",this_host.seqno);

    }

    static void store_seqno() {
    FILE *seqno_fd;
    if ( (seqno_fd = fopen(SEQNO_FILE,"w")) == NULL ) {
    alog(LOG_INFO,0,__FUNCTION__,
    "unable to open file: %s",
    SEQNO_FILE);
    return;
    }
    if (this_host.seqno == 0) {
    alog(LOG_DEBUG,0,__FUNCTION__,"seqno=0 not allowed, using 1");
    this_host.seqno = 1;
    }
    fprintf(seqno_fd,"%u",this_host.seqno);

    DEBUG(LOG_DEBUG,0,"Saved sequence number %lu",this_host.seqno);
    }

    /* This signal handler ensures clean exits */
    void signal_handler(int type)
    {

    switch (type) {
    case SIGSEGV:
    alog(LOG_ERR, 0, __FUNCTION__, "SEGMENTATION FAULT!!!! Exiting!!! "
    "To get a core dump, compile with DEBUG option.");
    case SIGINT:
    case SIGHUP:
    case SIGTERM:
    default:
    exit(0);
    }
    }

    int main(int argc, char **argv)
    {
    static char *ifname = NULL; /* Name of interface to attach to */
    fd_set rfds, readers;
    int n, nfds = 0, i;
    int daemonize = 0;
    struct timeval *timeout;

    /* Remember the name of the executable... */
    progname = strrchr(argv[0], '/');

    if (progname)
    progname++;
    else
    progname = argv[0];

    /* Use debug output as default */
    debug = 1;

    /* init libgcrypt */
    gcry_control (GCRYCTL_SET_THREAD_CBS,&gcry_threads_pthread);
    gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
    if (!gcry_check_version (GCRYPT_VERSION)) {
    printf("libcrypt failed load\n");
    exit(1);
    }

    /* Parse command line: */

    while (1) {
    int opt;

    opt = getopt_long(argc, argv, "i:fjln:dghoq:r:m:s:uwxDLRSV", longopts, 0);

    if (opt == EOF)
    break;

    switch (opt) {
    case 0:
    break;
    case 'd':
    debug = 0;
    daemonize = 1;
    break;
    case 'f':
    llfeedback = 1;
    active_route_timeout = ACTIVE_ROUTE_TIMEOUT_LLF;
    break;
    case 'g':
    rreq_gratuitous = !rreq_gratuitous;
    break;
    case 'i':
    ifname = optarg;
    break;
    case 'j':
    hello_jittering = !hello_jittering;
    break;
    case 'l':
    log_to_file = !log_to_file;
    break;
    case 'n':
    if (optarg && isdigit(*optarg)) {
    receive_n_hellos = atoi(optarg);
    if (receive_n_hellos < 2) {
    fprintf(stderr, "-n should be at least 2!\n");
    exit(-1);
    }
    }
    break;
    case 'o':
    optimized_hellos = !optimized_hellos;
    break;
    case 'q':
    if (optarg && isdigit(*optarg))
    hello_qual_threshold = atoi(optarg);
    break;
    case 'r':
    if (optarg && isdigit(*optarg))
    rt_log_interval = atof(optarg) * 1000;
    break;
    case 'u':
    unidir_hack = !unidir_hack;
    fprintf(stderr, "unidir hack unsupported!\n");
    exit(-1);
    break;
    case 'w':
    internet_gw_mode = !internet_gw_mode;
    fprintf(stderr, "internet gw mode unsupported!\n");
    exit(-1);
    break;
    case 'x':
    expanding_ring_search = !expanding_ring_search;
    break;
    case 'L':
    local_repair = !local_repair;
    break;
    case 'D':
    wait_on_reboot = !wait_on_reboot;
    break;
    case 'S':
    double_sign = !double_sign;
    break;
    case 'R':
    ratelimit = !ratelimit;
    break;
    case 'm':
    my_hash_function = gcry_to_hash(gcry_md_map_name(optarg));
    if (my_hash_function <= 0) {
    fprintf(stderr, "message digest alg not supported\n");
    exit(-1);
    }
    break;
    case 's':
    my_hash_function_sign = gcry_to_hash_f(gcry_md_map_name(optarg));
    if (my_hash_function_sign <= 0) {
    fprintf(stderr, "message digest alg not supported\n");
    exit(-1);
    }
    break;
    case 'V':
    printf
    ("\nSAODV v%s, %s based on AODV-UU %s\n"
    "© CEFRIEL. © Uppsala University & Ericsson AB.\n"
    "Author: Francesco Dolcini, <francesco.dolcini@students.cefriel.it>\n"
    "Author: Erik Nordström, <erik.nordstrom@it.uu.se>\n\n",
    SAODV_VERSION, SAODV_DRAFT_VERSION, AODV_UU_VERSION);
    exit(0);
    break;
    case '?':
    case ':':
    exit(0);
    default:
    usage(0);
    }
    }
    /* Check that we are running as root */
    if (geteuid() != 0) {
    fprintf(stderr, "must be root\n");
    exit(1);
    }

    /* Detach from terminal */
    if (daemonize) {
    if (fork() != 0)
    exit(0);
    /* Close stdin, stdout and stderr... */
    /* close(0); */
    close(1);
    close(2);
    setsid();
    }
    /* Make sure we cleanup at exit... */
    atexit((void *) &cleanup);

    /* Initialize data structures and services... */
    rt_table_init();
    log_init();
    packet_queue_init();
    host_init(ifname);
    packet_input_init();
    aodv_socket_init();
    aodv_ver_pipe_init();
    key_init();
    crypto_init();
    saodv_adapt_init();

    #ifdef LLFEEDBACK
    if (llfeedback) {
    llf_init();
    }
    #endif

    /* Catch SIGHUP, SIGINT and SIGTERM type signals */
    signal(SIGHUP, signal_handler);
    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);

    /* Only capture segmentation faults when we are not debugging... */
    #ifndef DEBUG
    signal(SIGSEGV, signal_handler);
    #endif
    /* Set sockets to watch... */
    FD_ZERO(&readers);
    for (i = 0; i < nr_callbacks; i++) {
    FD_SET(callbacks[i].fd, &readers);
    if (callbacks[i].fd >= nfds)
    nfds = callbacks[i].fd + 1;
    }

    /* Set the wait on reboot timer... */
    if (wait_on_reboot) {
    timer_init(&worb_timer, wait_on_reboot_timeout, &wait_on_reboot);
    timer_set_timeout(&worb_timer, DELETE_PERIOD);
    alog(LOG_NOTICE, 0, __FUNCTION__,
    "In wait on reboot for %d milliseconds. Disable with \"-D\".",
    DELETE_PERIOD);
    }

    /* Schedule the first Hello */
    if (!optimized_hellos && !llfeedback)
    hello_start();

    if (rt_log_interval)
    log_rt_table_init();

    while (1) {
    memcpy((char *) &rfds, (char *) &readers, sizeof(rfds));

    timeout = timer_age_queue();

    if ((n = select(nfds, &rfds, NULL, NULL, timeout)) < 0) {
    if (errno != EINTR)
    alog(LOG_WARNING, errno, __FUNCTION__,
    "Failed select (main loop)");
    continue;
    }

    if (n > 0) {
    for (i = 0; i < nr_callbacks; i++) {
    if (FD_ISSET(callbacks[i].fd, &rfds)) {
    /* We don't want any timer SIGALRM's while executing the
    callback functions, therefore we block the timer... */
    (*callbacks[i].func) (callbacks[i].fd);
    }
    }
    }
    } /* Main loop */
    return 0;
    }

    static void cleanup(void)
    {
    DEBUG(LOG_DEBUG, 0, "CLEANING UP!");
    store_seqno();
    remove_modules();
    rt_table_destroy();
    packet_input_cleanup();
    packet_queue_destroy();
    aodv_socket_cleanup();
    key_cleanup();
    crypto_cleanup();
    saodv_adapt_cleanup();
    #ifdef LLFEEDBACK
    if (llfeedback)
    llf_cleanup();
    #endif
    log_cleanup();
    }

  5. #5
    No scusa intendevo indentato e formattato con i tag appositi -.-
    Comunque adesso gli do un'occhiata.

  6. #6
    Utente di HTML.it
    Registrato dal
    Jul 2008
    Messaggi
    50

    ecco qui

    Originariamente inviato da menphisx
    No scusa intendevo indentato e formattato con i tag appositi -.-
    Comunque adesso gli do un'occhiata.
    javascript:void(0);PERDONO!...no ho letto le regole del forum...ecco qui. Spero di non sbagliare!
    javascript:void(0);

    codice:
    #include <config.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <errno.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <sys/stat.h>
    #include <linux/sockios.h>
    #include <linux/wireless.h>
    #include <getopt.h>
    #include <ctype.h>
    #include <pthread.h>
    
    #include <gcrypt.h>
    GCRY_THREAD_OPTION_PTHREAD_IMPL;
    
    #include "defs.h"
    #include "debug.h"
    #include "timer_queue.h"
    #include "params.h"
    #include "aodv_socket.h"
    #include "aodv_timeout.h"
    #include "k_route.h"
    #include "routing_table.h"
    #include "aodv_hello.h"
    #include "packet_input.h"
    #include "packet_queue.h"
    #include "key.h"
    #include "crypto.h"
    #include "hash.h"
    #include "saodv_adapt.h"
    
    #ifdef LLFEEDBACK
    #include "llf.h"
    #endif
    
    /* Global variables: */
    int log_to_file = 0;
    int rt_log_interval = 0;	/* msecs between routing table logging 0=off */
    int unidir_hack = 0;
    int rreq_gratuitous = 0;
    int expanding_ring_search = 1;
    int internet_gw_mode = 0;
    int local_repair = 0;
    int receive_n_hellos = 0;
    int hello_jittering = 1;
    int optimized_hellos = 0;
    int ratelimit = 1;		/* Option for rate limiting RREQs and RERRs. */
    char *progname;
    int wait_on_reboot = 0;
    int hello_qual_threshold = 0;
    int llfeedback = 0;
    int gw_prefix = 1;
    struct timer worb_timer;	/* Wait on reboot timer */
    u_int8_t my_hash_function = HASH_FUNC_SHA1;
    u_int8_t my_hash_function_sign = HASH_FUNC_SIGN_SHA1;
    u_int8_t my_sign_meth;
    int double_sign = 1;
    
    /* Dynamic configuration values */
    int active_route_timeout = ACTIVE_ROUTE_TIMEOUT_HELLO;
    int ttl_start = TTL_START_HELLO;
    int delete_period = DELETE_PERIOD_HELLO;
    
    static void cleanup();
    
    static void store_seqno();
    static void load_seqno();
    
    struct option longopts[] = {
        {"interface", required_argument, NULL, 'i'},
        {"hello-jitter", no_argument, NULL, 'j'},
        {"log", no_argument, NULL, 'l'},
        {"n-hellos", required_argument, NULL, 'n'},
        {"daemon", no_argument, NULL, 'd'},
        {"force-gratuitous", no_argument, NULL, 'g'},
        {"opt-hellos", no_argument, NULL, 'o'},
        {"quality-threshold", required_argument, NULL, 'q'},
        {"log-rt-table", required_argument, NULL, 'r'},
        {"unidir_hack", no_argument, NULL, 'u'},
        {"gateway-mode", no_argument, NULL, 'w'},
        {"help", no_argument, NULL, 'h'},
        {"no-expanding-ring", no_argument, NULL, 'x'},
        {"worb", no_argument, NULL, 'D'},
        {"local-repair", no_argument, NULL, 'L'},
        {"rate-limit", no_argument, NULL, 'R'},
        {"version", no_argument, NULL, 'V'},
        {"llfeedback", no_argument, NULL, 'f'},
        {"mdalg", required_argument, NULL, 'm'},
        {"mdalg-sign", required_argument, NULL, 's'},
        {"double-sign", no_argument, NULL, 'S'},
        {0}
    };
    
    void usage(int status)
    {
        if (status != 0) {
    	fprintf(stderr, "Try `%s --help' for more information.\n", progname);
    	exit(status);
        }
    
        printf
    	("\nUsage: %s [-dghjlouwxLDRSV] [-i if0,if1,..] [-r N] [-n N] [-q THR] [-m MDALG] [-s MDALG]\n\n"
    	 "-d, --daemon            Daemon mode, i.e. detach from the console.\n"
    	 "-g, --force-gratuitous  Force the gratuitous flag to be set on all RREQ's.\n"
    	 "-h, --help              This information.\n"
    	 "-i, --interface         Network interfaces to attach to. Defaults to first\n"
    	 "                        wireless interface.\n"
    	 "-j, --hello-jitter      Toggle hello jittering (default ON).\n"
    	 "-l, --log               Log debug output to %s.\n"
    	 "-o, --opt-hellos        Send HELLOs only when forwarding data (experimental).\n"
    	 "-r, --log-rt-table      Log routing table to %s every N secs.\n"
    	 "-n, --n-hellos          Receive N hellos from host before treating as neighbor.\n"
    	 "-u, --unidir-hack       Detect and avoid unidirectional links (experimental).\n"
    	 "-w, --gateway-mode      Enable experimental Internet gateway support.\n"
    	 "-x, --no-expanding-ring Disable expanding ring search for RREQs.\n"
    	 "-D, --worb              Enable 15 seconds wait on reboot delay.\n"
    	 "-L, --local-repair      Enable local repair.\n"
    	 "-f, --llfeedback        Enable link layer feedback.\n"
    	 "-R, --rate-limit        Toggle rate limiting of RREQs and RERRs (default ON).\n"
    	 "-q, --quality-threshold Set a minimum signal quality threshold for control packets.\n"
    	 "-m, --mdalg             Message digest algorithm for hash chain (default sha1).\n"
    	 "-s, --mdalg-sign        Message digest algorithm for signature (default sha1). \n"
    	 "-S, --double-sign       Toggle saodv with/without double signature (default ON), if double signature is disabled set rreq flag destination only also. \n"
    	 "-V, --version           Show version.\n\n"
    	 "Adaptive SAODV: to modify saodv adaptive threshold echo $new_threshold > %s, "
    	 "default is to answer always if double signature is enabled.\n"
    	 "See docs for more information \n\n"
    	 "Francesco Dolcini, <francesco.dolcini@students.cefriel.it> \n"
    	 "Erik Nordström, <erik.nordstrom@it.uu.se>\n\n",
    	 progname, AODV_LOG_PATH, AODV_RT_LOG_PATH, SAODV_ADAPT_FIFO);
    
        exit(status);
    }
    
    int set_kernel_options()
    {
        int i, fd = -1;
        char on = '1';
        char off = '0';
        char command[64];
    
        if ((fd = open("/proc/sys/net/ipv4/ip_forward", O_WRONLY)) < 0)
    	return -1;
        if (write(fd, &on, sizeof(char)) < 0)
    	return -1;
        close(fd);
    
        if ((fd = open("/proc/sys/net/ipv4/route/max_delay", O_WRONLY)) < 0)
    	return -1;
        if (write(fd, &off, sizeof(char)) < 0)
    	return -1;
        close(fd);
    
        if ((fd = open("/proc/sys/net/ipv4/route/min_delay", O_WRONLY)) < 0)
    	return -1;
        if (write(fd, &off, sizeof(char)) < 0)
    	return -1;
        close(fd);
    
        /* Disable ICMP redirects on all interfaces: */
    
        for (i = 0; i < MAX_NR_INTERFACES; i++) {
    	if (!DEV_NR(i).enabled)
    	    continue;
    
    	memset(command, '\0', 64);
    	sprintf(command, "/proc/sys/net/ipv4/conf/%s/send_redirects",
    		DEV_NR(i).ifname);
    	if ((fd = open(command, O_WRONLY)) < 0)
    	    return -1;
    	if (write(fd, &off, sizeof(char)) < 0)
    	    return -1;
    	close(fd);
    	memset(command, '\0', 64);
    	sprintf(command, "/proc/sys/net/ipv4/conf/%s/accept_redirects",
    		DEV_NR(i).ifname);
    	if ((fd = open(command, O_WRONLY)) < 0)
    	    return -1;
    	if (write(fd, &off, sizeof(char)) < 0)
    	    return -1;
    	close(fd);
        }
        memset(command, '\0', 64);
        sprintf(command, "/proc/sys/net/ipv4/conf/all/send_redirects");
        if ((fd = open(command, O_WRONLY)) < 0)
    	return -1;
        if (write(fd, &off, sizeof(char)) < 0)
    	return -1;
        close(fd);
    
    
        memset(command, '\0', 64);
        sprintf(command, "/proc/sys/net/ipv4/conf/all/accept_redirects");
        if ((fd = open(command, O_WRONLY)) < 0)
    	return -1;
        if (write(fd, &off, sizeof(char)) < 0)
    	return -1;
        close(fd);
    
        return 0;
    }
    
    int find_default_gw(void)
    {
        FILE *route;
        char buf[100], *l;
    
        route = fopen("/proc/net/route", "r");
    
        if (route == NULL) {
    	perror("open /proc/net/route");
    	exit(-1);
        }
    
        while (fgets(buf, sizeof(buf), route)) {
    	l = strtok(buf, " \t");
    	l = strtok(NULL, " \t");
    	if (l != NULL) {
    	    if (strcmp("00000000", l) == 0) {
    		l = strtok(NULL, " \t");
    		l = strtok(NULL, " \t");
    		if (strcmp("0003", l) == 0) {
    		    fclose(route);
    		    return 1;
    		}
    	    }
    	}
        }
        fclose(route);
        return 0;
    }
    
    /*
     * Returns information on a network interface given its name...
     */
    struct sockaddr_in *get_if_info(char *ifname, int type)
    {
        int skfd;
        struct sockaddr_in *ina;
        static struct ifreq ifr;
    
        /* Get address of interface... */
        skfd = socket(AF_INET, SOCK_DGRAM, 0);
    
        strcpy(ifr.ifr_name, ifname);
        if (ioctl(skfd, type, &ifr) < 0) {
    	alog(LOG_ERR, errno, __FUNCTION__,
    	    "Could not get address of %s ", ifname);
    	close(skfd);
    	return NULL;
        } else {
    	ina = (struct sockaddr_in *) &ifr.ifr_addr;
    	close(skfd);
    	return ina;
        }
    }
    
    /* This will limit the number of handler functions we can have for
       sockets and file descriptors and so on... */
    #define CALLBACK_FUNCS 5
    static struct callback {
        int fd;
        callback_func_t func;
    } callbacks[CALLBACK_FUNCS];
    
    static int nr_callbacks = 0;
    
    int attach_callback_func(int fd, callback_func_t func)
    {
        if (nr_callbacks >= CALLBACK_FUNCS) {
    	fprintf(stderr, "callback attach limit reached!!\n");
    	exit(-1);
        }
        callbacks[nr_callbacks].fd = fd;
        callbacks[nr_callbacks].func = func;
        nr_callbacks++;
        return 0;
    }
    
    /* Here we find out how to load the kernel modules... If the modules
       are located in the current directory. use those. Otherwise fall
       back to modprobe. */
    
    void load_modules(char *ifname)
    {
        struct stat st;
        char buf[1024], *l = NULL;
        int found = 0;
        FILE *m;
    
        memset(buf, '\0', 64);
        
        sprintf(buf, "/sbin/modprobe ip_queue &>/dev/null");
        
        system(buf);
    
        memset(buf, '\0', 64);
        
        if (stat("./kaodv.ko", &st) == 0)
    	sprintf(buf, "/sbin/insmod kaodv.ko ifname=%s qual_th=%d &>/dev/null", 
    		ifname, hello_qual_threshold);
        else if (stat("./kaodv.o", &st) == 0)	
    	sprintf(buf, "/sbin/insmod kaodv.o ifname=%s qual_th=%d &>/dev/null", 
    		ifname, hello_qual_threshold);
        else
    	sprintf(buf, "/sbin/modprobe kaodv ifname=%s qual_th=%d &>/dev/null", 
    		ifname, hello_qual_threshold);
        
        system(buf);
    
        /* Check result */
        m = fopen("/proc/modules", "r");
        while (fgets(buf, sizeof(buf), m)) {
    	l = strtok(buf, " \t");
    	if (!strcmp(l, "kaodv"))
    	    found++;
    	if (!strcmp(l, "ip_queue"))
    	    found++;
    	if (!strcmp(l, "ipchains")) {
    	    fprintf(stderr,
    		    "The ipchains kernel module is loaded and prevents AODV-UU from functioning properly.\n");
    	    exit(-1);
    	}
        }
        fclose(m);
        if (found != 2) {
    	fprintf(stderr,
    		"A kernel module could not be loaded, check your installation...\n");
    	exit(-1);
        }
    }

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2008
    Messaggi
    50

    Re: ecco qui II

    codice:
    void remove_modules(void)
    {
        system("/sbin/rmmod kaodv &>/dev/null");
        system("/sbin/rmmod ip_queue &>/dev/null");
    }
    
    void host_init(char *ifname)
    {
        struct sockaddr_in *ina;
        char buf[1024], tmp_ifname[IFNAMSIZ],
    	ifnames[(IFNAMSIZ + 1) * MAX_NR_INTERFACES], *iface;
        struct ifconf ifc;
        struct ifreq ifreq, *ifr;
        int i, iw_sock, if_sock = 0;
    
        memset(&this_host, 0, sizeof(struct host_info));
        memset(dev_indices, 0, sizeof(unsigned int) * MAX_NR_INTERFACES);
    
        /* Intitialize the local sequence number an rreq_id to zero */
        this_host.seqno = 1;
        this_host.rreq_id = 0;
        /* load the seqno from file if present */
        load_seqno();
    
        if (!ifname) {
    	/* No interface was given... search for first wireless. */
    	iw_sock = socket(PF_INET, SOCK_DGRAM, 0);
    	ifc.ifc_len = sizeof(buf);
    	ifc.ifc_buf = buf;
    	if (ioctl(iw_sock, SIOCGIFCONF, &ifc) < 0) {
    	    fprintf(stderr, "Could not get wireless info\n");
    	    exit(-1);
    	}
    	ifr = ifc.ifc_req;
    	for (i = ifc.ifc_len / sizeof(struct ifreq); i >= 0; i--, ifr++) {
    	    struct iwreq req;
    
    	    strcpy(req.ifr_name, ifr->ifr_name);
    	    if (ioctl(iw_sock, SIOCGIWNAME, &req) >= 0) {
    		strcpy(tmp_ifname, ifr->ifr_name);
    		break;
    	    }
    	}
    	/* Did we find a wireless interface? */
    	if (!strlen(tmp_ifname)) {
    	    fprintf(stderr, "\nCould not find a wireless interface!\n");
    	    fprintf(stderr, "Use -i <interface> to override...\n\n");
    	    exit(-1);
    	}
    	strcpy(ifreq.ifr_name, tmp_ifname);
    	if (ioctl(iw_sock, SIOCGIFINDEX, &ifreq) < 0) {
    	    alog(LOG_ERR, errno, __FUNCTION__,
    		"Could not get index of %s", tmp_ifname);
    	    close(if_sock);
    	    exit(-1);
    	}
    	close(iw_sock);
    
    	ifname = tmp_ifname;
    
    	alog(LOG_NOTICE, 0, __FUNCTION__,
    	    "Attaching to %s, override with -i <if1,if2,...>.", tmp_ifname);
        }
    
        strcpy(ifnames, ifname);
    
        /* Zero interfaces enabled so far... */
        this_host.nif = 0;
    
        gettimeofday(&this_host.bcast_time, NULL);
    
        /* Find the indices of all interfaces to broadcast on... */
        if_sock = socket(AF_INET, SOCK_DGRAM, 0);
    
        iface = strtok(ifname, ",");
    
        /* OK, now lookup interface information, and store it... */
        do {
    	strcpy(ifreq.ifr_name, iface);
    	if (ioctl(if_sock, SIOCGIFINDEX, &ifreq) < 0) {
    	    alog(LOG_ERR, errno, __FUNCTION__, "Could not get index of %s",
    		iface);
    	    close(if_sock);
    	    exit(-1);
    	}
    	this_host.devs[this_host.nif].ifindex = ifreq.ifr_ifindex;
    
    	dev_indices[this_host.nif++] = ifreq.ifr_ifindex;
    
    	strcpy(DEV_IFINDEX(ifreq.ifr_ifindex).ifname, iface);
    
    	/* Get IP-address of interface... */
    	ina = get_if_info(iface, SIOCGIFADDR);
    	if (ina == NULL)
    	    exit(-1);
    
    	DEV_IFINDEX(ifreq.ifr_ifindex).ipaddr = ina->sin_addr;
    
    	/* Get netmask of interface... */
    	ina = get_if_info(iface, SIOCGIFNETMASK);
    	if (ina == NULL)
    	    exit(-1);
    
    	DEV_IFINDEX(ifreq.ifr_ifindex).netmask = ina->sin_addr;
    
    	ina = get_if_info(iface, SIOCGIFBRDADDR);
    	if (ina == NULL)
    	    exit(-1);
    
    	DEV_IFINDEX(ifreq.ifr_ifindex).broadcast = ina->sin_addr;
    
    	DEV_IFINDEX(ifreq.ifr_ifindex).enabled = 1;
    
    	if (this_host.nif >= MAX_NR_INTERFACES)
    	    break;
    
        } while ((iface = strtok(NULL, ",")));
    
        close(if_sock);
    
        /* Load kernel modules */
        load_modules(ifnames);
    
        /* Enable IP forwarding and set other kernel options... */
        if (set_kernel_options() < 0) {
    	fprintf(stderr, "Could not set kernel options!\n");
    	exit(-1);
        }
    }
    
    static void load_seqno() {
    	FILE *seqno_fd;
    	char buffer[15];
    	if ( (seqno_fd = fopen(SEQNO_FILE,"r")) == NULL ) {
    		alog(LOG_INFO,0,__FUNCTION__,
    		 "unable to open file: %s, setting seqno = 1",
    		 SEQNO_FILE);
    		return;
    	}
    	if ( fgets(buffer,15,seqno_fd) == NULL) {
    		fprintf(stderr,"error reading file %s",SEQNO_FILE);
    		exit(-1);
    	}
    
    
    	this_host.seqno = atoi(buffer);
    	if (this_host.seqno == 0) {
    		alog(LOG_DEBUG,0,__FUNCTION__,"seqno=0 not allowed, using 1");
    		this_host.seqno = 1;
    	}
    
    	DEBUG(LOG_DEBUG,0,"Loaded sequence number %lu",this_host.seqno);
    
    }
    
    static void store_seqno() {
    	FILE *seqno_fd;
    	if ( (seqno_fd = fopen(SEQNO_FILE,"w")) == NULL ) {
    		alog(LOG_INFO,0,__FUNCTION__,
    		 "unable to open file: %s",
    		 SEQNO_FILE);
    		return;
    	}
    	if (this_host.seqno == 0) {
    		alog(LOG_DEBUG,0,__FUNCTION__,"seqno=0 not allowed, using 1");
    		this_host.seqno = 1;
    	}
    	fprintf(seqno_fd,"%u",this_host.seqno);
    
    	DEBUG(LOG_DEBUG,0,"Saved sequence number %lu",this_host.seqno);
    }
    
    /* This signal handler ensures clean exits */
    void signal_handler(int type)
    {
    
        switch (type) {
        case SIGSEGV:
    	alog(LOG_ERR, 0, __FUNCTION__, "SEGMENTATION FAULT!!!! Exiting!!! "
    	    "To get a core dump, compile with DEBUG option.");
        case SIGINT:
        case SIGHUP:
        case SIGTERM:
        default:
    	exit(0);
        }
    }
    
    int main(int argc, char **argv)
    {
        static char *ifname = NULL;	/* Name of interface to attach to */
        fd_set rfds, readers;
        int n, nfds = 0, i;
        int daemonize = 0;
        struct timeval *timeout;
    
        /* Remember the name of the executable... */
        progname = strrchr(argv[0], '/');
    
        if (progname)
    	progname++;
        else
    	progname = argv[0];
    
        /* Use debug output as default */
        debug = 1;
    
        /* init libgcrypt */
        gcry_control (GCRYCTL_SET_THREAD_CBS,&gcry_threads_pthread);
        gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
        if (!gcry_check_version (GCRYPT_VERSION)) { 
    	printf("libcrypt failed load\n"); 
    	exit(1); 
        }
    
        /* Parse command line: */
    
        while (1) {
    	int opt;
    
    	opt = getopt_long(argc, argv, "i:fjln:dghoq:r:m:s:uwxDLRSV", longopts, 0);
    
    	if (opt == EOF)
    	    break;
    
    	switch (opt) {
    	case 0:
    	    break;
    	case 'd':
    	    debug = 0;
    	    daemonize = 1;
    	    break;
    	case 'f':
    	    llfeedback = 1;
    	    active_route_timeout = ACTIVE_ROUTE_TIMEOUT_LLF;
    	    break; 
    	case 'g':
    	    rreq_gratuitous = !rreq_gratuitous;
    	    break;
    	case 'i':
    	    ifname = optarg;
    	    break;
    	case 'j':
    	    hello_jittering = !hello_jittering;
    	    break;
    	case 'l':
    	    log_to_file = !log_to_file;
    	    break;
    	case 'n':
    	    if (optarg && isdigit(*optarg)) {
    		receive_n_hellos = atoi(optarg);
    		if (receive_n_hellos < 2) {
    		    fprintf(stderr, "-n should be at least 2!\n");
    		    exit(-1);
    		}
    	    }
    	    break;
    	case 'o':
    	    optimized_hellos = !optimized_hellos;
    	    break;
    	case 'q':
    	    if (optarg && isdigit(*optarg))
    		hello_qual_threshold = atoi(optarg);
    	    break;
    	case 'r':
    	    if (optarg && isdigit(*optarg))
    		rt_log_interval = atof(optarg) * 1000;
    	    break;
    	case 'u':
    	    unidir_hack = !unidir_hack;
    	    fprintf(stderr, "unidir hack unsupported!\n");
    	    exit(-1);
    	    break;
    	case 'w':
    	    internet_gw_mode = !internet_gw_mode;
    	    fprintf(stderr, "internet gw mode unsupported!\n");
    	    exit(-1);
    	    break;
    	case 'x':
    	    expanding_ring_search = !expanding_ring_search;
    	    break;
    	case 'L':
    	    local_repair = !local_repair;
    	    break;
    	case 'D':
    	    wait_on_reboot = !wait_on_reboot;
    	    break;
    	case 'S':
    	    double_sign = !double_sign;
    	    break;
    	case 'R':
    	    ratelimit = !ratelimit;
    	    break;
    	case 'm':
    	    my_hash_function = gcry_to_hash(gcry_md_map_name(optarg));
    	    if (my_hash_function <= 0) {
    		    fprintf(stderr, "message digest alg not supported\n");
    		    exit(-1);
    	    }
    	    break;
    	case 's':
    	    my_hash_function_sign = gcry_to_hash_f(gcry_md_map_name(optarg));
    	    if (my_hash_function_sign <= 0) {
    		    fprintf(stderr, "message digest alg not supported\n");
    		    exit(-1);
    	    }
    	    break;
    	case 'V':
    	    printf
    		("\nSAODV v%s, %s based on AODV-UU %s\n"
    		 "© CEFRIEL. © Uppsala University & Ericsson AB.\n"
    		 "Author: Francesco Dolcini, <francesco.dolcini@students.cefriel.it>\n"
    		 "Author: Erik Nordström, <erik.nordstrom@it.uu.se>\n\n",
    		 SAODV_VERSION, SAODV_DRAFT_VERSION, AODV_UU_VERSION);
    	    exit(0);
    	    break;
    	case '?':
    	case ':':
    	    exit(0);
    	default:
    	    usage(0);
    	}
        }
        /* Check that we are running as root */
        if (geteuid() != 0) {
    	fprintf(stderr, "must be root\n");
    	exit(1);
        }
    
        /* Detach from terminal */
        if (daemonize) {
    	if (fork() != 0)
    	    exit(0);
    	/* Close stdin, stdout and stderr... */
    	/*  close(0); */
    	close(1);
    	close(2);
    	setsid();
        }
        /* Make sure we cleanup at exit... */
        atexit((void *) &cleanup);
    
        /* Initialize data structures and services... */
        rt_table_init();
        log_init();
        packet_queue_init();
        host_init(ifname);
        packet_input_init();
        aodv_socket_init();
        aodv_ver_pipe_init();
        key_init();
        crypto_init();
        saodv_adapt_init();
    
    #ifdef LLFEEDBACK
        if (llfeedback) {
    	llf_init();
        }
    #endif
    
        /* Catch SIGHUP, SIGINT and SIGTERM type signals */
        signal(SIGHUP, signal_handler);
        signal(SIGINT, signal_handler);
        signal(SIGTERM, signal_handler);
    
        /* Only capture segmentation faults when we are not debugging... */
    #ifndef DEBUG
        signal(SIGSEGV, signal_handler);
    #endif
        /* Set sockets to watch... */
        FD_ZERO(&readers);
        for (i = 0; i < nr_callbacks; i++) {
    	FD_SET(callbacks[i].fd, &readers);
    	if (callbacks[i].fd >= nfds)
    	    nfds = callbacks[i].fd + 1;
        }
    
        /* Set the wait on reboot timer... */
        if (wait_on_reboot) {
    	timer_init(&worb_timer, wait_on_reboot_timeout, &wait_on_reboot);
    	timer_set_timeout(&worb_timer, DELETE_PERIOD);
    	alog(LOG_NOTICE, 0, __FUNCTION__,
    	    "In wait on reboot for %d milliseconds. Disable with \"-D\".",
    	    DELETE_PERIOD);
        }
    
        /* Schedule the first Hello */
        if (!optimized_hellos && !llfeedback)
    	hello_start();
    
        if (rt_log_interval)
    	log_rt_table_init();
    
        while (1) {
    	memcpy((char *) &rfds, (char *) &readers, sizeof(rfds));
    
    	timeout = timer_age_queue();
    	
    	if ((n = select(nfds, &rfds, NULL, NULL, timeout)) < 0) {
    	    if (errno != EINTR)
    		alog(LOG_WARNING, errno, __FUNCTION__,
    		    "Failed select (main loop)");
    	    continue;
    	}
    	
    	if (n > 0) {
    	    for (i = 0; i < nr_callbacks; i++) {
    		if (FD_ISSET(callbacks[i].fd, &rfds)) {
    		    /* We don't want any timer SIGALRM's while executing the
    		       callback functions, therefore we block the timer... */
    		    (*callbacks[i].func) (callbacks[i].fd);
    		}
    	    }
    	} 
        }				/* Main loop */
        return 0;
    }
    
    static void cleanup(void)
    {
        DEBUG(LOG_DEBUG, 0, "CLEANING UP!");
        store_seqno();
        remove_modules();
        rt_table_destroy();
        packet_input_cleanup();
        packet_queue_destroy();
        aodv_socket_cleanup();
        key_cleanup();
        crypto_cleanup();
        saodv_adapt_cleanup();
    #ifdef LLFEEDBACK
        if (llfeedback) 
    	llf_cleanup();
    #endif
        log_cleanup();
    }
    Con questo aiuto sappi di essere una goccia nel deserto in cui ora mi trovo...quindi molto importante!!! grazie

  8. #8
    Utente di HTML.it
    Registrato dal
    Jul 2008
    Messaggi
    50

    un'informazione forse utile?

    Sto cercando di installare sul mio pc l'implementazione di un protocollo di sicurezza delle MANET (mobile ad hoc network)....una rete wifi di nodi tutti mobili.
    L'implementazione è chiamata A-SAODV, e il codice che sto studiando è preso dal seguente sito:

    http://saodv.cefriel.it/.

    Uso ubuntu 8.04, Linux trinity-laptop 2.6.24-19-generic #1 UTC 2008 i686 GNU/Linu

    javascript:void(0);

  9. #9

    Re: un'informazione forse utile?

    Originariamente inviato da edel
    Sto cercando di installare sul mio pc l'implementazione di un protocollo di sicurezza delle MANET (mobile ad hoc network)....una rete wifi di nodi tutti mobili.
    L'implementazione è chiamata A-SAODV, e il codice che sto studiando è preso dal seguente sito:

    http://saodv.cefriel.it/.

    Uso ubuntu 8.04, Linux trinity-laptop 2.6.24-19-generic #1 UTC 2008 i686 GNU/Linu

    javascript:void(0);
    Posta anche il contenuto di /usr/include/linux/wireless.h.
    Farò il possibile per aiutarti, anche se diciamo è un po' complicato ...

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2008
    Messaggi
    50
    codice:
    /*
     * This file define a set of standard wireless extensions
     *
     * Version :	22	16.3.07
     *
     * Authors :	Jean Tourrilhes - HPL - <jt@hpl.hp.com>
     * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved.
     */
    
    #ifndef _LINUX_WIRELESS_H
    #define _LINUX_WIRELESS_H
    
    #define WIRELESS_EXT	22
    /**************************** CONSTANTS ****************************/
    
    /* -------------------------- IOCTL LIST -------------------------- */
    
    /* Wireless Identification */
    #define SIOCSIWCOMMIT	0x8B00		/* Commit pending changes to driver */
    #define SIOCGIWNAME	0x8B01		/* get name == wireless protocol */
    /* SIOCGIWNAME is used to verify the presence of Wireless Extensions.
     * Common values : "IEEE 802.11-DS", "IEEE 802.11-FH", "IEEE 802.11b"...
     * Don't put the name of your driver there, it's useless. */
    
    /* Basic operations */
    #define SIOCSIWNWID	0x8B02		/* set network id (pre-802.11) */
    #define SIOCGIWNWID	0x8B03		/* get network id (the cell) */
    #define SIOCSIWFREQ	0x8B04		/* set channel/frequency (Hz) */
    #define SIOCGIWFREQ	0x8B05		/* get channel/frequency (Hz) */
    #define SIOCSIWMODE	0x8B06		/* set operation mode */
    #define SIOCGIWMODE	0x8B07		/* get operation mode */
    #define SIOCSIWSENS	0x8B08		/* set sensitivity (dBm) */
    #define SIOCGIWSENS	0x8B09		/* get sensitivity (dBm) */
    
    /* Informative stuff */
    #define SIOCSIWRANGE	0x8B0A		/* Unused */
    #define SIOCGIWRANGE	0x8B0B		/* Get range of parameters */
    #define SIOCSIWPRIV	0x8B0C		/* Unused */
    #define SIOCGIWPRIV	0x8B0D		/* get private ioctl interface info */
    #define SIOCSIWSTATS	0x8B0E		/* Unused */
    #define SIOCGIWSTATS	0x8B0F		/* Get /proc/net/wireless stats */
    /* SIOCGIWSTATS is strictly used between user space and the kernel, and
     * is never passed to the driver (i.e. the driver will never see it). */
    
    /* Spy support (statistics per MAC address - used for Mobile IP support) */
    #define SIOCSIWSPY	0x8B10		/* set spy addresses */
    #define SIOCGIWSPY	0x8B11		/* get spy info (quality of link) */
    #define SIOCSIWTHRSPY	0x8B12		/* set spy threshold (spy event) */
    #define SIOCGIWTHRSPY	0x8B13		/* get spy threshold */
    
    /* Access Point manipulation */
    #define SIOCSIWAP	0x8B14		/* set access point MAC addresses */
    #define SIOCGIWAP	0x8B15		/* get access point MAC addresses */
    #define SIOCGIWAPLIST	0x8B17		/* Deprecated in favor of scanning */
    #define SIOCSIWSCAN	0x8B18		/* trigger scanning (list cells) */
    #define SIOCGIWSCAN	0x8B19		/* get scanning results */
    
    /* 802.11 specific support */
    #define SIOCSIWESSID	0x8B1A		/* set ESSID (network name) */
    #define SIOCGIWESSID	0x8B1B		/* get ESSID */
    #define SIOCSIWNICKN	0x8B1C		/* set node name/nickname */
    #define SIOCGIWNICKN	0x8B1D		/* get node name/nickname */
    /* As the ESSID and NICKN are strings up to 32 bytes long, it doesn't fit
     * within the 'iwreq' structure, so we need to use the 'data' member to
     * point to a string in user space, like it is done for RANGE... */
    
    /* Other parameters useful in 802.11 and some other devices */
    #define SIOCSIWRATE	0x8B20		/* set default bit rate (bps) */
    #define SIOCGIWRATE	0x8B21		/* get default bit rate (bps) */
    #define SIOCSIWRTS	0x8B22		/* set RTS/CTS threshold (bytes) */
    #define SIOCGIWRTS	0x8B23		/* get RTS/CTS threshold (bytes) */
    #define SIOCSIWFRAG	0x8B24		/* set fragmentation thr (bytes) */
    #define SIOCGIWFRAG	0x8B25		/* get fragmentation thr (bytes) */
    #define SIOCSIWTXPOW	0x8B26		/* set transmit power (dBm) */
    #define SIOCGIWTXPOW	0x8B27		/* get transmit power (dBm) */
    #define SIOCSIWRETRY	0x8B28		/* set retry limits and lifetime */
    #define SIOCGIWRETRY	0x8B29		/* get retry limits and lifetime */
    
    /* Encoding stuff (scrambling, hardware security, WEP...) */
    #define SIOCSIWENCODE	0x8B2A		/* set encoding token & mode */
    #define SIOCGIWENCODE	0x8B2B		/* get encoding token & mode */
    /* Power saving stuff (power management, unicast and multicast) */
    #define SIOCSIWPOWER	0x8B2C		/* set Power Management settings */
    #define SIOCGIWPOWER	0x8B2D		/* get Power Management settings */
    
    /* WPA : Generic IEEE 802.11 informatiom element (e.g., for WPA/RSN/WMM).
     * This ioctl uses struct iw_point and data buffer that includes IE id and len
     * fields. More than one IE may be included in the request. Setting the generic
     * IE to empty buffer (len=0) removes the generic IE from the driver. Drivers
     * are allowed to generate their own WPA/RSN IEs, but in these cases, drivers
     * are required to report the used IE as a wireless event, e.g., when
     * associating with an AP. */
    #define SIOCSIWGENIE	0x8B30		/* set generic IE */
    #define SIOCGIWGENIE	0x8B31		/* get generic IE */
    
    /* WPA : IEEE 802.11 MLME requests */
    #define SIOCSIWMLME	0x8B16		/* request MLME operation; uses
    					 * struct iw_mlme */
    /* WPA : Authentication mode parameters */
    #define SIOCSIWAUTH	0x8B32		/* set authentication mode params */
    #define SIOCGIWAUTH	0x8B33		/* get authentication mode params */
    
    /* WPA : Extended version of encoding configuration */
    #define SIOCSIWENCODEEXT 0x8B34		/* set encoding token & mode */
    #define SIOCGIWENCODEEXT 0x8B35		/* get encoding token & mode */
    
    /* WPA2 : PMKSA cache management */
    #define SIOCSIWPMKSA	0x8B36		/* PMKSA cache operation */
    
    /* -------------------- DEV PRIVATE IOCTL LIST -------------------- */
    
    /* These 32 ioctl are wireless device private, for 16 commands.
     * Each driver is free to use them for whatever purpose it chooses,
     * however the driver *must* export the description of those ioctls
     * with SIOCGIWPRIV and *must* use arguments as defined below.
     * If you don't follow those rules, DaveM is going to hate you (reason :
     * it make mixed 32/64bit operation impossible).
     */
    #define SIOCIWFIRSTPRIV	0x8BE0
    #define SIOCIWLASTPRIV	0x8BFF
    /* Previously, we were using SIOCDEVPRIVATE, but we now have our
     * separate range because of collisions with other tools such as
     * 'mii-tool'.
     * We now have 32 commands, so a bit more space ;-).
     * Also, all 'even' commands are only usable by root and don't return the
     * content of ifr/iwr to user (but you are not obliged to use the set/get
     * convention, just use every other two command). More details in iwpriv.c.
     * And I repeat : you are not forced to use them with iwpriv, but you
     * must be compliant with it.
     */
    
    /* ------------------------- IOCTL STUFF ------------------------- */
    
    /* The first and the last (range) */
    #define SIOCIWFIRST	0x8B00
    #define SIOCIWLAST	SIOCIWLASTPRIV		/* 0x8BFF */
    #define IW_IOCTL_IDX(cmd)	((cmd) - SIOCIWFIRST)
    
    /* Odd : get (world access), even : set (root access) */
    #define IW_IS_SET(cmd)	(!((cmd) & 0x1))
    #define IW_IS_GET(cmd)	((cmd) & 0x1)
    
    /* ----------------------- WIRELESS EVENTS ----------------------- */
    /* Those are *NOT* ioctls, do not issue request on them !!! */
    /* Most events use the same identifier as ioctl requests */
    
    #define IWEVTXDROP	0x8C00		/* Packet dropped to excessive retry */
    #define IWEVQUAL	0x8C01		/* Quality part of statistics (scan) */
    #define IWEVCUSTOM	0x8C02		/* Driver specific ascii string */
    #define IWEVREGISTERED	0x8C03		/* Discovered a new node (AP mode) */
    #define IWEVEXPIRED	0x8C04		/* Expired a node (AP mode) */
    #define IWEVGENIE	0x8C05		/* Generic IE (WPA, RSN, WMM, ..)
    					 * (scan results); This includes id and
    					 * length fields. One IWEVGENIE may
    					 * contain more than one IE. Scan
    					 * results may contain one or more
    					 * IWEVGENIE events. */
    #define IWEVMICHAELMICFAILURE 0x8C06	/* Michael MIC failure
    					 * (struct iw_michaelmicfailure)
    					 */
    #define IWEVASSOCREQIE	0x8C07		/* IEs used in (Re)Association Request.
    					 * The data includes id and length
    					 * fields and may contain more than one
    					 * IE. This event is required in
    					 * Managed mode if the driver
    					 * generates its own WPA/RSN IE. This
    					 * should be sent just before
    					 * IWEVREGISTERED event for the
    					 * association. */
    #define IWEVASSOCRESPIE	0x8C08		/* IEs used in (Re)Association
    					 * Response. The data includes id and
    					 * length fields and may contain more
    					 * than one IE. This may be sent
    					 * between IWEVASSOCREQIE and
    					 * IWEVREGISTERED events for the
    					 * association. */
    #define IWEVPMKIDCAND	0x8C09		/* PMKID candidate for RSN
    					 * pre-authentication
    					 * (struct iw_pmkid_cand) */
    
    #define IWEVFIRST	0x8C00
    #define IW_EVENT_IDX(cmd)	((cmd) - IWEVFIRST)
    
    /* ------------------------- PRIVATE INFO ------------------------- */
    /*
     * The following is used with SIOCGIWPRIV. It allow a driver to define
     * the interface (name, type of data) for its private ioctl.
     * Privates ioctl are SIOCIWFIRSTPRIV -> SIOCIWLASTPRIV
     */
    
    #define IW_PRIV_TYPE_MASK	0x7000	/* Type of arguments */
    #define IW_PRIV_TYPE_NONE	0x0000
    #define IW_PRIV_TYPE_BYTE	0x1000	/* Char as number */
    #define IW_PRIV_TYPE_CHAR	0x2000	/* Char as character */
    #define IW_PRIV_TYPE_INT	0x4000	/* 32 bits int */
    #define IW_PRIV_TYPE_FLOAT	0x5000	/* struct iw_freq */
    #define IW_PRIV_TYPE_ADDR	0x6000	/* struct sockaddr */
    
    #define IW_PRIV_SIZE_FIXED	0x0800	/* Variable or fixed number of args */
    
    #define IW_PRIV_SIZE_MASK	0x07FF	/* Max number of those args */
    
    /*
     * Note : if the number of args is fixed and the size < 16 octets,
     * instead of passing a pointer we will put args in the iwreq struct...
     */

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.