pax_global_header00006660000000000000000000000064135634007120014513gustar00rootroot0000000000000052 comment=4efc1a6915bf6042467526f4ff6ffb128000fd92 nbtscan-1.6/000077500000000000000000000000001356340071200130115ustar00rootroot00000000000000nbtscan-1.6/.github/000077500000000000000000000000001356340071200143515ustar00rootroot00000000000000nbtscan-1.6/.github/workflows/000077500000000000000000000000001356340071200164065ustar00rootroot00000000000000nbtscan-1.6/.github/workflows/ccpp.yml000066400000000000000000000004431356340071200200570ustar00rootroot00000000000000name: C/C++ CI on: [push] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - name: autogen run: ./autogen.sh - name: configure run: ./configure - name: make run: make - name: make distclean run: make distclean nbtscan-1.6/AUTHORS000066400000000000000000000003261356340071200140620ustar00rootroot00000000000000Alla Bezroutchko , the original author. Joao Eriberto Mota Filho , the current project manager in GitHub (since 2019). Several contributors (see the ChangeLog file). nbtscan-1.6/CONTRIBUTING.md000066400000000000000000000017361356340071200152510ustar00rootroot00000000000000## HOW TO CONTRIBUTE TO NBTSCAN DEVELOPMENT NBTscan is available at https://github.com/resurrecting-open-source-projects/nbtscan If you are interested in contribute to NBTscan development, please, follow these steps: 1. Send a patch that fix an issue or that implement a new feature. Alternatively, you can do a 'pull request'[1] in GitHub. [1] https://help.github.com/articles/about-pull-requests 2. Ask for join to the NBTscan project in GitHub, if you want to work officially. Note that this second step is not compulsory. However, to accept you in project, is needed a minimum previous collaboration. To find issues and bugs to fix, you can check these addresses: - https://github.com/resurrecting-open-source-projects/nbtscan - https://bugs.debian.org/cgi-bin/pkgreport.cgi?dist=unstable;package=nbtscan - https://bugs.launchpad.net/ubuntu/+source/nbtscan/+bugs If you want to join, please make a contact. -- Eriberto, Thu, 14 Nov 2019 00:44:53 -0300. nbtscan-1.6/COPYING000066400000000000000000000432541356340071200140540ustar00rootroot00000000000000 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. nbtscan-1.6/ChangeLog000066400000000000000000000077431356340071200145760ustar00rootroot00000000000000Version 1.6 - November 2019 [ Joao Eriberto Mota Filho ] * Autotools files: - Added a distclean-local target in Makefile.am. - Added the autogen.sh file. - Added CFLAGS, CPPFLAGS and LDFLAGS to allow GCC hardening. - Changed .in files to .ac/.am. - Improved the configure.ac and Makefile.am files. - Moved some build lines from Makefile.am to src/Makefile.am. - Removed all autogenerated files. * Created AUTHORS and CONTRIBUTING.md. * Rewritten README file. * Moved the source code to src/. * Added headers and rights. * Using an updated COPYING file. * Using txt2man to produce a manpage. [ Jochen Friedrich ] * Several fix in source code to avoid warnings. * Using ":" in MAC addresses instead of "-". [ Johan Eidenvall ] * Fixed missing format specifiers that do debug output looks odd. [ Walter "Wallie" Jakob Doekes ] * Fixed invalid pointer when scanning some ranges with -v. Version 1.5.1 - June 2003 - Fixed segmentation fault when using -f option (noticed by Brian Lovrin) - Fixed printing ugliness (noticed by Darren Critchley) - Changed version number :) (1.5 said that it is 1.0.3 - now it proudly says 1.5.1) Version 1.5 - May 2002 - Fixed a bug in displaying of 15-character NetBIOS names (15th character wasn't displayed). Bug reported by Tom Kustner (Tom.Kustner@mortgage.wellsFargo.COM), Kenny Breck (KCBreck@NetZero.net) and Richard IJzermans (richard.ijzermans@lgphilips-displays.com) - Fixed a bug in interpreting netmask /32 and /0. Patch provided by Thomas Poindessous (thomas@poindessous.com) for Debian Linux - List of hosts to scan can now be read from stdin as well as from file. Suggested by Kevin Kadow (kadokev@msg.net) - Fixed a bug in timing. (nbtscan waited for two seconds after scanning not doing anything). Reported by Ceri Hopkins (ceri@sandc.demon.co.uk) - Nbtscan now works on Darwin. Patches provided by Mohammad A. Haque (mhaque@haque.net) - timeout option -t is now in milliseconds, not seconds - Fixed some Solaris portability problems. Patches provided by Petter Reinholdtsen (pere@hungry.com) Version 1.0.3 - February 2002 - NBTscan now returns meaningful exit code (patch by James Troup for Debian Linux) - Added /etc/hosts and lmhosts format output (suggested by Anahuac de Paula Gil and Sigmund Baginov) - configure script now honours --prefix argument (patch by Petter Reinholdtsen) - Error messages now include IP address that caused error - NBTscan accepts a file with a list of IP addresses to scan (suggested by Omas Jakobsson) - Service number is printed for unknown NetBIOS services in -h mode (suggested by Dan Wright) - Fixed some compile-time warnings on Linux - Corrected some typos Version 1.0.2 - March 30, 2000 - Added retransmits (-m option) (Several people asked) - Added output bandwidth throttling (-b option) (Suggested by Jason Garman ) - Rewrote sending queries and receiving answers part for more reliable scanning of large blocks of addresses. (Suggested by Jason Garman ) - Added script-friendly output option (-s) (Suggested by Patrick Heim ) - Added printing of human-readable NetBIOS service names (-h) (Suggested by Patrick Heim ) - Added -q command line option that suppresses printing banners and error messages. (Suggested by Sam Bayne ) - Rewrote parse_response completely. This allows for better parsing of Samba servers' responses. (Bug reported by Sam Bayne ) - Added -d command line option which makes whole packets get printed - Various cosmetic improvements including fixing some spelling errors Version 1.0.1 - May 5, 1999 - Fixed incorrect parsing of MAC address in parse_response() which made last byte of MAC addresses appear as 00. Bug pointed by Joseph Moon. - Changed message saying "Warning: -r option not supported under NT." to more accurate saying: "Warning: -r option not supported under Windows." - Corrected a typo in README. nbtscan-1.6/Makefile.am000066400000000000000000000020501356340071200150420ustar00rootroot00000000000000# Copyright 2019 Joao Eriberto Mota Filho # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. SUBDIRS = src man_MANS= man/nbtscan.1 EXTRA_DIST= man/nbtscan.1 distclean-local: -rm -rf autom4te.cache -rm aclocal.m4 compile config.log config.status \ configure depcomp INSTALL install-sh Makefile Makefile.in \ missing src/Makefile.in src/*.o src/nbtscan nbtscan-1.6/NEWS000066400000000000000000000000001356340071200134760ustar00rootroot00000000000000nbtscan-1.6/README000077700000000000000000000000001356340071200151432README.mdustar00rootroot00000000000000nbtscan-1.6/README.md000066400000000000000000000030271356340071200142720ustar00rootroot00000000000000# NBTscan #### nbtscan - scan networks for NetBIOS name information ## Help this project ## nbtscan needs your help. **If you are a programmer** and if you wants to help a nice project, this is your opportunity. nbtscan was imported from some tarballs (the original homepage[1] and developers are inactive). After this, all patches found in Debian project and other places for this program were applied. All initial work was registered in ChangeLog file (version 1.6 and later releases). nbtscan is being packaged in Debian[2] Project. If you are interested to help nbtscan, read the [CONTRIBUTING.md](CONTRIBUTING.md) file. [1]: http://www.inetcat.org/software/nbtscan.html [2]: https://tracker.debian.org/pkg/nbtscan ## What is NBTscan? ## NBTscan is a program for scanning IP networks for NetBIOS name information. It sends NetBIOS status query to each address in supplied range and lists received information in human readable form. For each responded host it lists IP address, NetBIOS computer name, logged-in user name and MAC address (such as Ethernet). ## Build and Install ## To build and install, run the following commands: $ ./autogen.sh $ ./configure $ make # make install To return to original source code you can use '$ make distclean' command. On Debian systems you can use '# apt install nbtscan'. ## Author ## NBTscan was originally developed by Alla Bezroutchko under GPL-2+ license. Currently, the source code and newer versions are available at https://github.com/resurrecting-open-source-projects/nbtscan nbtscan-1.6/autogen.sh000077500000000000000000000044511356340071200150160ustar00rootroot00000000000000#!/bin/sh # autogen.sh with clean option, v0.1-nbtscan # Copyright 2019 Joao Eriberto Mota Filho # # This file is under BSD-3-Clause license. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the authors nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # Use clean option if [ "$1" = "clean" -a ! -e Makefile ] then echo "Vanishing the code" rm -rf aclocal.m4 autom4te.cache/ compile config.* configure depcomp \ INSTALL install-sh Makefile.in missing src/Makefile.in exit 0 fi # Do not use clean option if [ "$1" = "clean" -a -e Makefile ] then echo "I can not clean. Use '$ make distclean'." exit 0 fi # Do autoreconf autoreconf -fi \ && { echo " "; \ echo "Done. You can use the 'clean' option to vanish the source code."; \ echo "Example of use: $ ./autogen.sh clean"; \ echo " "; \ echo "Now run ./configure, make, and make install."; \ } \ || { echo "We have a problem..."; exit 1; } nbtscan-1.6/configure.ac000066400000000000000000000041421356340071200153000ustar00rootroot00000000000000# Copyright 1999-2003 Alla Bezroutchko # Copyright 2019 Joao Eriberto Mota Filho # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.61) AC_INIT([nbtscan], [1.6], [https://github.com/resurrecting-open-source-projects/nbtscan/issues]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/statusq.c]) dnl Checks for programs. AC_PROG_CC AC_PROG_INSTALL dnl Checks for libraries. AC_CHECK_LIB(xnet, socket) AC_CHECK_LIB(socket, socket) AC_CHECK_LIB(resolv, inet_aton) dnl Checks for header files. AC_HEADER_STDC AC_CHECK_HEADERS(sys/time.h) AC_CHECK_HEADERS(stdint.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_CHECK_TYPE(uint8_t, [AC_DEFINE(my_uint8_t, uint8_t)], [AC_CHECK_TYPE(u_int8_t, [AC_DEFINE(my_uint8_t, u_int8_t)])]) AC_CHECK_TYPE(uint16_t, [AC_DEFINE(my_uint16_t, uint16_t)], [AC_CHECK_TYPE(u_int16_t, [AC_DEFINE(my_uint16_t, u_int16_t)])]) AC_CHECK_TYPE(uint32_t, [AC_DEFINE(my_uint32_t, uint32_t)], [AC_CHECK_TYPE(u_int32_t, [AC_DEFINE(my_uint32_t, u_int32_t)])]) AC_C_CONST AC_HEADER_TIME dnl Checks for library functions. AC_CHECK_FUNCS(snprintf inet_aton socket) #AC_CANONICAL_TARGET #if test "$target_os" = cygwin; then #AC_DEFINE(WINDOWS) #BINDIR=c: #TARGET=nbtscan.exe #else #AC_DEFINE(UNIX) #BINDIR=$prefix/bin #TARGET=nbtscan #fi #AC_SUBST(TARGET) #AC_SUBST(BINDIR) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT nbtscan-1.6/doc/000077500000000000000000000000001356340071200135565ustar00rootroot00000000000000nbtscan-1.6/doc/UPDATE-CHECK000066400000000000000000000005271356340071200153020ustar00rootroot00000000000000When updating, change the following files (if needed): - Update rights - Update ChangeLog - Check for spelling errors in ChangeLog, manpage and README. - man/create-man.sh (DATE, version) - Generate a new manpage. - Check final manpage with man command. - configure.ac (VERSION) - src/nbtscan.c (version) - Update README - Test in Debian Sid nbtscan-1.6/man/000077500000000000000000000000001356340071200135645ustar00rootroot00000000000000nbtscan-1.6/man/create-man.sh000077500000000000000000000007341356340071200161430ustar00rootroot00000000000000#!/bin/bash # Copyright 2015-2018 Joao Eriberto Mota Filho # Create a manpage using txt2man command. # # This script can be used under BSD-3-Clause license. T2M_DATE="14 Nov 2019" T2M_NAME=nbtscan T2M_VERSION=1.6 T2M_LEVEL=1 T2M_DESC="scan networks searching for NetBIOS information" # Don't change the following line txt2man -d "$T2M_DATE" -t $T2M_NAME -r $T2M_NAME-$T2M_VERSION -s $T2M_LEVEL -v "$T2M_DESC" $T2M_NAME.txt > $T2M_NAME.$T2M_LEVEL nbtscan-1.6/man/nbtscan.1000066400000000000000000000214171356340071200153030ustar00rootroot00000000000000.\" Text automatically generated by txt2man .TH nbtscan 1 "14 Nov 2019" "nbtscan-1.6" "scan networks searching for NetBIOS information" .SH NAME \fBnbtscan \fP- scan networks for NetBIOS name information \fB .SH SYNOPSIS .nf .fam C \fBnbtscan\fP [\fB-v\fP] [\fB-d\fP] [\fB-e\fP] [\fB-l\fP] [\fB-t\fP \fItimeout\fP] [\fB-b\fP \fIbandwidth\fP] [\fB-r\fP] [\fB-q\fP] [\fB-s\fP \fIseparator\fP] [\fB-h\fP] [\fB-m\fP \fIretransmits\fP] [\fB-f\fP \fIfilename\fP | \fItarget\fP] .fam T .fi .fam T .fi .SH DESCRIPTION NBTscan is a program for scanning IP networks for NetBIOS name information. It sends NetBIOS status query to each address in supplied range and lists received information in human readable form. For each responded host it lists IP address, NetBIOS computer name, logged-in user name and MAC address (such as Ethernet). .PP NBTscan produces a report like that: .PP .nf .fam C IP address NetBIOS Name Server User MAC address ------------------------------------------------------------------------------ 192.168.1.2 MYCOMPUTER JDOE 00-a0-c9-12-34-56 192.168.1.5 WIN98COMP RROE 00-a0-c9-78-90-00 192.168.1.123 DPTSERVER ADMINISTRATOR 08-00-09-12-34-56 .fam T .fi First column lists IP address of responded host. Second column is computer name. Third column indicates if this computer shares or is able to share files or printers. For NT machine it means that Server Service is running on this computer. For Windows 95 it means that "I want to be able to give others access to my files" or "I want to be able to allow others to print on my \fBprinter\fP(s)" checkbox is ticked (in Control Panel/Network/File and Print Sharing). Most often it means that this computer shares files. Third column shows user name. If no one is logged on from this computer it is same as computer name. Last column shows adapter MAC address. .PP If run with \fB-v\fP switch NBTscan lists whole NetBIOS name table for each responded address. The output looks like that: .PP .nf .fam C NetBIOS Name Table for Host 192.168.1.123: Name Service Type ---------------------------------------- DPTSERVER <00> UNIQUE DPTSERVER <20> UNIQUE DEPARTMENT <00> GROUP DEPARTMENT <1c> GROUP DEPARTMENT <1b> UNIQUE DEPARTMENT <1e> GROUP DPTSERVER <03> UNIQUE DEPARTMENT <1d> UNIQUE ??__MSBROWSE__? <01> GROUP INet~Services <1c> GROUP IS~DPTSERVER <00> UNIQUE DPTSERVER <01> UNIQUE Adapter address: 00-a0-c9-12-34-56 ---------------------------------------- .fam T .fi .SH OPTIONS A summary of options is included below. .TP .B \fB-v\fP Verbose output. Print all names received from each host. .TP .B \fB-d\fP Dump packets. Print whole packet contents. Cannot be used with \fB-v\fP, \fB-s\fP or \fB-h\fP options. .TP .B \fB-e\fP Format output in /etc/hosts format. .TP .B \fB-l\fP Format output in lmhosts format. .TP .B \fB-t\fP <\fItimeout\fP> Wait \fItimeout\fP seconds for response. Default 1. .TP .B \fB-b\fP <\fIbandwidth\fP> Output throttling. Slow down output so that it uses no more that \fIbandwidth\fP bps. Useful on slow links, so that outgoing queries don't get dropped. .TP .B \fB-r\fP Use local port 137 for scans. Win95 boxes respond to this only. You need to be root to use this option. .TP .B \fB-q\fP Suppress banners and error messages. .TP .B \fB-s\fP <\fIseparator\fP> Script-friendly output. Don't print column and record headers, separate fields with \fIseparator\fP. .TP .B \fB-h\fP Print human-readable names for services. Can only be used with \fB-v\fP option. .TP .B \fB-m\fP <\fIretransmits\fP> Number of \fIretransmits\fP. Default 0. .TP .B \fB-f\fP <\fIfilename\fP> Take IP addresses to scan from file "\fIfilename\fP" .TP .B \fItarget\fP NBTscan is a command-line tool. You have to supply at least one argument, the address range, in one of three forms: .RS .TP .B xxx.xxx.xxx.xxx Single IP in dotted-decimal notation. Example: 192.168.1.1 .TP .B xxx.xxx.xxx.xxx/xx Net address and subnet mask. Example: 192.168.1.0/24 .TP .B xxx.xxx.xxx.xxx-xxx Address range. Example: 192.168.1.1-127. This will scan all addresses from 192.168.1.1 to 192.168.1.127 .SH EXAMPLES Scans the whole C-class network: .PP .nf .fam C nbtscan -r 192.168.1.0/24 .fam T .fi Scans a range from 192.168.1.25 to 192.168.1.137: .PP .nf .fam C nbtscan 192.168.1.25-137 .fam T .fi Scans C-class network. Prints results in script-friendly format using colon as field \fIseparator\fP: .PP .nf .fam C nbtscan -v -s : 192.168.1.0/24 .fam T .fi The last command produces output like that: .PP .nf .fam C 192.168.0.1:NT_SERVER:00U 192.168.0.1:MY_DOMAIN:00G 192.168.0.1:ADMINISTRATOR:03U 192.168.0.2:OTHER_BOX:00U \.\.\. .fam T .fi Scans IP addresses specified in file iplist: .PP .nf .fam C nbtscan -f iplist .fam T .fi .SH NETBIOS SUFFIXES NetBIOS Suffix, aka NetBIOS End Character (endchar), indicates service type for the registered name. The most known codes are listed below. (U = Unique Name, G = Group Name) .PP .nf .fam C Name Number(h) Type Usage -------------------------------------------------------------------------- 00 U Workstation Service 01 U Messenger Service <\\--__MSBROWSE__> 01 G Master Browser 03 U Messenger Service 06 U RAS Server Service 1F U NetDDE Service 20 U File Server Service 21 U RAS Client Service 22 U Exchange Interchange(MSMail Connector) 23 U Exchange Store 24 U Exchange Directory 30 U Modem Sharing Server Service 31 U Modem Sharing Client Service 43 U SMS Clients Remote Control 44 U SMS Administrators Remote Control Tool 45 U SMS Clients Remote Chat 46 U SMS Clients Remote Transfer 87 U Microsoft Exchange MTA 6A U Microsoft Exchange IMC BE U Network Monitor Agent BF U Network Monitor Application 03 U Messenger Service 00 G Domain Name 1B U Domain Master Browser 1C G Domain Controllers 1D U Master Browser 1E G Browser Service Elections 1C G IIS 00 U IIS .fam T .fi .SH FAQ .IP 1. 4 NBTscan lists my Windows boxes just fine but does not list my Unixes or routers. Why? .PP R: That is the way it is supposed to work. NBTscan uses NetBIOS for scanning and NetBIOS is only implemented by Windows (and some software on Unix such as Samba). .IP 2. 4 Why do I get "Connection reset by peer" errors on Windows 2000? .PP R: NBTscan uses port 137 UDP for sending queries. If the port is closed on destination host destination will reply with ICMP "Port unreachable" message. Most operating system will ignore this message. Windows 2000 reports it to the application as "Connection reset by peer" error. Just ignore it. .IP 3. 4 Why NBTscan doesn't scan for shares? Are you going to add share scanning to NBTscan? .PP R: No. NBTscan uses UDP for what it does. That makes it very fast. Share scanning requires TCP. For one thing, it will make \fBnbtscan\fP more slow. Also adding share scanning means adding a lot of new code to \fBnbtscan\fP. There is a lot of good share scanners around, so there is no reason to duplicate that work. .IP 4. 4 Why do I get 00-00-00-00-00-00 instead of MAC address when I scan a Samba box? .PP R: Because that's what Samba send in response to the query. Nbtscan just prints out what it gets. .SH AUTHOR NBTscan was created by Alla Bezroutchko . Currently is maintained by some volunteers at https://github.com/resurrecting-open-source-projects/\fBnbtscan\fP .PP This manual page was written for the first time by Ryszard Lach and rewritten, from scratch, by Joao Eriberto Mota Filho for the Debian GNU/Linux system (but may be used by others). nbtscan-1.6/man/nbtscan.txt000066400000000000000000000203051356340071200157550ustar00rootroot00000000000000NAME nbtscan - scan networks for NetBIOS name information SYNOPSIS nbtscan [-v] [-d] [-e] [-l] [-t timeout] [-b bandwidth] [-r] [-q] [-s separator] [-h] [-m retransmits] [-f filename | target] DESCRIPTION NBTscan is a program for scanning IP networks for NetBIOS name information. It sends NetBIOS status query to each address in supplied range and lists received information in human readable form. For each responded host it lists IP address, NetBIOS computer name, logged-in user name and MAC address (such as Ethernet). NBTscan produces a report like that: IP address NetBIOS Name Server User MAC address ------------------------------------------------------------------------------ 192.168.1.2 MYCOMPUTER JDOE 00-a0-c9-12-34-56 192.168.1.5 WIN98COMP RROE 00-a0-c9-78-90-00 192.168.1.123 DPTSERVER ADMINISTRATOR 08-00-09-12-34-56 First column lists IP address of responded host. Second column is computer name. Third column indicates if this computer shares or is able to share files or printers. For NT machine it means that Server Service is running on this computer. For Windows 95 it means that "I want to be able to give others access to my files" or "I want to be able to allow others to print on my printer(s)" checkbox is ticked (in Control Panel/Network/File and Print Sharing). Most often it means that this computer shares files. Third column shows user name. If no one is logged on from this computer it is same as computer name. Last column shows adapter MAC address. If run with -v switch NBTscan lists whole NetBIOS name table for each responded address. The output looks like that: NetBIOS Name Table for Host 192.168.1.123: Name Service Type ---------------------------------------- DPTSERVER <00> UNIQUE DPTSERVER <20> UNIQUE DEPARTMENT <00> GROUP DEPARTMENT <1c> GROUP DEPARTMENT <1b> UNIQUE DEPARTMENT <1e> GROUP DPTSERVER <03> UNIQUE DEPARTMENT <1d> UNIQUE ??__MSBROWSE__? <01> GROUP INet~Services <1c> GROUP IS~DPTSERVER <00> UNIQUE DPTSERVER <01> UNIQUE Adapter address: 00-a0-c9-12-34-56 ---------------------------------------- OPTIONS A summary of options is included below. -v Verbose output. Print all names received from each host. -d Dump packets. Print whole packet contents. Cannot be used with -v, -s or -h options. -e Format output in /etc/hosts format. -l Format output in lmhosts format. -t Wait timeout seconds for response. Default 1. -b Output throttling. Slow down output so that it uses no more that bandwidth bps. Useful on slow links, so that outgoing queries don't get dropped. -r Use local port 137 for scans. Win95 boxes respond to this only. You need to be root to use this option. -q Suppress banners and error messages. -s Script-friendly output. Don't print column and record headers, separate fields with separator. -h Print human-readable names for services. Can only be used with -v option. -m Number of retransmits. Default 0. -f Take IP addresses to scan from file "filename" target NBTscan is a command-line tool. You have to supply at least one argument, the address range, in one of three forms: xxx.xxx.xxx.xxx Single IP in dotted-decimal notation. Example: 192.168.1.1 xxx.xxx.xxx.xxx/xx Net address and subnet mask. Example: 192.168.1.0/24 xxx.xxx.xxx.xxx-xxx Address range. Example: 192.168.1.1-127. This will scan all addresses from 192.168.1.1 to 192.168.1.127 EXAMPLES Scans the whole C-class network: nbtscan -r 192.168.1.0/24 Scans a range from 192.168.1.25 to 192.168.1.137: nbtscan 192.168.1.25-137 Scans C-class network. Prints results in script-friendly format using colon as field separator: nbtscan -v -s : 192.168.1.0/24 The last command produces output like that: 192.168.0.1:NT_SERVER:00U 192.168.0.1:MY_DOMAIN:00G 192.168.0.1:ADMINISTRATOR:03U 192.168.0.2:OTHER_BOX:00U ... Scans IP addresses specified in file iplist: nbtscan -f iplist NETBIOS SUFFIXES NetBIOS Suffix, aka NetBIOS End Character (endchar), indicates service type for the registered name. The most known codes are listed below. (U = Unique Name, G = Group Name) Name Number(h) Type Usage -------------------------------------------------------------------------- 00 U Workstation Service 01 U Messenger Service <\\--__MSBROWSE__> 01 G Master Browser 03 U Messenger Service 06 U RAS Server Service 1F U NetDDE Service 20 U File Server Service 21 U RAS Client Service 22 U Exchange Interchange(MSMail Connector) 23 U Exchange Store 24 U Exchange Directory 30 U Modem Sharing Server Service 31 U Modem Sharing Client Service 43 U SMS Clients Remote Control 44 U SMS Administrators Remote Control Tool 45 U SMS Clients Remote Chat 46 U SMS Clients Remote Transfer 87 U Microsoft Exchange MTA 6A U Microsoft Exchange IMC BE U Network Monitor Agent BF U Network Monitor Application 03 U Messenger Service 00 G Domain Name 1B U Domain Master Browser 1C G Domain Controllers 1D U Master Browser 1E G Browser Service Elections 1C G IIS 00 U IIS FAQ 1. NBTscan lists my Windows boxes just fine but does not list my Unixes or routers. Why? R: That is the way it is supposed to work. NBTscan uses NetBIOS for scanning and NetBIOS is only implemented by Windows (and some software on Unix such as Samba). 2. Why do I get "Connection reset by peer" errors on Windows 2000? R: NBTscan uses port 137 UDP for sending queries. If the port is closed on destination host destination will reply with ICMP "Port unreachable" message. Most operating system will ignore this message. Windows 2000 reports it to the application as "Connection reset by peer" error. Just ignore it. 3. Why NBTscan doesn't scan for shares? Are you going to add share scanning to NBTscan? R: No. NBTscan uses UDP for what it does. That makes it very fast. Share scanning requires TCP. For one thing, it will make nbtscan more slow. Also adding share scanning means adding a lot of new code to nbtscan. There is a lot of good share scanners around, so there is no reason to duplicate that work. 4. Why do I get 00-00-00-00-00-00 instead of MAC address when I scan a Samba box? R: Because that's what Samba send in response to the query. Nbtscan just prints out what it gets. AUTHOR NBTscan was created by Alla Bezroutchko . Currently is maintained by some volunteers at https://github.com/resurrecting-open-source-projects/nbtscan This manual page was written for the first time by Ryszard Lach and rewritten, from scratch, by Joao Eriberto Mota Filho for the Debian GNU/Linux system (but may be used by others). nbtscan-1.6/src/000077500000000000000000000000001356340071200136005ustar00rootroot00000000000000nbtscan-1.6/src/Makefile.am000066400000000000000000000024471356340071200156430ustar00rootroot00000000000000# Copyright 1999-2003 Alla Bezroutchko # Copyright 2018-2019 Joao Eriberto Mota Filho # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. bin_PROGRAMS = nbtscan OBJECTS=nbtscan.o statusq.o range.o list.o nbtscan$(EXEEXT): $(OBJECTS) $(CC) $(CFLAGS) -o nbtscan $(OBJECTS) $(LIBS) $(LDFLAGS) nbtscan.o: nbtscan.c statusq.h range.h list.h $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -c nbtscan.c statusq.o: statusq.c statusq.h $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -c statusq.c range.o: range.c range.h $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -c range.c list.o: list.c list.h $(CC) $(CFLAGS) $(CPPFLAGS) $(DEFS) -c list.c nbtscan-1.6/src/errors.h000066400000000000000000000017031356340071200152660ustar00rootroot00000000000000/* # Copyright 1999-2003 Alla Bezroutchko # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #if !defined ERRORS_H #define ERRORS_H #define err_die(error, quiet) if(!quiet) {perror(error); exit(1);}; #define err_print(error, quiet) if(!quiet) perror(error); #endif /* ERRORS_H */ nbtscan-1.6/src/list.c000066400000000000000000000065241356340071200147260ustar00rootroot00000000000000/* # Copyright 1999-2003 Alla Bezroutchko # Copyright 2004 Jochen Friedrich # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include "list.h" #include #include "errors.h" extern int quiet; struct list* new_list() { struct list* lst; if( ( lst = (struct list*) malloc(sizeof(struct list)) )==NULL ) err_die("Malloc failed", quiet); lst->head = NULL; return lst; }; struct list_item* new_list_item(unsigned long content) { struct list_item* lst_item; if( (lst_item = (struct list_item*) malloc(sizeof(struct list_item)) )==NULL ) err_die("Malloc failed", quiet); lst_item->next = NULL; lst_item->prev = NULL; lst_item->content = content; return lst_item; }; void delete_list(struct list* list) { struct list_item* pointer; pointer = list->head; if (pointer) { while(pointer->next) pointer = pointer->next; /* Find last list element */ /* Go back from tail to head deleteing list items on the way */ while(pointer->prev) { pointer = pointer->prev; free(pointer->next); }; free(pointer); } free(list); }; int compare(struct list_item* item1, struct list_item* item2) { if(item2==NULL) return ERROR; if(item1==NULL) return 1; if(item1->content == item2->content) return 0; if(item1->content > item2->content) return 1; return -1; }; int insert(struct list* lst, unsigned long content) { struct list_item *temp_item, *item; int cmp; item = new_list_item(content); cmp = compare(lst->head, item); if(lst->head==NULL) { lst->head=item; return 1; } else if (cmp==1) { item->next=lst->head; lst->head = item; item->prev = NULL; return 1; } else if (cmp==0) { free(item); return 0; } else if (cmp==-1) { temp_item = lst->head; while(compare(temp_item->next, item)==-1) { temp_item = temp_item->next; } /* temp_item points to last list element less then item */ /* we shall insert item after temp_item */ if(compare(temp_item->next, item)==0) { free(item); return 0; } else if(compare(temp_item->next, item)==ERROR) { free(item); return ERROR; } else if(compare(temp_item->next, item)==1) { item->next=temp_item->next; item->prev=temp_item; if(temp_item->next) temp_item->next->prev = item; temp_item->next = item; return 1; }; } else if (compare(lst->head, item)==ERROR) { free(item); return ERROR; }; return 0; }; int in_list(struct list* lst, unsigned long content) { struct list_item *temp_item, *item; item = new_list_item(content); if(lst->head==NULL) return 0; temp_item=lst->head; while(compare(temp_item, item) < 0) temp_item = temp_item->next; if (compare(temp_item, item)==0) return 1; return 0; }; nbtscan-1.6/src/list.h000066400000000000000000000022261356340071200147260ustar00rootroot00000000000000/* # Copyright 1999-2003 Alla Bezroutchko # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #define ERROR 12345 struct list_item { struct list_item* next; struct list_item* prev; unsigned long content; }; struct list { struct list_item* head; }; struct list* new_list(); struct list_item* new_list_item(unsigned long content); void delete_list(struct list* list); int compare(struct list_item* item1, struct list_item* item2); int insert(struct list* lst, unsigned long content); nbtscan-1.6/src/nbtscan.c000066400000000000000000000546571356340071200154150ustar00rootroot00000000000000/* # Copyright 1999-2003 Alla Bezroutchko # Copyright 2004 Jochen Friedrich # Copyright 2008 Walter "Wallie" Jakob Doekes # Copyright 2015 Johan Eidenvall # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #if HAVE_STDINT_H #include #endif #include "statusq.h" #include "range.h" #include "list.h" #include "errors.h" #include "time.h" int quiet=0; char* getnbservicename(my_uint8_t service, int unique, char* name); struct nb_host_info* parse_response(char* buff, int buffsize); int in_list(struct list* lst, unsigned long content); void send_query(int sock, struct in_addr dest_addr, my_uint32_t rtt_base); void print_banner(void) { printf("\nNBTscan version 1.6.\n"); printf("This is a free software and it comes with absolutely no warranty.\n"); printf("You can use, distribute and modify it under terms of GNU GPL 2+.\n\n"); } void usage(void) { printf("Usage:\nnbtscan [-v] [-d] [-e] [-l] [-t timeout] [-b bandwidth] [-r] [-q] [-s separator] [-m retransmits] (-f filename)|() \n"); printf("\t-v\t\tverbose output. Print all names received\n"); printf("\t\t\tfrom each host\n"); printf("\t-d\t\tdump packets. Print whole packet contents.\n"); printf("\t-e\t\tFormat output in /etc/hosts format.\n"); printf("\t-l\t\tFormat output in lmhosts format.\n"); printf("\t\t\tCannot be used with -v, -s or -h options.\n"); printf("\t-t timeout\twait timeout milliseconds for response.\n"); printf("\t\t\tDefault 1000.\n"); printf("\t-b bandwidth\tOutput throttling. Slow down output\n"); printf("\t\t\tso that it uses no more that bandwidth bps.\n"); printf("\t\t\tUseful on slow links, so that ougoing queries\n"); printf("\t\t\tdon't get dropped.\n"); printf("\t-r\t\tuse local port 137 for scans. Win95 boxes\n"); printf("\t\t\trespond to this only.\n"); printf("\t\t\tYou need to be root to use this option on Unix.\n"); printf("\t-q\t\tSuppress banners and error messages,\n"); printf("\t-s separator\tScript-friendly output. Don't print\n"); printf("\t\t\tcolumn and record headers, separate fields with separator.\n"); printf("\t-h\t\tPrint human-readable names for services.\n"); printf("\t\t\tCan only be used with -v option.\n"); printf("\t-m retransmits\tNumber of retransmits. Default 0.\n"); printf("\t-f filename\tTake IP addresses to scan from file filename.\n"); printf("\t\t\t-f - makes nbtscan take IP addresses from stdin.\n"); printf("\t\twhat to scan. Can either be single IP\n"); printf("\t\t\tlike 192.168.1.1 or\n"); printf("\t\t\trange of addresses in one of two forms: \n"); printf("\t\t\txxx.xxx.xxx.xxx/xx or xxx.xxx.xxx.xxx-xxx.\n"); printf("Examples:\n"); printf("\tnbtscan -r 192.168.1.0/24\n"); printf("\t\tScans the whole C-class network.\n"); printf("\tnbtscan 192.168.1.25-137\n"); printf("\t\tScans a range from 192.168.1.25 to 192.168.1.137\n"); printf("\tnbtscan -v -s : 192.168.1.0/24\n"); printf("\t\tScans C-class network. Prints results in script-friendly\n"); printf("\t\tformat using colon as field separator.\n"); printf("\t\tProduces output like that:\n"); printf("\t\t192.168.0.1:NT_SERVER:00U\n"); printf("\t\t192.168.0.1:MY_DOMAIN:00G\n"); printf("\t\t192.168.0.1:ADMINISTRATOR:03U\n"); printf("\t\t192.168.0.2:OTHER_BOX:00U\n"); printf("\t\t...\n"); printf("\tnbtscan -f iplist\n"); printf("\t\tScans IP addresses specified in file iplist.\n"); exit(2); }; int set_range(char* range_str, struct ip_range* range_struct) { if(is_ip(range_str, range_struct)) return 1; if(is_range1(range_str, range_struct)) return 1; if(is_range2(range_str, range_struct)) return 1; return 0; }; void print_header(void) { printf("%-17s%-17s%-10s%-17s%-17s\n", "IP address", "NetBIOS Name", "Server", "User", "MAC address"); printf("------------------------------------------------------------------------------\n"); }; void d_print_hostinfo(struct in_addr addr, const struct nb_host_info* hostinfo) { int i; unsigned char service; /* 16th byte of NetBIOS name */ char name[16]; printf("\nPacket dump for Host %s:\n\n", inet_ntoa(addr)); if(hostinfo->is_broken) printf("Incomplete packet, %d bytes long.\n", hostinfo->is_broken); if(hostinfo->header) { printf("Transaction ID: 0x%04x (%1$d)\n", hostinfo->header->transaction_id); printf("Flags: 0x%04x (%1$d)\n", hostinfo->header->flags); printf("Question count: 0x%04x (%1$d)\n", hostinfo->header->question_count); printf("Answer count: 0x%04x (%1$d)\n", hostinfo->header->answer_count); printf("Name service count: 0x%04x (%1$d)\n", hostinfo->header->name_service_count); printf("Additional record count: 0x%04x (%1$d)\n", hostinfo->header->additional_record_count); printf("Question name: %s\n", hostinfo->header->question_name); printf("Question type: 0x%04x (%1$d)\n", hostinfo->header->question_type); printf("Question class: 0x%04x (%1$d)\n", hostinfo->header->question_class); printf("Time to live: 0x%08x (%1$d)\n", hostinfo->header->ttl); printf("Rdata length: 0x%04x (%1$d)\n", hostinfo->header->rdata_length); printf("Number of names: 0x%02x (%1$d)\n", hostinfo->header->number_of_names); }; if(hostinfo->names) { printf("Names received:\n"); for(i=0; i< hostinfo->header->number_of_names; i++) { service = hostinfo->names[i].ascii_name[15]; strncpy(name, hostinfo->names[i].ascii_name, 15); name[15]=0; printf("%-17s Service: 0x%02x Flags: 0x%04x\n", name, service, hostinfo->names[i].rr_flags); } }; if(hostinfo->footer) { printf("Adapter address: %02x:%02x:%02x:%02x:%02x:%02x\n", hostinfo->footer->adapter_address[0], hostinfo->footer->adapter_address[1], hostinfo->footer->adapter_address[2], hostinfo->footer->adapter_address[3], hostinfo->footer->adapter_address[4], hostinfo->footer->adapter_address[5]); printf("Version major: 0x%02x (%1$d)\n", hostinfo->footer->version_major); printf("Version minor: 0x%02x (%1$d)\n", hostinfo->footer->version_minor); printf("Duration: 0x%04x (%1$d)\n", hostinfo->footer->duration); printf("FRMRs Received: 0x%04x (%1$d)\n", hostinfo->footer->frmps_received); printf("FRMRs Transmitted: 0x%04x (%1$d)\n", hostinfo->footer->frmps_transmitted); printf("IFrame Receive errors: 0x%04x (%1$d)\n", hostinfo->footer->iframe_receive_errors); printf("Transmit aborts: 0x%04x (%1$d)\n", hostinfo->footer->transmit_aborts); printf("Transmitted: 0x%08x (%1$d)\n", hostinfo->footer->transmitted); printf("Received: 0x%08x (%1$d)\n", hostinfo->footer->received); printf("IFrame transmit errors: 0x%04x (%1$d)\n", hostinfo->footer->iframe_transmit_errors); printf("No receive buffers: 0x%04x (%1$d)\n", hostinfo->footer->no_receive_buffer); printf("tl timeouts: 0x%04x (%1$d)\n", hostinfo->footer->tl_timeouts); printf("ti timeouts: 0x%04x (%1$d)\n", hostinfo->footer->ti_timeouts); printf("Free NCBS: 0x%04x (%1$d)\n", hostinfo->footer->free_ncbs); printf("NCBS: 0x%04x (%1$d)\n", hostinfo->footer->ncbs); printf("Max NCBS: 0x%04x (%1$d)\n", hostinfo->footer->max_ncbs); printf("No transmit buffers: 0x%04x (%1$d)\n", hostinfo->footer->no_transmit_buffers); printf("Max datagram: 0x%04x (%1$d)\n", hostinfo->footer->max_datagram); printf("Pending sessions: 0x%04x (%1$d)\n", hostinfo->footer->pending_sessions); printf("Max sessions: 0x%04x (%1$d)\n", hostinfo->footer->max_sessions); printf("Packet sessions: 0x%04x (%1$d)\n", hostinfo->footer->packet_sessions); }; }; int v_print_hostinfo(struct in_addr addr, const struct nb_host_info* hostinfo, char* sf, int hr) { int i, unique; my_uint8_t service; /* 16th byte of NetBIOS name */ char name[16]; if(!sf) { printf("\nNetBIOS Name Table for Host %s:\n\n", inet_ntoa(addr)); if(hostinfo->is_broken) printf("Incomplete packet, %d bytes long.\n", hostinfo->is_broken); printf("%-17s%-17s%-17s\n", "Name", "Service", "Type"); printf("----------------------------------------\n"); }; if(hostinfo->header && hostinfo->names) { for(i=0; i< hostinfo->header->number_of_names; i++) { service = hostinfo->names[i].ascii_name[15]; strncpy(name, hostinfo->names[i].ascii_name, 15); name[15]=0; unique = !(hostinfo->names[i].rr_flags & 0x0080); if(sf) { printf("%s%s%s%s", inet_ntoa(addr), sf, name, sf); if(hr) printf("%s\n", (char*)getnbservicename(service, unique, name)); else { printf("%02x", service); if(unique) printf("U\n"); else printf("G\n"); } } else { printf("%-17s", name); if(hr) printf("%s\n", (char*)getnbservicename(service, unique, name)); else { printf("<%02x>", service); if(unique) printf(" UNIQUE\n"); else printf(" GROUP\n"); }; } }; }; if(hostinfo->footer) { if(sf) printf("%s%sMAC%s", inet_ntoa(addr), sf, sf); else printf("\nAdapter address: "); printf("%02x:%02x:%02x:%02x:%02x:%02x\n", hostinfo->footer->adapter_address[0], hostinfo->footer->adapter_address[1], hostinfo->footer->adapter_address[2], hostinfo->footer->adapter_address[3], hostinfo->footer->adapter_address[4], hostinfo->footer->adapter_address[5]); }; if(!sf) printf("----------------------------------------\n"); return 1; }; int print_hostinfo(struct in_addr addr, struct nb_host_info* hostinfo, char* sf) { int i; unsigned char service; /* 16th byte of NetBIOS name */ char comp_name[16], user_name[16]; int is_server=0; int unique; int first_name=1; strncpy(comp_name,"",15); strncpy(user_name,"",15); if(hostinfo->header && hostinfo->names) { for(i=0; i< hostinfo->header->number_of_names; i++) { service = hostinfo->names[i].ascii_name[15]; unique = ! (hostinfo->names[i].rr_flags & 0x0080); if(service == 0 && unique && first_name) { /* Unique name, workstation service - this is computer name */ strncpy(comp_name, hostinfo->names[i].ascii_name, 15); comp_name[15] = 0; first_name = 0; }; if(service == 0x20 && unique) { is_server=1; } if(service == 0x03 && unique) { strncpy(user_name, hostinfo->names[i].ascii_name, 15); user_name[15]=0; }; }; }; if(sf) { printf("%s%s%s%s", inet_ntoa(addr), sf, comp_name, sf); if(is_server) printf(""); printf("%s%s%s", sf, user_name, sf); } else { printf("%-17s%-17s",inet_ntoa(addr),comp_name); if(is_server) printf("%-10s", ""); else printf("%-10s",""); printf("%-17s", user_name); }; if(hostinfo->footer) { printf("%02x:%02x:%02x:%02x:%02x:%02x\n", hostinfo->footer->adapter_address[0], hostinfo->footer->adapter_address[1], hostinfo->footer->adapter_address[2], hostinfo->footer->adapter_address[3], hostinfo->footer->adapter_address[4], hostinfo->footer->adapter_address[5]); } else { printf("\n"); }; return 1; }; /* Print hostinfo in /etc/hosts or lmhosts format */ /* If l is true adds #PRE to each line of output (for lmhosts) */ void l_print_hostinfo(struct in_addr addr, struct nb_host_info* hostinfo, int l) { int i; unsigned char service; /* 16th byte of NetBIOS name */ char comp_name[16]; int unique; int first_name=1; strncpy(comp_name,"",15); if(hostinfo->header && hostinfo->names) { for(i=0; i< hostinfo->header->number_of_names; i++) { service = hostinfo->names[i].ascii_name[15]; unique = ! (hostinfo->names[i].rr_flags & 0x0080); if(service == 0 && unique && first_name) { /* Unique name, workstation service - this is computer name */ strncpy(comp_name, hostinfo->names[i].ascii_name, 15); comp_name[15]=0; first_name = 0; }; }; }; printf("%s\t%s", inet_ntoa(addr), comp_name); if(l) printf("\t#PRE"); printf("\n"); } #define BUFFSIZE 1024 int main(int argc, char *argv[]) { int timeout=1000, verbose=0, use137=0, ch, dump=0, bandwidth=0, send_ok=0, hr=0, etc_hosts=0, lmhosts=0; extern char *optarg; extern int optind; char* target_string; char* sf=NULL; char* filename =NULL; struct ip_range range; void *buff; int sock, addr_size; struct sockaddr_in src_sockaddr, dest_sockaddr; struct in_addr *prev_in_addr=NULL; struct in_addr *next_in_addr; struct timeval select_timeout, last_send_time, current_time, diff_time, send_interval; struct timeval transmit_started, now, recv_time; struct nb_host_info* hostinfo; fd_set* fdsr; fd_set* fdsw; int size; struct list* scanned; my_uint32_t rtt_base; /* Base time (seconds) for round trip time calculations */ float rtt; /* most recent measured RTT, seconds */ float srtt=0; /* smoothed rtt estimator, seconds */ float rttvar=0.75; /* smoothed mean deviation, seconds */ double delta; /* used in retransmit timeout calculations */ int rto, retransmits=0, more_to_send=1, i; char errmsg[80]; char str[80]; FILE* targetlist=NULL; /* Parse supplied options */ /**************************/ if(argc<2) { print_banner(); usage(); }; while ((ch = getopt(argc, argv, "vrdelqhm:s:t:b:f:")) != -1) switch (ch) { case 'v': verbose = 1; break; case 't': timeout=atoi(optarg); if(timeout==0) { printf("Bad timeout value: %s\n", optarg); usage(); }; break; case 'r': #if defined WINDOWS printf("Warning: -r option not supported under Windows. Running without it.\n\n"); #else use137=1; #endif break; case 'd': dump=1; break; case 'e': etc_hosts=1; break; case 'l': lmhosts=1; break; case 'q': quiet=1; /* Global variable */ break; case 'b': bandwidth=atoi(optarg); if(bandwidth==0) err_print("Bad bandwidth value, ignoring it", quiet); break; case 'h': hr=1; /* human readable service names instead of hex codes */ break; case 's': sf=optarg; /* script-friendly output format */ break; case 'm': retransmits=atoi(optarg); if(retransmits==0) { printf("Bad number of retransmits: %s\n", optarg); usage(); }; break; case 'f': filename = optarg; break; default: print_banner(); usage(); }; if(dump && verbose) { printf("Cannot be used with both dump (-d) and verbose (-v) options.\n"); usage(); }; if(dump && sf) { printf("Cannot be used with both dump (-d) and script-friendly (-s) options.\n"); usage(); }; if(dump && lmhosts) { printf("Cannot be used with both dump (-d) and lmhosts (-l) options.\n"); usage(); }; if(dump && etc_hosts) { printf("Cannot be used with both dump (-d) and /etc/hosts (-e) options.\n"); usage(); }; if(verbose && lmhosts){ printf("Cannot be used with both verbose (-v) and lmhosts (-l) options.\n"); usage(); }; if(verbose && etc_hosts){ printf("Cannot be used with both verbose (-v) and /etc/hosts (-e) options.\n"); usage(); }; if(lmhosts && etc_hosts){ printf("Cannot be used with both lmhosts (-l) and /etc/hosts (-e) options.\n"); usage(); }; if(dump && hr) { printf("Cannot be used with both dump (-d) and \"human-readable service names\" (-h) options.\n"); usage(); }; if(hr && !verbose) { printf("\"Human-readable service names\" (-h) option cannot be used without verbose (-v) option.\n"); usage(); }; if(filename) { if(strcmp(filename, "-") == 0) { /* Get IP addresses from stdin */ targetlist = stdin; target_string = "STDIN"; } else { targetlist=fopen(filename,"r"); target_string = filename; }; if(!targetlist) { snprintf(errmsg, 80, "Cannot open file %s", filename); err_die(errmsg, quiet); } } else { argc -= optind; argv += optind; if(argc!=1) usage(); if((target_string=strdup(argv[0]))==NULL) err_die("Malloc failed.\n", quiet); if(!set_range(target_string, &range)) { printf("Error: %s is not an IP address or address range.\n", target_string); free(target_string); usage(); }; } if(!(quiet || sf || lmhosts || etc_hosts)) printf("Doing NBT name scan for addresses from %s\n\n", target_string); /* Finished with options */ /*************************/ /* Prepare socket and address structures */ /*****************************************/ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (sock < 0) err_die("Failed to create socket", quiet); bzero((void*)&src_sockaddr, sizeof(src_sockaddr)); src_sockaddr.sin_family = AF_INET; if(use137) src_sockaddr.sin_port = htons(NB_DGRAM); if (bind(sock, (struct sockaddr *)&src_sockaddr, sizeof(src_sockaddr)) == -1) err_die("Failed to bind", quiet); fdsr=malloc(sizeof(fd_set)); if(!fdsr) err_die("Malloc failed", quiet); FD_ZERO(fdsr); FD_SET(sock, fdsr); fdsw=malloc(sizeof(fd_set)); if(!fdsw) err_die("Malloc failed", quiet); FD_ZERO(fdsw); FD_SET(sock, fdsw); /* timeout is in milliseconds */ select_timeout.tv_sec = 60; /* Default 1 min to survive ARP timeouts */ select_timeout.tv_usec = 0; addr_size = sizeof(struct sockaddr_in); next_in_addr = malloc(sizeof(struct in_addr)); if(!next_in_addr) err_die("Malloc failed", quiet); buff=malloc(BUFFSIZE); if(!buff) err_die("Malloc failed", quiet); /* Calculate interval between subsequent sends */ timerclear(&send_interval); if(bandwidth) send_interval.tv_usec = (NBNAME_REQUEST_SIZE + UDP_HEADER_SIZE + IP_HEADER_SIZE)*8*1000000 / bandwidth; /* Send interval in microseconds */ else /* Assuming 10baseT bandwidth */ send_interval.tv_usec = 1; /* for 10baseT interval should be about 1 ms */ if (send_interval.tv_usec >= 1000000) { send_interval.tv_sec = send_interval.tv_usec / 1000000; send_interval.tv_usec = send_interval.tv_usec % 1000000; } gettimeofday(&last_send_time, NULL); /* Get current time */ rtt_base = last_send_time.tv_sec; /* Send queries, receive answers and print results */ /***************************************************/ scanned = new_list(); if(!(quiet || verbose || dump || sf || lmhosts || etc_hosts)) print_header(); for(i=0; i <= retransmits; i++) { gettimeofday(&transmit_started, NULL); while ( (select(sock+1, fdsr, fdsw, NULL, &select_timeout)) > 0) { if(FD_ISSET(sock, fdsr)) { if ( (size = recvfrom(sock, buff, BUFFSIZE, 0, (struct sockaddr*)&dest_sockaddr, &addr_size)) <= 0 ) { snprintf(errmsg, 80, "%s\tRecvfrom failed", inet_ntoa(dest_sockaddr.sin_addr)); err_print(errmsg, quiet); continue; }; gettimeofday(&recv_time, NULL); hostinfo = (struct nb_host_info*)parse_response(buff, size); if(!hostinfo) { err_print("parse_response returned NULL", quiet); continue; }; /* If this packet isn't a duplicate */ if(insert(scanned, ntohl(dest_sockaddr.sin_addr.s_addr))) { rtt = recv_time.tv_sec + recv_time.tv_usec/1000000 - rtt_base - hostinfo->header->transaction_id/1000; /* Using algorithm described in Stevens' Unix Network Programming */ delta = rtt - srtt; srtt += delta / 8; if(delta < 0.0) delta = - delta; rttvar += (delta - rttvar) / 4 ; if (verbose) v_print_hostinfo(dest_sockaddr.sin_addr, hostinfo, sf, hr); else if (dump) d_print_hostinfo(dest_sockaddr.sin_addr, hostinfo); else if (etc_hosts) l_print_hostinfo(dest_sockaddr.sin_addr, hostinfo, 0); else if (lmhosts) l_print_hostinfo(dest_sockaddr.sin_addr, hostinfo, 1); else print_hostinfo(dest_sockaddr.sin_addr, hostinfo,sf); }; free(hostinfo); }; FD_ZERO(fdsr); FD_SET(sock, fdsr); /* check if send_interval time passed since last send */ gettimeofday(¤t_time, NULL); timersub(¤t_time, &last_send_time, &diff_time); send_ok = timercmp(&diff_time, &send_interval, >=); if(more_to_send && FD_ISSET(sock, fdsw) && send_ok) { if(targetlist) { if(fgets(str, 80, targetlist)) { if(!inet_aton(str, next_in_addr)) { /* if(!inet_pton(AF_INET, str, next_in_addr)) { */ fprintf(stderr,"%s - bad IP address\n", str); } else { if(!in_list(scanned, ntohl(next_in_addr->s_addr))) send_query(sock, *next_in_addr, rtt_base); } } else { if(feof(targetlist)) { more_to_send=0; FD_ZERO(fdsw); /* timeout is in milliseconds */ select_timeout.tv_sec = timeout / 1000; select_timeout.tv_usec = (timeout % 1000) * 1000; /* Microseconds */ continue; } else { snprintf(errmsg, 80, "Read failed from file %s", filename); err_die(errmsg, quiet); } } } else if(next_address(&range, prev_in_addr, next_in_addr) ) { if(!in_list(scanned, ntohl(next_in_addr->s_addr))) send_query(sock, *next_in_addr, rtt_base); prev_in_addr=next_in_addr; /* Update last send time */ gettimeofday(&last_send_time, NULL); } else { /* No more queries to send */ more_to_send=0; FD_ZERO(fdsw); /* timeout is in milliseconds */ select_timeout.tv_sec = timeout / 1000; select_timeout.tv_usec = (timeout % 1000) * 1000; /* Microseconds */ continue; }; }; if(more_to_send) { FD_ZERO(fdsw); FD_SET(sock, fdsw); }; }; if (i>=retransmits) break; /* If we are not going to retransmit we can finish right now without waiting */ rto = (srtt + 4 * rttvar) * (i+1); if ( rto < 2.0 ) rto = 2.0; if ( rto > 60.0 ) rto = 60.0; gettimeofday(&now, NULL); if(now.tv_sec < (transmit_started.tv_sec+rto)) sleep((transmit_started.tv_sec+rto)-now.tv_sec); prev_in_addr = NULL ; more_to_send=1; FD_ZERO(fdsw); FD_SET(sock, fdsw); FD_ZERO(fdsr); FD_SET(sock, fdsr); }; delete_list(scanned); exit(0); }; nbtscan-1.6/src/range.c000066400000000000000000000106111356340071200150370ustar00rootroot00000000000000/* # Copyright 1999-2003 Alla Bezroutchko # Copyright 2004 Jochen Friedrich # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include "range.h" #include #include #include "errors.h" #ifndef INADDR_NONE # define INADDR_NONE (in_addr_t)-1 #endif extern int quiet; /* is_ip checks if supplied string is an ip address in dotted-decimal notation, and fills both members of range structure with its numerical value (host byte order)/ Returns 1 on success, 0 on failure */ int is_ip(char* string, struct ip_range* range) { unsigned long addr; addr = inet_addr(string); if(addr != INADDR_NONE) { range->start_ip = ntohl(addr); range->end_ip = ntohl(addr); return 1; } else return 0; }; /* is_range1 checks if supplied string is an IP address range in form xxx.xxx.xxx.xxx/xx (as in 192.168.1.2/24) and fills range structure with start and end ip addresses of the interval. Returns 1 on success, 0 on failure */ int is_range1(char* string, struct ip_range* range) { char* separator; unsigned int mask; char* ip; if((ip = (char *)malloc(strlen(string)+1))==NULL) err_die("Malloc failed", quiet); if (strlen(string)>19) return 0; if((separator=(char*)strchr(string,'/'))) { separator++; mask=atoi(separator); if(mask<=0 || mask>32) return 0; strcpy(ip, string); ip[abs(string-separator)-1]=0; if((range->start_ip=inet_addr(ip)) == INADDR_NONE) return 0; /* mask=((1<start_ip=ntohl(range->start_ip); // We store ips in host byte order range->start_ip &= mask; range->end_ip = range->start_ip | ( ~ mask); free(ip); return 1; } free(ip); return 0; }; /* next_address function writes next ip address in range after prev_addr to structure pointed by next_addr. Returns 1 if next ip found and 0 otherwise */ int next_address(const struct ip_range* range, const struct in_addr* prev_addr, struct in_addr* next_addr) { unsigned long pa; // previous address, host byte order if(prev_addr) { pa = ntohl(prev_addr->s_addr); if(pa < range->end_ip) { next_addr->s_addr=htonl(++pa); return 1; } else return 0; } else { next_addr->s_addr=htonl(range->start_ip); return 1; }; }; /* is_range2 checks if supplied string is an IP address range in form xxx.xxx.xxx.xxx-xxx (as in 192.168.1.2-15) and fills range structure with start and end ip addresses of the interval. Returns 1 on success, 0 on failure */ int is_range2(char* string, struct ip_range* range) { unsigned long last_octet; /*last octet of last ip in range*/ char* separator; unsigned long addr; char* ip; if((ip = (char *)malloc(strlen(string)+1))==NULL) err_die("Malloc failed", quiet); strcpy(ip,string); if((separator = (char*)strchr(ip,'-'))) { *separator=0; separator++; last_octet = atoi(separator); if(last_octet<0 || last_octet > 255) { free(ip); return 0; }; addr = inet_addr(ip); if(addr == INADDR_NONE) { free(ip); return 0; }; range->start_ip = ntohl(addr); range->end_ip = (range->start_ip & 0xffffff00) | last_octet; if (range->end_ip < range->start_ip) { free(ip); return 0; }; free(ip); return 1; } free(ip); return 0; }; void print_range(const struct ip_range* range) { struct in_addr *addr; if((addr = (struct in_addr*)malloc(sizeof(struct in_addr)))==NULL) err_die("Malloc failed", quiet); next_address(range, 0, addr); printf("%s\n",inet_ntoa(*addr)); while(next_address(range, addr, addr)) { printf("%s\n",inet_ntoa(*addr)); }; free(addr); }; nbtscan-1.6/src/range.h000066400000000000000000000044051356340071200150500ustar00rootroot00000000000000/* # Copyright 1999-2003 Alla Bezroutchko # Copyright 2004 Jochen Friedrich # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #if !defined RANGE_H #define RANGE_H struct ip_range { unsigned long start_ip; // IP addresses in _host_ order, not network unsigned long end_ip; }; /* is_ip checks if supplied string is an ip address in dotted-decimal notation, and fills both members of range structure with its numerical value (host byte order)/ Returns 1 on success, 0 on failure */ int is_ip(char* string, struct ip_range* range); /* is_range1 checks if supplied string is an IP address range in form xxx.xxx.xxx.xxx/xx (as in 192.168.1.2/24) and fills range structure with start and end ip addresses of the interval. Returns 1 on success, 0 on failure */ int is_range1(char* string, struct ip_range* range); /* next_address function writes next ip address in range after prev_addr to structure pointed by next_addr. Returns 1 if next ip found and 0 otherwise */ int next_address(const struct ip_range* range, const struct in_addr* prev_addr, struct in_addr* next_addr); /* is_range2 checks if supplied string is an IP address range in form xxx.xxx.xxx.xxx-xxx (as in 192.168.1.2-15) and fills range structure with start and end ip addresses of the interval. Returns 1 on success, 0 on failure */ int is_range2(char* string, struct ip_range* range); void print_range(const struct ip_range* range); #endif /* RANGE_H */ nbtscan-1.6/src/statusq.c000066400000000000000000000341341356340071200154550ustar00rootroot00000000000000/* This file contains a portion of code from Samba package, * / which contains the following license: * / Unix SMB/Netbios implementation Version 1.9 Main SMB server routine Copyright 1992-1995 Andrew Tridgell Copyright 2004 Jochen Friedrich This program is free software; you can redistribute it and/or modif it under the terms of the GNU General Public License as published b the Free Software Foundation; either version 2 of the License, o (at your option) any later version This program is distributed in the hope that it will be useful but WITHOUT ANY WARRANTY; without even the implied warranty o MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See th GNU General Public License for more details You should have received a copy of the GNU General Public Licens along with this program; if not, write to the Free Softwar Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA */ #include #include #include #include #include #include #include "statusq.h" #include #include #include #include #include "errors.h" extern int quiet; /* Start of code from Samba */ int name_mangle( char *In, char *Out, char name_type ) { int i; int c; int len; char buf[20]; char *p = Out; char* scope=""; /* Safely copy the input string, In, into buf[]. */ (void)memset( buf, 0, 20 ); if (strcmp(In,"*") == 0) buf[0] = '*'; else #ifdef HAVE_SNPRINTF (void)snprintf( buf, sizeof(buf) - 1, "%-15.15s%c", In, name_type ); #else (void)sprintf( buf, "%-15.15s%c", In, name_type ); #endif /* HAVE_SNPRINTF */ /* Place the length of the first field into the output buffer. */ p[0] = 32; p++; /* Now convert the name to the rfc1001/1002 format. */ for( i = 0; i < 16; i++ ) { c = toupper( buf[i] ); p[i*2] = ( (c >> 4) & 0x000F ) + 'A'; p[(i*2)+1] = (c & 0x000F) + 'A'; } p += 32; p[0] = '\0'; /* Add the scope string. */ for( i = 0, len = 0; NULL != scope; i++, len++ ) { switch( scope[i] ) { case '\0': p[0] = len; if( len > 0 ) p[len+1] = 0; return( strlen(Out) ); case '.': p[0] = len; p += (len + 1); len = 0; break; default: p[len+1] = scope[i]; break; } } return( strlen(Out) ); }; /* name_mangle */ /* end of code from Samba */ void send_query(int sock, struct in_addr dest_addr, my_uint32_t rtt_base) { struct nbname_request request; struct sockaddr_in dest_sockaddr; int status; struct timeval tv; char errmsg[80]; bzero((void*)&dest_sockaddr, sizeof(dest_sockaddr)); dest_sockaddr.sin_family = AF_INET; dest_sockaddr.sin_port = htons(NB_DGRAM); dest_sockaddr.sin_addr = dest_addr; request.flags = htons(FL_BROADCAST); request.question_count = htons(1); request.answer_count = 0; request.name_service_count = 0; request.additional_record_count = 0; name_mangle("*", request.question_name,0); request.question_type = htons(0x21); request.question_class = htons(0x01); gettimeofday(&tv, NULL); /* Use transaction ID as a timestamp */ request.transaction_id = htons((tv.tv_sec-rtt_base)*1000+tv.tv_usec/1000); /* printf("%s: timestamp: %d\n", inet_ntoa(dest_addr), request.transaction_id); */ status = sendto(sock, (char*)&request, sizeof(request), 0, (struct sockaddr *)&dest_sockaddr, sizeof(dest_sockaddr)); if(status==-1) { snprintf(errmsg, 80, "%s\tSendto failed", inet_ntoa(dest_addr)); err_print(errmsg, quiet); }; }; my_uint32_t get32(void* data) { union { char bytes[4]; my_uint32_t all; } x; memcpy(x.bytes, data, 4); return(ntohl(x.all)); }; my_uint16_t get16(void* data) { union { char bytes[2]; my_uint16_t all; } x; memcpy(x.bytes, data, 2); return(ntohs(x.all)); }; struct nb_host_info* parse_response(char* buff, int buffsize) { struct nb_host_info* hostinfo = NULL; nbname_response_footer_t* response_footer; nbname_response_header_t* response_header; int name_table_size; int offset = 0; if((response_header = malloc(sizeof(nbname_response_header_t)))==NULL) return NULL; if((response_footer = malloc(sizeof(nbname_response_footer_t)))==NULL) return NULL; bzero(response_header, sizeof(nbname_response_header_t)); bzero(response_footer, sizeof(nbname_response_footer_t)); if((hostinfo = malloc(sizeof(struct nb_host_info)))==NULL) return NULL; hostinfo->header = NULL; hostinfo->names = NULL; hostinfo->footer = NULL; /* Parsing received packet */ /* Start with header */ if( offset+sizeof(response_header->transaction_id) >= buffsize) goto broken_packet; response_header->transaction_id = get16(buff+offset); //Move pointer to the next structure field offset+=sizeof(response_header->transaction_id); hostinfo->header = response_header; // Check if there is room for next field in buffer if( offset+sizeof(response_header->flags) >= buffsize) goto broken_packet; response_header->flags = get16(buff+offset); offset+=sizeof(response_header->flags); if( offset+sizeof(response_header->question_count) >= buffsize) goto broken_packet; response_header->question_count = get16(buff+offset); offset+=sizeof(response_header->question_count); if( offset+sizeof(response_header->answer_count) >= buffsize) goto broken_packet; response_header->answer_count = get16(buff+offset); offset+=sizeof(response_header->answer_count); if( offset+sizeof(response_header->name_service_count) >= buffsize) goto broken_packet; response_header->name_service_count = get16(buff+offset); offset+=sizeof(response_header->name_service_count); if( offset+sizeof(response_header->additional_record_count) >= buffsize) goto broken_packet; response_header->additional_record_count = get16(buff+offset); offset+=sizeof(response_header->additional_record_count); if( offset+sizeof(response_header->question_name) >= buffsize) goto broken_packet; strncpy(response_header->question_name, buff+offset, sizeof(response_header->question_name)); offset+=sizeof(response_header->question_name); if( offset+sizeof(response_header->question_type) >= buffsize) goto broken_packet; response_header->question_type = get16(buff+offset); offset+=sizeof(response_header->question_type); if( offset+sizeof(response_header->question_class) >= buffsize) goto broken_packet; response_header->question_class = get16(buff+offset); offset+=sizeof(response_header->question_class); if( offset+sizeof(response_header->ttl) >= buffsize) goto broken_packet; response_header->ttl = get32(buff+offset); offset+=sizeof(response_header->ttl); if( offset+sizeof(response_header->rdata_length) >= buffsize) goto broken_packet; response_header->rdata_length = get16(buff+offset); offset+=sizeof(response_header->rdata_length); if( offset+sizeof(response_header->number_of_names) >= buffsize) goto broken_packet; response_header->number_of_names = *(typeof(response_header->number_of_names)*)(buff+offset); offset+=sizeof(response_header->number_of_names); /* Done with packet header - it is okay */ name_table_size = (response_header->number_of_names) * (sizeof(struct nbname)); if( offset+name_table_size >= buffsize) goto broken_packet; if((hostinfo->names = malloc(name_table_size))==NULL) return NULL; memcpy(hostinfo->names, buff + offset, name_table_size); offset+=name_table_size; /* Done with name table - it is okay */ /* Now parse response footer */ if( offset+sizeof(response_footer->adapter_address) >= buffsize) goto broken_packet; memcpy(response_footer->adapter_address, (buff+offset), sizeof(response_footer->adapter_address)); offset+=sizeof(response_footer->adapter_address); hostinfo->footer=response_footer; if( offset+sizeof(response_footer->version_major) >= buffsize) goto broken_packet; response_footer->version_major = *(typeof(response_footer->version_major)*)(buff+offset); offset+=sizeof(response_footer->version_major); if( offset+sizeof(response_footer->version_minor) >= buffsize) goto broken_packet; response_footer->version_minor = *(typeof(response_footer->version_minor)*)(buff+offset); offset+=sizeof(response_footer->version_minor); if( offset+sizeof(response_footer->duration) >= buffsize) goto broken_packet; response_footer->duration = get16(buff+offset); offset+=sizeof(response_footer->duration); if( offset+sizeof(response_footer->frmps_received) >= buffsize) goto broken_packet; response_footer->frmps_received= get16(buff+offset); offset+=sizeof(response_footer->frmps_received); if( offset+sizeof(response_footer->frmps_transmitted) >= buffsize) goto broken_packet; response_footer->frmps_transmitted = get16(buff+offset); offset+=sizeof(response_footer->frmps_transmitted); if( offset+sizeof(response_footer->iframe_receive_errors) >= buffsize) goto broken_packet; response_footer->iframe_receive_errors = get16(buff+offset); offset+=sizeof(response_footer->iframe_receive_errors); if( offset+sizeof(response_footer->transmit_aborts) >= buffsize) goto broken_packet; response_footer->transmit_aborts = get16(buff+offset); offset+=sizeof(response_footer->transmit_aborts); if( offset+sizeof(response_footer->transmitted) >= buffsize) goto broken_packet; response_footer->transmitted = get32(buff+offset); offset+=sizeof(response_footer->transmitted); if( offset+sizeof(response_footer->received) >= buffsize) goto broken_packet; response_footer->received = get32(buff+offset); offset+=sizeof(response_footer->received); if( offset+sizeof(response_footer->iframe_transmit_errors) >= buffsize) goto broken_packet; response_footer->iframe_transmit_errors = get16(buff+offset); offset+=sizeof(response_footer->iframe_transmit_errors); if( offset+sizeof(response_footer->no_receive_buffer) >= buffsize) goto broken_packet; response_footer->no_receive_buffer = get16(buff+offset); offset+=sizeof(response_footer->no_receive_buffer); if( offset+sizeof(response_footer->tl_timeouts) >= buffsize) goto broken_packet; response_footer->tl_timeouts = get16(buff+offset); offset+=sizeof(response_footer->tl_timeouts); if( offset+sizeof(response_footer->ti_timeouts) >= buffsize) goto broken_packet; response_footer->ti_timeouts = get16(buff+offset); offset+=sizeof(response_footer->ti_timeouts); if( offset+sizeof(response_footer->free_ncbs) >= buffsize) goto broken_packet; response_footer->free_ncbs = get16(buff+offset); offset+=sizeof(response_footer->free_ncbs); if( offset+sizeof(response_footer->ncbs) >= buffsize) goto broken_packet; response_footer->ncbs = get16(buff+offset); offset+=sizeof(response_footer->ncbs); if( offset+sizeof(response_footer->max_ncbs) >= buffsize) goto broken_packet; response_footer->max_ncbs = get16(buff+offset); offset+=sizeof(response_footer->max_ncbs); if( offset+sizeof(response_footer->no_transmit_buffers) >= buffsize) goto broken_packet; response_footer->no_transmit_buffers = get16(buff+offset); offset+=sizeof(response_footer->no_transmit_buffers); if( offset+sizeof(response_footer->max_datagram) >= buffsize) goto broken_packet; response_footer->max_datagram = get16(buff+offset); offset+=sizeof(response_footer->max_datagram); if( offset+sizeof(response_footer->pending_sessions) >= buffsize) goto broken_packet; response_footer->pending_sessions = get16(buff+offset); offset+=sizeof(response_footer->pending_sessions); if( offset+sizeof(response_footer->max_sessions) >= buffsize) goto broken_packet; response_footer->max_sessions = get16(buff+offset); offset+=sizeof(response_footer->max_sessions); if( offset+sizeof(response_footer->packet_sessions) >= buffsize) goto broken_packet; response_footer->packet_sessions = get16(buff+offset); offset+=sizeof(response_footer->packet_sessions); /* Done with packet footer and the whole packet */ return hostinfo; broken_packet: hostinfo->is_broken = offset; return hostinfo; }; nb_service_t services[] = { {"__MSBROWSE__", 0x01, 0, "Master Browser"}, {"INet~Services", 0x1C, 0, "IIS"}, {"IS~", 0x00, 1, "IIS"}, {"", 0x00, 1, "Workstation Service"}, {"", 0x01, 1, "Messenger Service"}, {"", 0x03, 1, "Messenger Service"}, {"", 0x06, 1, "RAS Server Service"}, {"", 0x1F, 1, "NetDDE Service"}, {"", 0x20, 1, "File Server Service"}, {"", 0x21, 1, "RAS Client Service"}, {"", 0x22, 1, "Microsoft Exchange Interchange(MSMail Connector)"}, {"", 0x23, 1, "Microsoft Exchange Store"}, {"", 0x24, 1, "Microsoft Exchange Directory"}, {"", 0x30, 1, "Modem Sharing Server Service"}, {"", 0x31, 1, "Modem Sharing Client Service"}, {"", 0x43, 1, "SMS Clients Remote Control"}, {"", 0x44, 1, "SMS Administrators Remote Control Tool"}, {"", 0x45, 1, "SMS Clients Remote Chat"}, {"", 0x46, 1, "SMS Clients Remote Transfer"}, {"", 0x4C, 1, "DEC Pathworks TCPIP service on Windows NT"}, {"", 0x52, 1, "DEC Pathworks TCPIP service on Windows NT"}, {"", 0x87, 1, "Microsoft Exchange MTA"}, {"", 0x6A, 1, "Microsoft Exchange IMC"}, {"", 0xBE, 1, "Network Monitor Agent"}, {"", 0xBF, 1, "Network Monitor Application"}, {"", 0x03, 1, "Messenger Service"}, {"", 0x00, 0, "Domain Name"}, {"", 0x1B, 1, "Domain Master Browser"}, {"", 0x1C, 0, "Domain Controllers"}, {"", 0x1D, 1, "Master Browser"}, {"", 0x1E, 0, "Browser Service Elections"}, {"", 0x2B, 1, "Lotus Notes Server Service"}, {"IRISMULTICAST", 0x2F, 0, "Lotus Notes"}, {"IRISNAMESERVER", 0x33, 0, "Lotus Notes"}, {"Forte_$ND800ZA", 0x20, 1, "DCA IrmaLan Gateway Server Service"} }; char* getnbservicename(my_uint8_t service, int unique, char* name) { int i; char *unknown; unknown = (char*)malloc(100); if(!unknown) err_die("Malloc failed.\n", 0); for(i=0; i < 35; i++) { if(strstr(name, services[i].nb_name) && service == services[i].service_number && unique == services[i].unique) return services[i].service_name; }; snprintf(unknown, 100, "Unknown service (code %x)", service); return(unknown); }; nbtscan-1.6/src/statusq.h000066400000000000000000000047701356340071200154650ustar00rootroot00000000000000#if !defined STATUSQ_H #define STATUSQ_H #if defined HAVE_STDINT_H #include #endif #include #define FL_REQUEST 0x8000 #define FL_QUERY 0x7800 #define FL_NON_AUTH_ANSWER 0x0400 #define FL_DGRAM_NOT_TRUNCATED 0x0200 #define FL_RECURSION_NOT_DESIRED 0x0100 #define FL_RECURSION_NOT_AVAIl 0x0080 #define FL_RESERVED1 0x0040 #define FL_RESERVED2 0x0020 #define FL_BROADCAST 0x0010 #define FL_SUCCESS 0x000F #define QT_NODE_STATUS_REQUEST 0x0021 #define QC_INTERNET 0x0001 #define NB_DGRAM 137 struct nbname { char ascii_name [16] ; my_uint16_t rr_flags; }; struct nbname_request { my_uint16_t transaction_id; my_uint16_t flags; my_uint16_t question_count; my_uint16_t answer_count; my_uint16_t name_service_count; my_uint16_t additional_record_count; char question_name[34]; my_uint16_t question_type; my_uint16_t question_class; }; #define NBNAME_REQUEST_SIZE 50 #define UDP_HEADER_SIZE 8 #define IP_HEADER_SIZE 20 typedef struct nbname_response_header { my_uint16_t transaction_id; my_uint16_t flags; my_uint16_t question_count; my_uint16_t answer_count; my_uint16_t name_service_count; my_uint16_t additional_record_count; char question_name[34]; my_uint16_t question_type; my_uint16_t question_class; my_uint32_t ttl; my_uint16_t rdata_length; my_uint8_t number_of_names; } nbname_response_header_t; /* #define NBNAME_RESPONSE_NUMBER_OF_NAMES_OFFSET 56 */ #define NBNAME_RESPONSE_HEADER_SIZE 57 typedef struct nbname_response_footer { my_uint8_t adapter_address [6]; my_uint8_t version_major; my_uint8_t version_minor; my_uint16_t duration; my_uint16_t frmps_received; my_uint16_t frmps_transmitted; my_uint16_t iframe_receive_errors; my_uint16_t transmit_aborts; my_uint32_t transmitted; my_uint32_t received; my_uint16_t iframe_transmit_errors; my_uint16_t no_receive_buffer; my_uint16_t tl_timeouts; my_uint16_t ti_timeouts; my_uint16_t free_ncbs; my_uint16_t ncbs; my_uint16_t max_ncbs; my_uint16_t no_transmit_buffers; my_uint16_t max_datagram; my_uint16_t pending_sessions; my_uint16_t max_sessions; my_uint16_t packet_sessions; } nbname_response_footer_t ; #define NBNAME_RESPONSE_FOOTER_SIZE 50 struct nb_host_info { struct nbname_response_header* header; struct nbname* names; struct nbname_response_footer* footer; int is_broken; }; typedef struct nb_service { char nb_name[16]; my_uint8_t service_number; int unique; char* service_name; } nb_service_t ; #endif /* STATUSQ_H */ nbtscan-1.6/src/time.h000066400000000000000000000030741356340071200147130ustar00rootroot00000000000000/* # Copyright 1999-2003 Alla Bezroutchko # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef timerclear #define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0 #endif #ifndef timercmp #define timercmp(tvp, uvp, cmp) \ (((tvp)->tv_sec == (uvp)->tv_sec) ? \ ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ ((tvp)->tv_sec cmp (uvp)->tv_sec)) #endif #ifndef timersub #define timersub(tvp, uvp, vvp) \ do { \ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ if ((vvp)->tv_usec < 0) { \ (vvp)->tv_sec--; \ (vvp)->tv_usec += 1000000; \ } \ } while (0) #endif