1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-08 21:51:28 +00:00
Commit Graph

92 Commits

Author SHA1 Message Date
david
685f5fa4c3 Define SOLARIS_BPF_PCAP_CAPTURE for Solaris 11.
Solaris 11 uses BPF packet capture rather than DLPI, which requires
different handling in many cases. The new preprocessor symbol tells when
this is the case; it is additional granularity on top of SOLARIS.
2012-04-07 08:07:41 +00:00
david
664dff4644 Add a long comment about Solaris 11 BPF.
I was surprised when I found that Solaris 11 scanning works now. I
thought that it would require a change in the defines around
pcap_selectable_fd_valid, because it's valid for Solaris 10 and earlier
but not for Solaris 11. Why it started working was the
pcap_selectable_fd_one_to_one test added in r28319. As a side effect of
that function overrides pcap_selectable_fd_valid for all Solaris
releases, it makes changes in pcap_selectable_fd_valid unnecessary.
However it is indirect in the way it does it, so I'm adding a comment
explaining the situation and a hope that there is an easy change to make
pcap_selectable_fd_valid correct on its own.
2012-04-03 23:06:07 +00:00
david
9958ed8ebe Protect pcap_selectable_fd_valid from platforms that don't have it.
Thanks jah for catching this.
2012-03-24 01:52:43 +00:00
david
cdcc9da0d8 Fix a bug in the last commit: need another level of indirection on packet pointer. 2012-03-22 00:32:31 +00:00
david
5008078dac Add a non-blocking workaround for pcaps that buffer packets.
This is designed to solve the following problem: On Solaris 10 (maybe other
platforms), doing a select on a pcap fd works, in that it returns true when
there are frames available to be read. However, after finding the fd selectable
and calling pcap_dispatch (or pcap_next, etc.), libpcap may read more than one
frame and buffer them internally. This means that later calls to select will
return false. So there may be a frame to be read, but you can't know without
calling pcap_dispatch to check, and that blocks indefinitely (on Solaris) if
you're wrong.

The way this works is that we do a non-blocking read on the pcap fd to see if
there is anything available. If not, we do a select with a timeout as usual.
(The select is to enforce the timeout and prevent spinning CPU by repeatedly
trying non-blocking reads.)

