From a36652959e52e8c810b7d2d76a283b2ae9718d96 Mon Sep 17 00:00:00 2001 From: epochqwert Date: Thu, 23 Apr 2015 04:53:35 -0500 Subject: elapsedtime handles partial seconds better unescape now handles multiple lines from stdin clump can now have an optional argument to specify input separator cuturl can now take compressed short options. (like: cuturl -dPs) filemon... I don't remember. just reformatted it looks like. ipconvert. looks like I added explainations before output. normalpath now uses getenv("PWD") instead of getcwd() so you can pick what you want to be the base for relative paths. urcdump... nothing I guess. probably a space or something dumb. httpd... more environment variables set for CGIs --- src/bin/clump.c | 8 ++- src/bin/cuturl.c | 95 +++++++++++++++---------------- src/bin/dcchelper.c | 22 -------- src/bin/filemon.c | 155 +++++++++++++++++++++++++++++---------------------- src/bin/ipconvert.c | 6 +- src/bin/normalpath.c | 4 +- src/bin/urcdump.c | 30 ++++++++-- 7 files changed, 170 insertions(+), 150 deletions(-) delete mode 100644 src/bin/dcchelper.c (limited to 'src/bin') diff --git a/src/bin/clump.c b/src/bin/clump.c index 18c8e5b..ec06d17 100644 --- a/src/bin/clump.c +++ b/src/bin/clump.c @@ -8,17 +8,19 @@ //printf "a a\na b\na c\nb a\nb b\nc a\nc b\n" | clump //still working on the name. -int main() { +int main(int argc,char *argv[]) { char line[256]; char *id; + char sep=' '; char *value; char *oldid=malloc(1); *oldid=0; + if(argc > 1) sep=argv[1][0]; while(fgets(line,sizeof(line),stdin)) { id=line; if(strchr(line,'\n')) *strchr(line,'\n')=0; - if(strchr(id,' ')) { - value=strchr(id,' '); + if(strchr(id,sep)) { + value=strchr(id,sep); *value=0; value++; } diff --git a/src/bin/cuturl.c b/src/bin/cuturl.c index d706fd3..40b7766 100644 --- a/src/bin/cuturl.c +++ b/src/bin/cuturl.c @@ -2,9 +2,10 @@ #include #include #include + /* schemes are case sensitive but cononicals are lower case. - domain is case insensitive. return it lowercased. + domain is case insensitive. return it lowercased? port is optional and in decimal path scheme://username:password@domain:port/path?query_string#fragment_id @@ -14,23 +15,6 @@ scheme, username, password, port, path, query_string, fragment_id */ -/* -#define DEFAULT_SCHEME "http" -#define DEFAULT_USERNAME "anonymous" -#define DEFAULT_PASSWORD "anonymous" -#define DEFAULT_PORT "80" -#define DEFAULT_QUERY_STRING "" -#define DEFAULT_FRAGMENT_ID "" - -#define DEFAULT_SCHEME "DEFAULT" -#define DEFAULT_USERNAME "DEFAULT" -#define DEFAULT_PASSWORD "DEFAULT" -#define DEFAULT_PORT "DEFAULT" -#define DEFAULT_PATH "DEFAULT" -#define DEFAULT_QUERY_STRING "DEFAULT" -#define DEFAULT_FRAGMENT_ID "DEFAULT" -*/ - #define AorB(a,b) ((a)?(a):(b)) #define F_SCHEME 1<<0 @@ -46,7 +30,7 @@ char *long_opts[]={"scheme","username","password","domain","port","path","query_ char *short_opts[]={"s","u","k","d","P","p","q","f"}; int main(int argc,char *argv[]) { - char *line; + char *line=0; char *scheme=0; char *username=0; char *password=0; @@ -56,11 +40,11 @@ int main(int argc,char *argv[]) { char *query_string=0; char *fragment_id=0; char sport[10]; + char args[256]; struct servent *serv; - //exactly 8 parts! let's store that in a byte. - unsigned char flags=0; - int i; + int i,j,c=0; int size=1024; + char fixme=0; char using_stdin=1; char malloced=0; if(argc > 1) { @@ -74,6 +58,8 @@ int main(int argc,char *argv[]) { printf("To set default values use environment variables like: CUTURL_[OPTION]\n"); return 2; } + argc--; + argv++; } while(1) { scheme=0; @@ -84,24 +70,33 @@ int main(int argc,char *argv[]) { path=0; query_string=0; fragment_id=0; - if(!using_stdin) flags=0; - if(argc > 1) { - for(argc--,argv++;argc>0;argc--,argv++) { + if(!using_stdin) c=0; + if(argc >= 1) { + for(;argc>0;argc--,argv++) { for(i=0;long_opts[i];i++) { if(!strncmp(*argv,"--",2)) { if(!strcmp(*argv+2,long_opts[i])) { - flags|=(1<s_port)); port=AorB(port,AorB(getenv("CUTURL_PORT"),(serv?sport:"DEFAULT"))); - //port=AorB(port,AorB(getenv("CUTURL_PORT"),"DEFAULT")); - - path=AorB(path,AorB(getenv("CUTURL_PATH"),"DEFAULT")); query_string=AorB(query_string,AorB(getenv("CUTURL_QUERY_STRING"),"DEFAULT")); fragment_id=AorB(fragment_id,AorB(getenv("CUTURL_FRAGMENT_ID"),"DEFAULT")); - if(flags) { - if(flags&F_SCHEME) printf("%s\n",scheme); - if(flags&F_USERNAME) printf("%s\n",username); - if(flags&F_PASSWORD) printf("%s\n",password); - if(flags&F_DOMAIN) printf("%s\n",domain); - if(flags&F_PORT) printf("%s\n",port); - if(flags&F_PATH) printf("%s\n",path); - if(flags&F_QUERY_STRING) printf("%s\n",query_string); - if(flags&F_FRAGMENT_ID) printf("%s\n",fragment_id); + if(c) { + for(i=0;i -#include -#include - -int main(int argc,char *argv[]) { - char *wanip; - if(argc < 2) { - return printf("usage: %s [IP]\n",argv[0]); - } - if(!strncmp(argv[1],"127.",4)) { - wanip="127.0.0.1"; - } - else if(!strncmp(argv[1],"1.",2)) { - wanip="1.41.41.1"; - } - else if(!strncmp(argv[1],"192.168.0.",10)) { - wanip="192.168.0.2"; - } else { - wanip="98.159.69.172"; - } - return printf("%u\n",htonl(inet_addr(wanip))); -} diff --git a/src/bin/filemon.c b/src/bin/filemon.c index 6930673..2f0af24 100644 --- a/src/bin/filemon.c +++ b/src/bin/filemon.c @@ -1,72 +1,93 @@ //ripped from the netbsd man page for kqueue //and modified very slightly. //I'll add some more stuff as I find a use for it. - #include - #include - #include - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include +#include +#include - int - main(int argc, char *argv[]) - { - int fd, kq, nev; - struct kevent ev; - static const struct timespec tout = { 1, 0 }; +int main(int argc, char *argv[]) { + if(argc < 2) { + printf("usage: filemon file [prog]"); + return 1; + } + monitor(argv[1],argv[2]); +} - if ((fd = open(argv[1], O_RDONLY)) == -1) - err(1, "Cannot open `%s'", argv[1]); - - if ((kq = kqueue()) == -1) - err(1, "Cannot create kqueue"); - - EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR, - NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK| - NOTE_RENAME|NOTE_REVOKE, 0, 0); - if (kevent(kq, &ev, 1, NULL, 0, &tout) == -1) - err(1, "kevent"); - for (;;) { - nev = kevent(kq, NULL, 0, &ev, 1, &tout); - if (nev == -1) - err(1, "kevent"); - if (nev == 0) - continue; - if (ev.fflags & (NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|NOTE_RENAME|NOTE_REVOKE)) { - printf("%s: ",argv[1]); - } - if (ev.fflags & NOTE_DELETE) { - printf("deleted "); - ev.fflags &= ~NOTE_DELETE; - } - if (ev.fflags & NOTE_WRITE) { - printf("written "); - ev.fflags &= ~NOTE_WRITE; - } - if (ev.fflags & NOTE_EXTEND) { - printf("extended "); - ev.fflags &= ~NOTE_EXTEND; - } - if (ev.fflags & NOTE_ATTRIB) { - printf("chmod/chown/utimes "); - ev.fflags &= ~NOTE_ATTRIB; - } - if (ev.fflags & NOTE_LINK) { - printf("hardlinked "); - ev.fflags &= ~NOTE_LINK; - } - if (ev.fflags & NOTE_RENAME) { - printf("renamed "); - ev.fflags &= ~NOTE_RENAME; - } - if (ev.fflags & NOTE_REVOKE) { - printf("revoked "); - ev.fflags &= ~NOTE_REVOKE; - } - printf("\n"); - if (ev.fflags) - warnx("unknown event 0x%x\n", ev.fflags); - } - } +int monitor(char *file,char *handler) { + int fd, kq, nev; + struct kevent ev; + struct stat sb; + char buffer[ + static const struct timespec tout = { 1, 0 }; + if ((fd = open(file, O_RDONLY)) == -1) err(1, "Cannot open `%s'", argv[1]); + fstat(fd,&sb); + if(S_ISDIR(sb.st_mode)) { + //read list of files from dir? + //rerun self on all files in that dir. + //system("filemon file/*"); //XD + getdents(fd,,); + } + if ((kq = kqueue()) == -1) err(1, "Cannot create kqueue"); + EV_SET(&ev, + fd, + EVFILT_VNODE, + EV_ADD | EV_ENABLE | EV_CLEAR, + NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|NOTE_RENAME|NOTE_REVOKE, + 0, + 0); + if (kevent(kq, &ev, 1, NULL, 0, &tout) == -1) err(1, "kevent"); + for (;;) { + nev = kevent(kq, NULL, 0, &ev, 1, &tout); + if (nev == -1) err(1, "kevent"); + if (nev == 0) continue; + printf("nev:%x\n",nev);//probably fd that triggered event? + printf("ev.ident:%x\n",ev.ident); + printf("ev.filter:%x\n",ev.filter); + printf("ev.flags:%x\n",ev.flags); + printf("ev.fflags:%x\n",ev.fflags); + printf("ev.data:%x\n",ev.data); + printf("ev.udata:%x\n",ev.udata); + if (ev.fflags & (NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|NOTE_RENAME|NOTE_REVOKE)) { + printf("%s: ",file); + if(argv[2]) system(handler); + } + if (ev.fflags & NOTE_DELETE) { + printf("deleted "); + ev.fflags &= ~NOTE_DELETE; + } + if (ev.fflags & NOTE_WRITE) { + printf("written "); + ev.fflags &= ~NOTE_WRITE; + } + if (ev.fflags & NOTE_EXTEND) { + printf("extended "); + ev.fflags &= ~NOTE_EXTEND; + } + if (ev.fflags & NOTE_ATTRIB) { + printf("chmod/chown/utimes "); + ev.fflags &= ~NOTE_ATTRIB; + } + if (ev.fflags & NOTE_LINK) { + printf("hardlinked "); + ev.fflags &= ~NOTE_LINK; + } + if (ev.fflags & NOTE_RENAME) { + printf("renamed "); + ev.fflags &= ~NOTE_RENAME; + } + if (ev.fflags & NOTE_REVOKE) { + printf("revoked "); + ev.fflags &= ~NOTE_REVOKE; + } + printf("\n"); + if (ev.fflags) { + warnx("unknown event 0x%x\n", ev.fflags); + } + } + return 0; +} diff --git a/src/bin/ipconvert.c b/src/bin/ipconvert.c index d106d13..0390aff 100644 --- a/src/bin/ipconvert.c +++ b/src/bin/ipconvert.c @@ -3,8 +3,8 @@ int main(int argc,char *argv[]) { int addr=inet_addr(argv[1]); - printf("%x\n",htonl(addr)); - printf("%u\n",htonl(addr)); - printf("%u.%u.%u.%u\n",addr&255,addr>>8&255,addr>>16&255,addr>>24&255); + printf("hex: %x\n",htonl(addr)); + printf("dec: %u\n",htonl(addr)); + printf("dotted-quad: %u.%u.%u.%u\n",addr&255,addr>>8&255,addr>>16&255,addr>>24&255); return 0; } diff --git a/src/bin/normalpath.c b/src/bin/normalpath.c index 2ea916f..a80ecda 100644 --- a/src/bin/normalpath.c +++ b/src/bin/normalpath.c @@ -18,7 +18,9 @@ int main(int argc,char *argv[]) { strcpy(out,(char *)getenv("HOME")); break; default: - getcwd(out,MAXPATHLEN); +//old code, but might be what I decide I /really/ want. +// getcwd(out,MAXPATHLEN); + if(getenv("PWD")) strcpy(out,getenv("PWD")); strcat(out,"/"); } strcat(out,s); diff --git a/src/bin/urcdump.c b/src/bin/urcdump.c index 8d19370..0fea8ed 100644 --- a/src/bin/urcdump.c +++ b/src/bin/urcdump.c @@ -7,7 +7,8 @@ int main(int argc,char *argv[]) { int s; struct sockaddr_in name; - char *tmp; + //char *tmp; + int tmp; char chunk[BS]; int off=0; char buf[BS]; @@ -25,15 +26,34 @@ int main(int argc,char *argv[]) { if(connect(s,(struct sockaddr *)&name,len) == -1) return -1; while((len=read(s,buf,BS-1)) > 0) { - memcpy(chunk+off,buf,len); - off+=len; - if(off > 26) { + for(tmp=0;tmp>4&15),1); + write(1,"0123456789abcdef"+((buf[tmp])&15),1); + } + } +/* + while(off > 26) { if((tmp=memchr(chunk+26,'\n',off-26))) { tmp++; - write(1,chunk+26,tmp-chunk-26); +//old write(1,chunk+26,tmp-chunk-26); +//testing: + for(len=26;len>4 & 15),1); + write(1,"0123456789abcdef"+((*chunk+len)&15),1); + } + } memmove(chunk,tmp,tmp-chunk+1); off-=(tmp-chunk); } } + */ } } -- cgit v1.2.3