From 9750d3845bd5bbc2e5e76134b8c4a902faa9bce9 Mon Sep 17 00:00:00 2001 From: Epoch Qwert Date: Wed, 24 Dec 2014 07:31:09 -0600 Subject: added IPv6 support to hop0, peerip, and gopherd.sh gopherd.sh got lots of other updates too. speed is for measuring how many lines per second your pipes can do. --- src/bin/speed.c | 21 +++++++++++++++++++++ src/bin/strstr.c | 7 +++++++ src/libexec/peerip.c | 12 ++++++++---- 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/bin/speed.c create mode 100644 src/bin/strstr.c (limited to 'src') 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 +#include + +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 +#include + +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 #include #include +#include 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; -- cgit v1.2.3