I don't know if this phenomenon affects other platforms than Solaris 10
(more specifically, platforms using DLPI for libpcap). This same thing may be
safe or necessary on other platforms. But I have limited it to Solaris for now.
Solaris 11 uses BPF, not DLPI, for libpcap, but we can unconditionally follow
this code path on Solaris because BPF pcap fds can't be selected on.
2012-03-22 00:29:30 +00:00
david
e8c4db180d Don't duplicate #ifdefs. 2012-03-21 23:14:26 +00:00
david
f0f1419c5f Rearrange and document. 2012-03-21 23:04:13 +00:00
david
560e663867 Factor out common code from read_arp_reply_pcap and read_ns_reply_pcap. 2012-03-21 23:03:42 +00:00
david
29a4522c33 Pass a length argument to frame_is_arp. 2012-03-21 21:32:04 +00:00
david
8124bf69b9 More attempted header rearrangement for AIX compatibility. 2012-03-19 16:26:39 +00:00
david
2a71786fb9 Revert "Include <net/if.h> before <net/if_arp.h>" in netutil.cc.
This seems be broken on AIX 5.3.
2012-03-12 23:00:04 +00:00
david
941d609eef Include <net/if.h> before <net/if_arp.h>.
This may fix some build problems on AIX 5.3.
2012-03-07 03:39:11 +00:00
fyodor
684f42c4ad One more adjustment to the license text. Notes that Zenmap, Ncat, and Nping use this license. Note that contributions made directly in the src repository are treated the same as those in the mailing list. 2012-03-01 06:53:35 +00:00
fyodor
e96a7b7b24 Update the headers for each code file. This updates code copyright dates to 2012, notes the awesome NSE in the list of technology, and slightly rewords the derivative works clarification 2012-03-01 06:32:23 +00:00
david
49c6b65a5a Fix the display of "Unknown protocol" in ippackethdrinfo.
nexthdrtoa always returns the same static buffer, so it is never NULL.
Check for an empty string instead.
2012-02-24 05:01:41 +00:00
david
c1e1a12e2c Use ip_get_data_any, not ip_get_data, in ippackethdrinfo.
The difference is that ip_get_data_any doesn't require there to be an
upper-layer header at the end of an IPv6 chain. This avoids the message
"BOGUS!  Can't parse supposed IP packet" during -sO -6 scan. The -sO
sends non–upper-layer headers, some even with empty payloads, and so
causes this situation often.
2012-02-24 05:01:41 +00:00
david
d1ef18a245 Disable "WARNING: Unable to find appropriate interface for system route to...".
This often comes up these days with IPv6 routes that don't seem to
affect scanning. I don't think we have problems with routes being
removed when they shouldn't be anymore.
2011-12-23 05:05:07 +00:00
david
02ff5e83b6 Comment typo. 2011-11-27 19:50:17 +00:00
david
06b69fa9a3 Make some args const. 2011-10-29 19:40:15 +00:00
david
17e54e2d0e Document ip_get_data and ip_get_data_any. 2011-10-29 19:40:14 +00:00
david
c21d62d4e6 Revert r26741.
This makes Nmap assume that pcap sockets are selectable on Solaris again. I had
originally tested this on Solaris x86, and couldn't get a scan to complete witho
ut this change. But it was reported that it fails on Solaris SPARC (scans take a
 long time, indicating that pcap calls are blocking longer than their timeout).
I just tested it again on Solaris x86, and now I can't get a scan to complete wi
th r26741. So reverting.
2011-10-22 01:09:30 +00:00
david
6987814beb Remove extra const qualifiers.
Some function declared parameters like this:
	int f(const char * const s)
Where appropriate, I changed to
	int f(const char *s)

The second const is a qualifier on the pointer itself; i.e., the value
of s may not be changed (may not be made to point to anything else)
within the function. This is probably not what was intended. The first
const is what prevents modifying things referenced through s.
2011-10-13 20:52:03 +00:00
david
293a073c92 pcap sockets appear not to be selectable on Solaris. 2011-09-29 22:23:15 +00:00
david
c87da9aa8b Avoid using parameter names that are #defined on AIX.
AIX defines various things like ip_id as some implementation-dependent
submember of struct ip.
2011-09-21 07:31:37 +00:00
david
75f753b441 Rearrange include for AIX. 2011-09-21 07:31:35 +00:00
david
9bf2ec3884 Merge from /nmap-exp/luis/nmap-os6.
svn merge --ignore-ancestry svn://svn.insecure.org/nmap@26621 svn://svn.insecure.org/nmap-exp/luis/nmap-os6

This is the IPv6 OS detection branch. "nmap -6 -O" works now, though at
this point it only prints fingerprints and not OS guesses, because we
need to collect more submissions.
2011-09-19 18:31:46 +00:00
david
f41753c4e9 Add a sockaddr dst argument to send_ip function that use raw sockets.
Heretofore we have always extracted teh destination address directly
from the packet contents. But the raw packet bytes do not contain enough
information in one case: IPv6 link-local addresses. For those we really
need the scope ID, and for that we must pass this information all the
way down.

Before this, I got "no route to host" on OS link-local addresses. I
think that it was working on Linux only on accident, by the OS picking a
default interface or something.
2011-09-19 16:13:35 +00:00
david
d91b131da0 Make various accessors and parameters const. 2011-09-19 16:13:33 +00:00
david
5898afd06b Canonicalize interface addresses returned from libdnet.
Mac OS X appears to have a new address convention that I can't find
documented. The link-local address fe80:4::X:X:X:X stands for
fe80::X:X:X:X%en0, if en0 is the interface with index 4. (I.e., it would
be fe80::X:X:X:X%4 on Windows.) The number 4 could be different numbers.

