diff options
author | epochqwert <epoch@hacking.allowed.org> | 2015-04-23 04:53:35 -0500 |
---|---|---|
committer | epochqwert <epoch@hacking.allowed.org> | 2015-04-23 04:53:35 -0500 |
commit | a36652959e52e8c810b7d2d76a283b2ae9718d96 (patch) | |
tree | a8c9712f7eb243d72bfdb492c0c14e630e78a03d /src/bin | |
parent | 318b3220d191011bb9132efd4dbd5e6fb467b4e7 (diff) | |
download | misc-a36652959e52e8c810b7d2d76a283b2ae9718d96.tar.gz misc-a36652959e52e8c810b7d2d76a283b2ae9718d96.zip |
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
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/clump.c | 8 | ||||
-rw-r--r-- | src/bin/cuturl.c | 95 | ||||
-rw-r--r-- | src/bin/dcchelper.c | 22 | ||||
-rw-r--r-- | src/bin/filemon.c | 155 | ||||
-rw-r--r-- | src/bin/ipconvert.c | 6 | ||||
-rw-r--r-- | src/bin/normalpath.c | 4 | ||||
-rw-r--r-- | src/bin/urcdump.c | 30 |
7 files changed, 170 insertions, 150 deletions
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 <stdio.h> #include <string.h> #include <stdlib.h> + /* 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<<i); + args[c]=1<<i; + c++; break; } } - else if(**argv=='-') { - if(*(*argv+1)==*short_opts[i]) { - flags|=(1<<i); - break; + } + fixme=0; + if(**argv=='-' && argv[0][1] != '-') { + for(j=1;argv[0][j];j++) { + for(i=0;short_opts[i];i++) { + if(argv[0][j]==*short_opts[i]) { + args[c]=1<<i; + c++; + fixme=1; + } } } } + if(fixme) continue; if(long_opts[i]) continue; + //if we get here we are at data instead of flags. work on it. line=*argv; using_stdin=0; argc--; @@ -109,6 +104,9 @@ int main(int argc,char *argv[]) { break; } } + if(!argc && !line) {//if we are out of arguments and it didn't include data + using_stdin=1; + } if(using_stdin) { line=malloc(size+1); malloced=1; @@ -120,6 +118,9 @@ int main(int argc,char *argv[]) { for(i=0;line[i] && line[i] != '\n' && line[i] != '\r';i++); line[i]=0; +/// end of interface logic +/// beginning of business logic + //split at first single / into line and path for(i=0;line[i];i++) { if(line[i] == '/' && line[i+1] == '/') { @@ -198,7 +199,7 @@ int main(int argc,char *argv[]) { } } - if(domain) { + if(domain) {//for magnet links. if(strchr(domain,'?')) { query_string=strchr(domain,'?'); *query_string=0; @@ -218,11 +219,7 @@ int main(int argc,char *argv[]) { password=0; } -// before deciding to also handle magnets -// if(!domain) { -// fprintf(stderr,"how the fuck is this supposed to be a URL?\n"); -// return 1; -// } +/// end of business logic // printf("scheme://username:password@domain:port/path?query_string#fragment_id\n\n"); //let's set them to what'll get printed now... @@ -234,22 +231,21 @@ int main(int argc,char *argv[]) { serv=getservbyname(scheme,strcmp(scheme,"udp")?"tcp":"udp"); if(serv) snprintf(sport,sizeof(sport)-1,"%d",ntohs(serv->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<c;i++) { + if(args[i]&F_SCHEME) printf("%s\n",scheme); + if(args[i]&F_USERNAME) printf("%s\n",username); + if(args[i]&F_PASSWORD) printf("%s\n",password); + if(args[i]&F_DOMAIN) printf("%s\n",domain); + if(args[i]&F_PORT) printf("%s\n",port); + if(args[i]&F_PATH) printf("%s\n",path); + if(args[i]&F_QUERY_STRING) printf("%s\n",query_string); + if(args[i]&F_FRAGMENT_ID) printf("%s\n",fragment_id); + } } else { printf("scheme: %s\n",scheme); printf("username: %s\n",username); @@ -263,8 +259,9 @@ int main(int argc,char *argv[]) { if(malloced) { free(line); malloced=0; - } else { line=0; + } else { + line=0;//??? } } return 0; diff --git a/src/bin/dcchelper.c b/src/bin/dcchelper.c deleted file mode 100644 index 50009aa..0000000 --- a/src/bin/dcchelper.c +++ /dev/null @@ -1,22 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <arpa/inet.h> - -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 <sys/types.h> - #include <sys/event.h> - #include <sys/time.h> - #include <stdio.h> - #include <unistd.h> - #include <stdlib.h> - #include <fcntl.h> - #include <err.h> +#include <sys/types.h> +#include <sys/event.h> +#include <sys/time.h> +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <fcntl.h> +#include <err.h> - 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<len;tmp++) { + if(isprint(*(buf+tmp))) { + write(1,(buf+tmp),1); + } else { + write(1,"%",1); + write(1,"0123456789abcdef"+((buf[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<tmp-chunk-1;len++) { + if(isprint(*(chunk+len))) { + write(1,(chunk+len),1); + } else { + write(1,"%",1); + write(1,"0123456789abcdef"+((*chunk+len)>>4 & 15),1); + write(1,"0123456789abcdef"+((*chunk+len)&15),1); + } + } memmove(chunk,tmp,tmp-chunk+1); off-=(tmp-chunk); } } + */ } } |