From 954af9179665457b40453a0417ddf5b3949a0449 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 4 Mar 2007 18:35:36 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r2, which included commits to RCS files with non-trunk default branches. --- seekp.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 seekp.c (limited to 'seekp.c') diff --git a/seekp.c b/seekp.c new file mode 100644 index 0000000..3890d75 --- /dev/null +++ b/seekp.c @@ -0,0 +1,110 @@ +/* + Query remote host for TCP/IP socket +*/ +#include +#include +#include +#include +#include + +#include +#include + +char *name; + +int Connect(); + +main(argc,argv) +int argc; +char *argv[]; + +{ + int f; + + name=argv[0]; + + if (argc<2) + { + fprintf(stderr,"%s: usage %s host\n",name,name); + exit(1); + } + + setbuf(stdout,NULL); + + for(f=0;f<0x10000;f++) + { + if (argc>2) + printf("Trying %s:%d...\n",argv[1],f); + + Connect(argv[1],f); + + if ((argc==2)&&(f)&&((f%10000)==0)) + fprintf(stderr,"Tried up to %s:%d\n",argv[1],f); + } + + return(0); +} + + +char *GetLine() + +{ + static char buff[1024]; + int l; + + if (feof(stdin)) + return(NULL); + + printf("> "); + + if (!gets(buff)) + return(NULL); + + l=strlen(buff); + + if (buff[l-1]=='\n') + buff[l-1]=0; + + if (strlen(buff)) + return(buff); + else + return(GetLine()); +} + + +int Connect(n,p) +char *n; +int p; + +{ + static int init=0; + static struct hostent *remote; + static struct sockaddr_in addr; + int sock; + + if (!init) + { + if (!(remote=gethostbyname(n))) + { + fprintf(stderr,"%s: unknown host %s\n",name,n); + exit(1); + } + + bcopy(remote->h_addr,&addr.sin_addr,remote->h_length); + init=1; + } + + if ((sock=socket(AF_INET,SOCK_STREAM,0))==-1) + { + perror(name); + exit(1); + } + + addr.sin_family=AF_INET; + addr.sin_port=htons(p); + + if (connect(sock,&addr,sizeof(addr))!=-1) + printf("%s:%d\n",n,p); + + close(sock); +} -- cgit v1.2.3