~ubuntu-branches/ubuntu/oneiric/nmap/oneiric

« back to all changes in this revision

Viewing changes to traceroute.cc

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, fyodor, Davide
  • Date: 2008-05-31 22:55:14 UTC
  • mfrom: (1.2.10 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080531225514-dej22l1clq3nj2o3
Tags: 4.62-1
[fyodor]

* new upstream release

[Davide]

* create an desktop file for zenmap.  Closes: #457799
* remove useless file /usr/bin/uninstall_zenmap.  Closes: #474511

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 * These restrictions only apply when you actually redistribute Nmap.  For *
37
37
 * example, nothing stops you from writing and selling a proprietary       *
38
38
 * front-end to Nmap.  Just distribute it by itself, and point people to   *
39
 
 * http://insecure.org/nmap/ to download Nmap.                             *
 
39
 * http://nmap.org to download Nmap.                                       *
40
40
 *                                                                         *
41
41
 * We don't consider these to be added restrictions on top of the GPL, but *
42
42
 * just a clarification of how we interpret "derived works" as it applies  *
75
75
 * Source code also allows you to port Nmap to new platforms, fix bugs,    *
76
76
 * and add new features.  You are highly encouraged to send your changes   *
77
77
 * to fyodor@insecure.org for possible incorporation into the main         *
78
 
 * distribution.  By sending these changes to Fyodor or one the            *
 
78
 * distribution.  By sending these changes to Fyodor or one of the         *
79
79
 * Insecure.Org development mailing lists, it is assumed that you are      *
80
80
 * offering Fyodor and Insecure.Com LLC the unlimited, non-exclusive right *
81
81
 * to reuse, modify, and relicense the code.  Nmap will always be          *
325
325
    u16 open_port = 1;
326
326
    u16 closed_port = 1;
327
327
    u16 filtered_port = 1;
328
 
    u16 state = 0;
329
328
    u16 port = 0;
 
329
    int state = -1;
330
330
    struct Port *np;
331
331
 
332
332
    /* Use the first specified port for ping traceroutes */
347
347
        open_port = (!scaninfo.open_response) ? 0 : 1;
348
348
    }
349
349
 
350
 
    /* First we try to find an open port, if not we try to find a closed
351
 
     * port and lastly we try to find a filtered port */
352
 
    if (open_port && t->ports.getStateCounts (proto, scaninfo.open_state))
353
 
        state = scaninfo.open_state;
354
 
    else if (closed_port && t->ports.getStateCounts (proto, scaninfo.closed_state))
355
 
        state = scaninfo.closed_state;
356
 
    else if (filtered_port && t->ports.getStateCounts (proto, PORT_FILTERED)) {
 
350
    /* For UDP we try for a closed port, then an open one.  For everything else
 
351
     * we try the opposite.  When all else fails, we try for filtered */
 
352
    if (proto == IPPROTO_UDP) {
 
353
        if (closed_port && t->ports.getStateCounts (proto, scaninfo.closed_state))
 
354
            state = scaninfo.closed_state;
 
355
        else if (open_port && t->ports.getStateCounts (proto, scaninfo.open_state))
 
356
            state = scaninfo.open_state;
 
357
    } else {
 
358
        if (open_port && t->ports.getStateCounts (proto, scaninfo.open_state))
 
359
            state = scaninfo.open_state;
 
360
        else if (closed_port && t->ports.getStateCounts (proto, scaninfo.closed_state))
 
361
            state = scaninfo.closed_state;
 
362
    }
 
363
 
 
364
    if (state == -1 && filtered_port &&
 
365
        t->ports.getStateCounts (proto, PORT_FILTERED)) {
357
366
        state = PORT_FILTERED;
358
367
        if (o.verbose)
359
368
            log_write (LOG_PLAIN, "%s: only filtered %s available, results may be incorrect\n",
360
369
                       t->targetipstr (), o.ipprotscan ? "protocols" : "ports");
361
 
    } else {
 
370
    }
 
371
 
 
372
    if (state == -1)
362
373
        return -1;
363
 
    }
364
374
 
365
375
    np = t->ports.nextPort (NULL, proto, state);
366
376
    if (!np)
733
743
            tg->setState (G_ALIVE_TTL);
734
744
            return -1;
735
745
        }
736
 
        if (!tg->ttl || tg->gotReply && tg->noDistProbe) {
 
746
        if (!tg->ttl || (tg->gotReply && tg->noDistProbe) ) {
737
747
            tg->setState (G_FINISH);
738
748
            return 0;
739
749
        }
1125
1135
        addr.s_addr = commonPath[ttl_count];
1126
1136
        log_write(LOG_XML, "<hop ttl=\"%d\" rtt=\"--\" ", ttl_count);
1127
1137
        log_write(LOG_XML, "ipaddr=\"%s\"", inet_ntoa(addr));
1128
 
        if((hostname_tmp = lookup_cached_host(commonPath[ttl_count])) != "")
 
1138
        if((hostname_tmp = lookup_cached_host(commonPath[ttl_count])) != NULL)
1129
1139
            log_write(LOG_XML, " host=\"%s\"", hostname_tmp);
1130
1140
        log_write(LOG_XML, "/>\n");
1131
1141
    }
1492
1502
 
1493
1503
    memset (nameipbuf, '\0', MAXHOSTNAMELEN + INET6_ADDRSTRLEN);
1494
1504
    addr.s_addr = ip;
1495
 
    if((hname = lookup_cached_host(ip)) == "")
 
1505
    if((hname = lookup_cached_host(ip)) == NULL)
1496
1506
        Snprintf(nameipbuf, MAXHOSTNAMELEN+INET6_ADDRSTRLEN, "%s", inet_ntoa(addr));
1497
1507
    else
1498
1508
        Snprintf (nameipbuf, MAXHOSTNAMELEN + INET6_ADDRSTRLEN, "%s (%s)", hname, inet_ntoa (addr));