SHA256
1
0
forked from pool/netdiscover
netdiscover/netdiscover-upstream-20160415.patch
2017-07-01 17:49:30 +00:00

452 lines
14 KiB
Diff

diff -uraN netdiscover-0.3-pre-beta7/src/data_reply.c netdiscover.svn/src/data_reply.c
--- netdiscover-0.3-pre-beta7/src/data_reply.c 2015-03-24 05:03:46.000000000 +0100
+++ netdiscover.svn/src/data_reply.c 2016-05-22 23:54:48.803447040 +0200
@@ -98,7 +98,7 @@
/* Fill again with spaces and cut the string to fit width */
- for (j=strlen(line); j<win_sz.ws_col - 1; j++)
+ for (j=strlen(line); (j<win_sz.ws_col - 1) && (j<sizeof(line)-1) ; j++)
strcat(line, blank);
string_cutter(line, win_sz.ws_col - 1 );
diff -uraN netdiscover-0.3-pre-beta7/src/data_request.c netdiscover.svn/src/data_request.c
--- netdiscover-0.3-pre-beta7/src/data_request.c 2015-03-24 05:03:46.000000000 +0100
+++ netdiscover.svn/src/data_request.c 2016-05-22 23:54:48.851447278 +0200
@@ -103,7 +103,7 @@
strcat(line, tline);
/* Fill again with spaces and cut the string to fit width */
- for (j=strlen(line); j<win_sz.ws_col - 1; j++)
+ for (j=strlen(line); (j<win_sz.ws_col - 1) && (j<sizeof(line)-1); j++)
strcat(line, blank);
string_cutter(line, win_sz.ws_col - 1);
diff -uraN netdiscover-0.3-pre-beta7/src/data_unique.c netdiscover.svn/src/data_unique.c
--- netdiscover-0.3-pre-beta7/src/data_unique.c 2015-03-24 05:03:46.000000000 +0100
+++ netdiscover.svn/src/data_unique.c 2016-05-22 23:54:48.799447020 +0200
@@ -97,7 +97,7 @@
strcat(line, tline);
/* Fill again with spaces and cut the string to fit width */
- for (j=strlen(line); j<win_sz.ws_col - 1; j++)
+ for (j=strlen(line); (j<win_sz.ws_col - 1) && (j<sizeof(line)-1); j++)
strcat(line, blank);
string_cutter(line, win_sz.ws_col - 1);
diff -uraN netdiscover-0.3-pre-beta7/update-oui-database-legacy.sh netdiscover.svn/update-oui-database-legacy.sh
--- netdiscover-0.3-pre-beta7/update-oui-database-legacy.sh 1970-01-01 01:00:00.000000000 +0100
+++ netdiscover.svn/update-oui-database-legacy.sh 2016-05-22 23:54:48.603446048 +0200
@@ -0,0 +1,120 @@
+#!/bin/bash
+
+# Script for generation "oui.h" file (netdiscover program at
+# http://nixgeneration.com/~jaime/netdiscover/
+#
+# Obtain data from internet source at:
+# lynx -source http://standards.ieee.org/regauth/oui/oui.txt >oui.txt
+#
+# Syntax: oui.txt2oui.h_netdiscover
+#
+# Script generate src/oui.h file.
+#
+# 16-May-2009 Frantisek Hanzlik <franta@hanzlici.cz> (Original author)
+# 07-Jun-2001 Larry Reznick <lreznick@rezfam.com> (fixes & code clean)
+#**********************************************************************
+#
+# 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 3 of the License, or
+# (at your option) any later version.
+#
+
+JA=${0##*/}
+DATE=$(date +'%Y%m%d')
+ORIGF=oui.txt
+DSTD=src
+DSTF=oui.h
+URL="http://standards.ieee.org/develop/regauth/oui/oui.txt"
+TMPF=$ORIGF-$DATE
+AWK="gawk"
+#AWK="mawk"
+#AWK="awk"
+
+[ -d "$DSTD" ] || { echo "$JA: Destdir \"$DSTD\" not exist!"; exit 1; }
+#if ! [ -f "$TMPF" -a -s "$TMPF" ]; then
+# echo "Trying download \"$ORIGF\" with lynx..."
+# if ! lynx -source $URL >"$TMPF"; then
+# echo "Trying download \"$ORIGF\" with elinks..."
+# if ! elinks -source $URL >"$TMPF"; then
+# echo "Trying download \"$ORIGF\" with wget..."
+# if ! wget --quiet --output-document="$TMPF" $URL; then
+# echo "$JA: Cann't obtain \"$URL\"!"
+# exit 1
+# fi
+# fi
+# fi
+#else
+# echo "\"$TMPF\" already exist, skipping download..."
+#fi
+if ! [ -f "$TMPF" -a -s "$TMPF" ]; then
+ echo -n "Trying download \"$ORIGF\" with lynx..."
+ if [[ -x /usr/bin/lynx ]]; then
+ lynx -source $URL >"$TMPF"
+ else
+ echo -n " with elinks..."
+ if [[ -x /usr/bin/elinks ]]; then
+ elinks -source $URL >"$TMPF"
+ else
+ echo " with wget..."
+ if [[ -x /usr/bin/wget ]]; then
+ wget --quiet --output-document="$TMPF" $URL
+ else
+ if [[ -x /usr/bin/curl ]]; then
+ curl -s $URL >"$TMPF"
+ else
+ echo "$JA: Can't obtain \"$URL\"!"
+ exit 1
+ fi
+ fi
+ fi
+ fi
+else
+ echo -n "\"$TMPF\" already exist, skipping download..."
+fi
+echo ""
+
+echo "Process oui.txt (\"$TMPF\")..."
+
+# if RS is null string, then records are separated by blank lines...
+# but this isn't true in oui.txt
+
+LANG=C grep "base 16" $TMPF | sed "s/\"/'/g" | $AWK --re-interval --assign URL="$URL" '
+BEGIN {
+ NN = 0;
+ printf( \
+ "/*\n" \
+ " * Organizationally Unique Identifier list at date %s\n" \
+ " * Automatically generated from %s\n" \
+ " * For Netdiscover by Jaime Penalba\n" \
+ " *\n" \
+ " */\n" \
+ "\n" \
+ "struct oui {\n" \
+ " char *prefix; /* 24 bit global prefix */\n" \
+ " char *vendor; /* Vendor id string */\n" \
+ "};\n" \
+ "\n" \
+ "struct oui oui_table[] = {\n", strftime("%d-%b-%Y"), URL);
+}
+
+{
+ printf(" { \"%s\", \"", $1);
+ for (i=4; i<NF; i++) printf $i " ";
+ printf("%s\" },\n", $NF);
+ NN++;
+}
+
+END {
+ printf(" { NULL, NULL }\n};\n\n");
+ printf("// Total %i items.\n\n", NN);
+}' >"$DSTD/$DSTF"
+
+
+if [ $? -ne 0 ]; then
+ echo "$JA: $TMPF parsing error !"
+ exit 1
+else
+ echo "All OK"
+ ls -oh oui.txt-* src/oui.h
+fi
diff -uraN netdiscover-0.3-pre-beta7/update-oui-database.sh netdiscover.svn/update-oui-database.sh
--- netdiscover-0.3-pre-beta7/update-oui-database.sh 2015-03-24 05:03:46.000000000 +0100
+++ netdiscover.svn/update-oui-database.sh 2016-05-22 23:54:48.603446048 +0200
@@ -1,120 +1,177 @@
#!/bin/bash
-# Script for generation "oui.h" file (netdiscover program at
-# http://nixgeneration.com/~jaime/netdiscover/
+# update-oui-database-ng.sh
+# This script creates the src/oui.h file needed by netdiscover.
#
-# Obtain data from internet source at:
-# lynx -source http://standards.ieee.org/regauth/oui/oui.txt >oui.txt
+# Copyright 2016 Joao Eriberto Mota Filho <eriberto@debian.org>
+# This file is under GPL-2+ license.
#
-# Syntax: oui.txt2oui.h_netdiscover
+# netdiscover was written by Jaime Penalba Estebanez <jpenalbae@gmail.com>
+# and is available at http://nixgeneration.com/~jaime/netdiscover/
#
-# Script generate src/oui.h file.
-#
-# 16-May-2009 Frantisek Hanzlik <franta@hanzlici.cz> (Original author)
-# 07-Jun-2001 Larry Reznick <lreznick@rezfam.com> (fixes & code clean)
-#**********************************************************************
-#
-# 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 3 of the License, or
-# (at your option) any later version.
-#
-
-JA=${0##*/}
-DATE=$(date +'%Y%m%d')
-ORIGF=oui.txt
-DSTD=src
-DSTF=oui.h
-URL="http://standards.ieee.org/develop/regauth/oui/oui.txt"
-TMPF=$ORIGF-$DATE
-AWK="gawk"
-#AWK="mawk"
-#AWK="awk"
-
-[ -d "$DSTD" ] || { echo "$JA: Destdir \"$DSTD\" not exist!"; exit 1; }
-#if ! [ -f "$TMPF" -a -s "$TMPF" ]; then
-# echo "Trying download \"$ORIGF\" with lynx..."
-# if ! lynx -source $URL >"$TMPF"; then
-# echo "Trying download \"$ORIGF\" with elinks..."
-# if ! elinks -source $URL >"$TMPF"; then
-# echo "Trying download \"$ORIGF\" with wget..."
-# if ! wget --quiet --output-document="$TMPF" $URL; then
-# echo "$JA: Cann't obtain \"$URL\"!"
-# exit 1
-# fi
-# fi
-# fi
-#else
-# echo "\"$TMPF\" already exist, skipping download..."
-#fi
-if ! [ -f "$TMPF" -a -s "$TMPF" ]; then
- echo -n "Trying download \"$ORIGF\" with lynx..."
- if [[ -x /usr/bin/lynx ]]; then
- lynx -source $URL >"$TMPF"
- else
- echo -n " with elinks..."
- if [[ -x /usr/bin/elinks ]]; then
- elinks -source $URL >"$TMPF"
- else
- echo " with wget..."
- if [[ -x /usr/bin/wget ]]; then
- wget --quiet --output-document="$TMPF" $URL
- else
- if [[ -x /usr/bin/curl ]]; then
- curl -s $URL >"$TMPF"
- else
- echo "$JA: Can't obtain \"$URL\"!"
- exit 1
- fi
- fi
- fi
- fi
-else
- echo -n "\"$TMPF\" already exist, skipping download..."
+# License for this script:
+#
+# 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.
+
+VERSION=0.1
+
+# CHANGELOG
+#
+# v0.1, 2016-04-13, Eriberto
+#
+# * Initial release.
+
+
+#####################
+# Initial variables #
+#####################
+
+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
+
+DATE=$(date +%F | tr -d "-")
+DATE2=$(date +%F)
+NAME=oui.txt-$DATE
+OUIFILE=src/oui.h
+
+# Minimum amount of MAC addresses for check.
+# To calculate, use "cat `oui_file` | grep "base 16" | wc -l"
+# Last definition on 2016-04-13.
+MINIMUM_MAC=21900
+
+# The original URL[1] redirects to this URL[2].
+# [1] http://standards.ieee.org/develop/regauth/oui/oui.txt
+# [2] http://standards-oui.ieee.org/oui/oui.txt
+URL=http://standards-oui.ieee.org/oui/oui.txt
+
+
+####################
+# Help and version #
+####################
+
+if [ "$1" = "--help" ]
+then
+ printf "\nupdate-oui-database-ng.sh\n\n"
+ printf "Usage: ./update-oui-database-ng.sh [OPTIONS]\n\n"
+ printf " --help Show this help.\n"
+ printf " --no-download Do not download the oui.txt to use an existent version.\n"
+ printf " --version Show version.\n"
+ exit 0
fi
-echo ""
-echo "Process oui.txt (\"$TMPF\")..."
+if [ "$1" = "--version" ]
+then
+ printf "\nupdate-oui-database-ng.sh\n\n"
+ printf "Version $VERSION\n\n"
+ exit 0
+fi
-# if RS is null string, then records are separated by blank lines...
-# but this isn't true in oui.txt
-LANG=C grep "base 16" $TMPF | sed "s/\"/'/g" | $AWK --re-interval --assign URL="$URL" '
-BEGIN {
- NN = 0;
- printf( \
- "/*\n" \
- " * Organizationally Unique Identifier list at date %s\n" \
- " * Automatically generated from %s\n" \
- " * For Netdiscover by Jaime Penalba\n" \
- " *\n" \
- " */\n" \
- "\n" \
- "struct oui {\n" \
- " char *prefix; /* 24 bit global prefix */\n" \
- " char *vendor; /* Vendor id string */\n" \
- "};\n" \
- "\n" \
- "struct oui oui_table[] = {\n", strftime("%d-%b-%Y"), URL);
-}
-
-{
- printf(" { \"%s\", \"", $1);
- for (i=4; i<NF; i++) printf $i " ";
- printf("%s\" },\n", $NF);
- NN++;
-}
-
-END {
- printf(" { NULL, NULL }\n};\n\n");
- printf("// Total %i items.\n\n", NN);
-}' >"$DSTD/$DSTF"
-
-
-if [ $? -ne 0 ]; then
- echo "$JA: $TMPF parsing error !"
- exit 1
-else
- echo "All OK"
- ls -oh oui.txt-* src/oui.h
+######################
+# Check for dos2unix #
+######################
+
+dos2unix -V > /dev/null 2> /dev/null || { printf "\nYou need dos2unix command to use this script.\n\n"; exit 1; }
+
+
+####################
+# OUI.txt download #
+####################
+
+# Search for downloaders
+
+DOWN=0
+
+if [ "$1" = "--no-download" ]; then DOWN=no; fi
+
+if [ "$DOWN" = "0" ]; then axel -V > /dev/null 2> /dev/null && DOWN="axel -ao $NAME"; fi
+if [ "$DOWN" = "0" ]; then curl -V > /dev/null 2> /dev/null && DOWN="curl -Lo $NAME"; fi
+if [ "$DOWN" = "0" ]; then wget -V > /dev/null 2> /dev/null && DOWN="wget -O $NAME"; fi
+if [ "$DOWN" = "0" ]; then printf "\nYou need axel (faster!), wget or curl to use this script.\n\n" && exit 1; fi
+
+# Download the oui.txt
+
+if [ -f "$NAME" ] && [ "$DOWN" != "no" ]
+then
+ printf "\nThe file $NAME already exists. To run this script, remove $NAME or use --no-download option.\n\n"
+ exit 0
+elif [ ! -f "$NAME" ] && [ "$DOWN" = "no" ]
+then
+ printf "\nThe file $NAME is missing. To download it, does not use --no-download option.\n\n"
+ exit 0
+elif [ "$DOWN" != "no" ]
+then
+ printf "\n\nDownloading oui.txt from $URL\n"
+ printf "Downloader to be used: $(echo $DOWN | cut -d" " -f1)\n\n"
+ $DOWN $URL
fi
+
+# Final check and conversion to Unix
+
+TOTAL_MAC=$(cat $NAME | grep "base 16" | wc -l)
+
+if [ "$TOTAL_MAC" -lt "$MINIMUM_MAC" ]
+then
+ printf "\nThe file $NAME seems to be corrupted. There are $TOTAL_MAC MAC addresses. However, over the $MINIMUM_MAC were expected.\n\n"
+ exit 0
+fi
+
+dos2unix -q $NAME
+
+
+######################
+# Building src/oui.h #
+######################
+
+printf "\n\nBuilding the $OUIFILE.\n"
+
+# The header
+
+cat << EOT > $OUIFILE
+/*
+ * Organizationally Unique Identifier list downloaded on $DATE2
+ * Automatically generated from http://standards.ieee.org/develop/regauth/oui/oui.txt
+ * For Netdiscover by Jaime Penalba
+ *
+ */
+
+struct oui {
+ char *prefix; /* 24 bit global prefix */
+ char *vendor; /* Vendor id string */
+};
+
+struct oui oui_table[] = {
+EOT
+
+# The MACs
+
+cat $NAME | grep "base 16" | tr '\t' ' ' | tr -s " " | sed 's/(base 16) //' | \
+ grep '[0-9A-F]' | sort | sed 's/ /", "/' | sed 's/^/ { "/' | \
+ sed -z 's/\n/" },#/g' | tr '#' '\n' >> $OUIFILE
+
+# Total of MACs
+
+TOTALMAC=$(cat $OUIFILE | egrep "{ .[0-9A-F]" | wc -l)
+
+# The tail
+
+cat << EOT >> $OUIFILE
+ { NULL, NULL }
+};
+
+// Total $TOTALMAC items.
+EOT
+
+printf "Done. $OUIFILE has $TOTALMAC MAC addresses.\n"
+# END