The interface addresses seem to be stored with these pseudo-zone IDs at
a low level, because they appear that way when they come from libdnet.
This is what "nmap --iflist" shows:

lo0  (lo0)   fe80:1::1/64                   loopback    up   16384
en0  (en0)   fe80:4::xxxx:xxxx:xxxx:xxxx/64 ethernet    up   1500  XX:XX:XX:XX:XX:XX

The OS X network tools seem to hide this. This is what "ifconfig" and
"netstat -rn -f inet6" show:

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
en0: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
        inet6 fe80::xxxx:xxxx:xxxx:xxxx%en0 prefixlen 64 scopeid 0x4

fe80::1%lo0                             link#1                          UHLI            lo0
fe80::xxxx:xxxx:xxxx:xxxx%en0           XX:XX:XX:XX:XX:XX               UHLI            lo0

(Not the "scopeid 0x4".) Also, if you use one of these addresses, it
magically transforms into one without the pseudo-ID (getaddrinfo does
this):

$ ping6 fe80:4::1234
PING6(56=40+8+8 bytes) fe80::xxxx:xxxx:xxxx:xxxx%en0 --> fe80::1234%en0
$ ping6 fe80:1::1234
PING6(56=40+8+8 bytes) fe80::1%lo0 --> fe80::1234%lo0

This translation is messing up our netmask comparisons for the purpose
of routing. If you use a normal link-local address starting with fe80:0,
then it doesn't compare equal with the fe80:4/64 interface address. If
you try to use the 4, then getaddrinfo turns it into fe80:0 anyway, and
the comparison still fails.

So for this reason I added a canonicalize_address function, which calls
getnameinfo on an address, then calls getaddrinfo on the returned
string, to mangle an address the same way the OS would do it. One would
hope this is a no-op in cases other than the one I have described.

Now "nmap --iflist" shows:
lo0  (lo0)   fe80::1/64                   loopback    up   16384
en0  (en0)   fe80::xxxx:xxxx:xxxx:xxxx/64 ethernet    up   1500  XX:XX:XX:XX:XX:XX
2011-09-18 23:49:34 +00:00
david
1887aef067 Allow setting certain extension headers as ancillary data in send_ipv6_ip. 2011-09-18 23:46:54 +00:00
david
66cf4fbe4a Define __APPLE_USE_RFC_3542.
Since OS X 10.7, we must declare whether we want the IPv6 sockets API to
work like RFC 2292 or RFC 3542. As far as I know, we are compatible with
both, so just pick the more recent one, which Apple says will become the
default in the future.
2011-09-18 05:11:25 +00:00
david
a13313ad2f Don't double-count RTA_LENGTH in netlink messages.
For each rtattr we add to the netlink message, we were adding
RTA_LENGTH(rtattr->rta_len) to the length of the netlink message. But
rtattr->rta_len was already calculated as RTA_LENGTH of something, and
doing RTA_LENGTH twice made the length 4 bytes longer than it should be.
This caused a log in dmesg:
	netlink: 4 bytes leftover after parsing attributes.
or
	netlink: 8 bytes leftover after parsing attributes.
if there was an IPv6 scope ID (because that causes two rtattrs instead
of one).

The new code is consistent with the rtnetlink(3) man page, which does
	rta->rta_len = sizeof(unsigned int);
	req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + RTA_LENGTH(sizeof(unsigned int));
We do the equivalent
	rta->rta_len = sizeof(unsigned int);
	req.n.nlmsg_len = NLMSG_ALIGN(req.n.nlmsg_len) + rta->rta_len;
