summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xnocompile/bin/hop06
-rwxr-xr-xnocompile/libexec/gopherd.sh42
-rw-r--r--src/bin/speed.c21
-rw-r--r--src/bin/strstr.c7
-rw-r--r--src/libexec/peerip.c12
5 files changed, 70 insertions, 18 deletions
diff --git a/nocompile/bin/hop0 b/nocompile/bin/hop0
index 7dc0812..e7c3ff8 100755
--- a/nocompile/bin/hop0
+++ b/nocompile/bin/hop0
@@ -1,6 +1,10 @@
#!/bin/sh
if [ "_$(uname -s)" != "_Linux" ];then
- /sbin/route -n get "$1" | grep "local addr" | cut -d: -f2 | tr -d ' '
+ if echo $1 | grep ":" 2>&1 >/dev/null;then
+ /sbin/route -n get -inet6 "$1" | grep "local addr" | cut -d: -f2- | tr -d ' '
+ else
+ /sbin/route -n get "$1" | grep "local addr" | cut -d: -f2 | tr -d ' '
+ fi
else
/sbin/ip r g "$1" | cut '-d ' -f8
fi
diff --git a/nocompile/libexec/gopherd.sh b/nocompile/libexec/gopherd.sh
index 9d3ba5c..57b3554 100755
--- a/nocompile/libexec/gopherd.sh
+++ b/nocompile/libexec/gopherd.sh
@@ -1,13 +1,14 @@
#!/bin/bash
export PATH=$PATH:/usr/local/bin
-#set these two variables if you have your server behind DMZ
read -t 10 req
base="$1"
-req=$(echo "$req" | tr -d '\r')
-realpath=$(realpath ${base}${req})
+arg=$(echo "$req" | tr -d '\r' | cut -f2)
+req=$(echo "$req" | tr -d '\r' | cut -f1)
+realpath="$(realpath "${base}${req}")"
if grep -v "^${base}" <<< "${realpath}" > /dev/null;then
echo ${base}
echo ${realpath}
+ echo 'error!!! cant find base in realpath'
exit 1
fi
myIP=$(hop0 $(/usr/local/libexec/peerip | head -n1))
@@ -15,28 +16,43 @@ hostname=$(rdns ${myIP})
if [ ! "${hostname}" ]; then
hostname=${myIP}
else
- if [ $(dig +short $hostname) != ${myIP} ];then
- logger "hostname (${hostname}) and IP (${myIP}) aren't matching up. >_>";
- exit 2
+ if strstr "${myIP}" ":";then
+ if [ $(dig -t AAAA +short $hostname) != ${myIP} ];then
+ logger "hostname (${hostname}) and IP (${myIP}) aren't matching up.";
+ exit 2
+ fi
+ else
+ if [ $(dig -t A +short $hostname) != ${myIP} ];then
+ logger "hostname (${hostname}) and IP (${myIP}) aren't matching up.";
+ exit 2
+ fi
fi
fi
+export hostname
+export port=70
type=$(file "${realpath}" | cut -d: -f2-)
-if grep directory <<< "$type" 2>&1 > /dev/null; then
+if strstr "$type" "directory";then
if [ -e "${realpath}/.header" ];then
- cat "${realpath}/.header" | sed "s/^/i&/g" | sed "s/\$/"`printf "\r"`"/g"
+ cat "${realpath}/.header" | while read -r l;do
+ printf "i%s\t%s\t%s\t%s\r\n" "$l" "fake" "(NULL)" "0"
+ done
fi
- for i in $(ls "${realpath}");do
+ ls "${realpath}" | while read i;do
stype=$(file "${realpath}/${i}" | cut -d: -f2-)
- if grep directory <<< "$stype" 2>&1 > /dev/null; then
- printf "1%s\t%s\t%s\t70\r\n" ${req}/${i} ${req}/${i} $hostname
+ if strstr "$stype" "directory"; then
+ printf "1%s\t%s\t%s\t%s\r\n" "${req}/${i}" "${req}/${i}" $hostname $port
else
- printf "0%s\t%s\t%s\t70\r\n" ${req}/${i} ${req}/${i} $hostname
+ if stat "${realpath}/${i}" | cut '-d ' -f3 | grep x >/dev/null;then
+ printf "7%s\t%s\t%s\t%s\r\n" "${req}/${i}" "${req}/${i}" $hostname $port
+ else
+ printf "0%s\t%s\t%s\t%s\r\n" "${req}/${i}" "${req}/${i}" $hostname $port
+ fi
fi
done
printf ".\r\n"
else
if stat "${realpath}" | cut '-d ' -f3 | grep x >/dev/null;then
- "${realpath}"
+ "${realpath}" $arg | sed "s/\$/"`printf "\r"`"/g"
else
cat "${realpath}"
fi
diff --git a/src/bin/speed.c b/src/bin/speed.c
new file mode 100644
index 0000000..3b8cc72
--- /dev/null
+++ b/src/bin/speed.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <signal.h>
+
+int count;
+
+void printandreset(int sig) {
+ alarm(1);
+ printf("persecond: %d\n",count);
+ count=0;
+}
+
+int main(int argc,char *argv[]) {
+ char in[256];
+ count=0;
+ signal(SIGALRM,printandreset);
+ alarm(1);
+ while(fgets(in,256,stdin)) {
+ count++;
+ }
+ return 0;
+}
diff --git a/src/bin/strstr.c b/src/bin/strstr.c
new file mode 100644
index 0000000..9b244ec
--- /dev/null
+++ b/src/bin/strstr.c
@@ -0,0 +1,7 @@
+#include <stdio.h>
+#include <string.h>
+
+int main(int argc,char *argv[]) {
+ if(argc < 3) return printf("usage: strstr big little\n"),2;
+ else return !strstr(argv[1],argv[2]);
+}
diff --git a/src/libexec/peerip.c b/src/libexec/peerip.c
index 9298f87..6bcf1f1 100644
--- a/src/libexec/peerip.c
+++ b/src/libexec/peerip.c
@@ -1,16 +1,20 @@
#include <stdio.h>
#include <sys/socket.h>
#include <netdb.h>
+#include <netinet/in.h>
int main(int argc,char *argv[]) {
int i;
- struct sockaddr sa;
- int sl=sizeof(sa);
+ struct sockaddr_in6 sa6;
+ int err;
+ int sl=sizeof(sa6);
char h[NI_MAXHOST], s[NI_MAXSERV];
- getpeername(0,&sa,&sl);
- if(getnameinfo(&sa,sl,h,sizeof(h),s,sizeof(s),NI_NUMERICHOST|NI_NUMERICSERV)) {
+ if(getpeername(0,(struct sockaddr *)&sa6,&sl) == -1) {
return 1;
}
+ if(err=getnameinfo((struct sockaddr *)&sa6,sl,h,sizeof(h),s,sizeof(s),NI_NUMERICHOST|NI_NUMERICSERV)) {
+ return 2;
+ }
puts(h);
puts(s);
return 0;