2011-09-03 17:22:07 +00:00
david
1ef0db4b33 Define CMSG_ALIGN, CMSG_SPACE, and CMSG_LEN for old Solaris.
This was reported by Dagobert Michelsen and comes from
http://wiki.opencsw.org/porting-faq#toc10.
2011-09-03 01:51:35 +00:00
david
77204b9d43 Add an ifindex member to interface_info.
This is a copy of intf_index from libdnet.
2011-08-30 23:55:08 +00:00
david
31be04c93c Factor out a function to get an interface name from an index. 2011-08-30 23:55:05 +00:00
david
44e5b39fa2 Don't fatal when failing to find an interface by index. 2011-08-30 19:19:34 +00:00
david
43422f9344 Show a hint about an IPv6 zone ID suffix when get_srcaddr fails. 2011-08-30 18:32:35 +00:00
david
d1a518e08d Don't fatal when get_srcaddr can't connect the socket.
Let it be handled by a higher layer.
2011-08-30 18:32:34 +00:00
david
d759b485ea Honor sin6_scope_id in route_dst_generic.
This is set nonzero when there is a scope identifier at the end of
an IPv6 address, like fe80::a8bb:ccff:fedd:eeff%eth0 or
fe80::a8bb:ccff:fedd:eeff%1 on Windows. When this happens, we look up
the interface by index and then act as if it was the interface given by
-e. (But -e always has precedence over this.)
2011-08-30 17:01:51 +00:00
david
c5afa5b57b Temporarily revert r26242.
if_indextoname doesn't work the same way on Windows.
2011-08-30 14:33:20 +00:00
david
053154e5c3 Honor sin6_scope_id in route_dst_generic.
This is set nonzero when there is a scope identifier at the end of
an IPv6 address, like fe80::a8bb:ccff:fedd:eeff%eth0. When this
happens, we look up the interface by index and then act as if it was the
interface given by -e. (But -e always has precedence over this.)
2011-08-30 04:18:58 +00:00
david
d7302d7608 Use if_indextoname instead of our own intf_name function. 2011-08-30 04:18:57 +00:00
david
96a785e67d Honor sin6_scope_id in route_dst_netlink.
This is set nonzero when there is a scope identifier at the end of an
IPv6 address, like fe80::a8bb:ccff:fedd:eeff%eth0. When this happens, we
add an rtattr with type RTA_OIF to request a particular outgoing
interface.

In my tests, this does the right thing when the address is in fact the
assigned address of the interface; the interface becomes lo instead of
the physical interface name.
2011-08-30 04:18:56 +00:00
djalal
fc79deba75 Made getInterfaceByName() return IPv6 interface information. 2011-08-10 22:56:34 +00:00
weilin
1dcf652410 Added ND ping for local IPv6 nets, merging from /nmap-exp/weilin/nmap-nd. 2011-07-19 02:31:54 +00:00
david
f5fe8fb6e9 Use the proper length in get_srcaddr, not sizeof(sockaddr_in6).
This was a bug in r24413. The size needs to vary with the address family
on some platforms including OS X. This was noticed by Chris Clements.
2011-06-28 00:35:01 +00:00
david
fd259a2422 Use getsockname to get source addresses.
This was previously gotten by setting the source address to be the same
of the interface address of the matching route. However this can be
wrong; when making a normal socket connection the source address is
chosen differently. We create a SOCK_DGRAM socket, connect it, and read
the local address with getsockname.
2011-06-27 18:05:39 +00:00
shinnok
e06012af5a Type conversion safety fixes that remove compiler warnings too. 2011-06-23 20:48:06 +00:00
shinnok
68bdff3e54 Minor cosmetic fix. 2011-06-23 11:14:42 +00:00
david
e748e46d9e Add ipv6_get_data_any and ip_get_data_any.
These version allow returning an extension header or other
non–upper-layer protocol if it is the final header before the end of the
packet. This is used to parse the broken packets sent as part of
protocol scan.
2011-06-17 05:47:33 +00:00