📄 sktdbg.c
字号:
/* begin PortMaster firewall re-initialize */pmskt= Sopen_clientport(buf,"PMClient",PORTMASTER);if(!pmskt) { freeSocket(pmskt); return; }/* send a PM_FWINIT */for(trycnt= 0; trycnt < PM_MAXTRY; ++trycnt) { /* this is where the PM_FWINIT gets sent */ mesg= htons(PM_FWINIT); Swrite(pmskt,(char *) &mesg,sizeof(mesg)); /* wait for PortMaster to respond with PM_OK (I hope) */ if(Stimeoutwait(pmskt,20L,0L) < 0) { Sclose(pmskt); return; } /* read PortMaster response */ Sread(pmskt,(char *) &mesg,sizeof(mesg)); mesg= ntohs(mesg); if(mesg != PM_RESEND) break; }if(mesg == PM_OK) printf("PortMaster firewall re-initialized\n");else printf("PortMaster isn't handling firewalls\n");}/* ------------------------------------------------------------------------- *//* Tfput: puts the entire contents of a file, line by line, across a Socket */#ifdef __PROTOTYPE__void Tfput(char *buf)#else /* __PROTOTYPE__ */void Tfput(buf)char *buf;#endif /* __PROTOTYPE__ */{char *b;char locbuf[BUFSIZE];FILE *fp;srmtrblk(buf);b = stpblk(buf);if(*b && skt) { fp= fopen(b,"r"); if(!fp) { error(XTDIO_WARNING,"unable to open file<%s>\n",sprt(b)); return; } while(fgets(locbuf,BUFSIZE,fp)) { srmtrblk(locbuf); Sputs(locbuf,skt); printf(" %sSputs%s(locbuf<%s>,skt<%s>)\n", YELLOW, GREEN, sprt(locbuf), Sprtskt(skt)); } fclose(fp); }}/* --------------------------------------------------------------------- *//* Tgets: this function does a Sread */#ifdef __PROTOTYPE__void Tgets(char *buf)#else /* __PROTOTYPE__ */void Tgets(buf)char *buf;#endif /* __PROTOTYPE__ */{char locbuf[BUFSIZE];/* only wait up to TIMEOUT seconds */if(Stimeoutwait(skt,TIMEOUT,0L) <= 0) { error(XTDIO_WARNING,"get timed out (waited %ld seconds)\n",TIMEOUT); return; }(void *) Sgets(locbuf,BUFSIZE,skt);printf(" %sSgets%s: skt<%s> locbuf<%s>\n", YELLOW,GREEN,Sprtskt(skt),sprt(locbuf));}/* ------------------------------------------------------------------------- *//* Tputs: this function does a Swrite */#ifdef __PROTOTYPE__void Tputs(char *buf)#else /* __PROTOTYPE__ */void Tputs(buf)char *buf;#endif /* __PROTOTYPE__ */{Sputs(buf,skt);printf(" %sSputs%s(buf<%s>,skt<%s>)\n",YELLOW,GREEN,sprt(buf),Sprtskt(skt));}/* ------------------------------------------------------------------------- *//* Tshut: this function shuts down the PortMaster */#ifdef __PROTOTYPE__void Tshut(char *buf)#else /* __PROTOTYPE__ */void Tshut(buf)char *buf;#endif /* __PROTOTYPE__ */{int trycnt;Socket *pmskt;SKTEVENT mesg;/* shut down client/accept socket */printf(" %sSclose%s(skt<%s>)",YELLOW,GREEN,Sprtskt(skt));Sclose(skt); skt= NULL;/* if server, shut down server socket */if(server) { printf(" %sSclose%s(server<%s>)",YELLOW,GREEN,Sprtskt(server)); Sclose(server); server= NULL; }/* begin PortMaster shutdown sequence */pmskt= Sopen_clientport(buf,"PMClient",PORTMASTER);if(!pmskt) { freeSocket(pmskt); return; }/* send a QUIT */for(trycnt= 0; trycnt < PM_MAXTRY; ++trycnt) { mesg= htons(PM_QUIT); Swrite(pmskt,(char *) &mesg,sizeof(mesg)); if(Stimeoutwait(pmskt,20L,0L) < 0) { Sclose(pmskt); return; } Sread(pmskt,(char *) &mesg,sizeof(mesg)); mesg= ntohs(mesg); if(mesg == PM_OK) break; }/* finish up termination sequence */Sputs("PortMaster",pmskt);Sclose(pmskt);printf(" %sclosed down%s PortMaster\n",YELLOW,GREEN);/* ok, exit the program */#ifdef vmsexit(1);#elseexit(0);#endif}/* ------------------------------------------------------------------------- *//* Tquit: this function quits */#ifdef __PROTOTYPE__void Tquit(char *buf)#else /* __PROTOTYPE__ */void Tquit(buf)char *buf;#endif /* __PROTOTYPE__ */{if(skt) { printf(" %sSclose%s(skt<%s>)\n",YELLOW,GREEN,Sprtskt(skt)); Sclose(skt); }if(server) { printf(" %sSclose%s(server<%s>)\n",YELLOW,GREEN,Sprtskt(server)); Sclose(server); }#ifdef vmsexit(1);#elseexit(0);#endif}/* ------------------------------------------------------------------------- *//* Tread: this function does a Sread */#ifdef __PROTOTYPE__void Tread(char *buf)#else /* __PROTOTYPE__ */void Tread(buf)char *buf;#endif /* __PROTOTYPE__ */{char locbuf[BUFSIZE];int buflen;int ibuf;buflen= Sread(skt,locbuf,BUFSIZE);printf(" %sSread%s: skt<%s> locbuf<",YELLOW,GREEN,Sprtskt(skt));for(ibuf=0; ibuf < buflen; ++ibuf) printf("%s ",cprt(locbuf[ibuf]));printf("> buflen=%d\n",buflen);}/* ------------------------------------------------------------------------- *//* Twrite: this function does a Swrite */#ifdef __PROTOTYPE__void Twrite(char *buf)#else /* __PROTOTYPE__ */void Twrite(buf)char *buf;#endif /* __PROTOTYPE__ */{int buflen;buflen= Swrite(skt,buf,strlen(buf)+1);printf(" %sSwrite%s: skt<%s> buf<%s> buflen=%d\n", YELLOW,GREEN,Sprtskt(skt),sprt(buf),buflen);}/* ------------------------------------------------------------------------- *//* Twait: this function does a Swait */#ifdef __PROTOTYPE__void Twait(char *buf)#else /* __PROTOTYPE__ */void Twait(buf)char *buf;#endif /* __PROTOTYPE__ */{int buflen;buflen= Swait(skt);printf(" %sSwait%s: skt<%s> buflen=%d\n",YELLOW,GREEN,Sprtskt(skt),buflen);}/* ------------------------------------------------------------------------- *//* Tscanf: this function tests Sscanf with "%s %d %lf %s" */#ifdef __PROTOTYPE__void Tscanf(char *buf)#else /* __PROTOTYPE__ */void Tscanf(buf)char *buf;#endif /* __PROTOTYPE__ */{char *b;char buf1[BUFSIZE];char buf2[BUFSIZE];int i;int nbytes;double d;for(b= strchr(buf,'%'); b; b= strchr(b+1,'%')) { /* only wait up to TIMEOUT seconds */ if(Stimeoutwait(skt,TIMEOUT,0L) <= 0) { error(XTDIO_WARNING,"scanf timed out (waited %ld seconds)\n",TIMEOUT); return; } /* skip over 'l' and 'h' modifier */ if (b[1] == 'l') ++b; else if(b[1] == 'h') ++b; /* process data on Socket */ switch(b[1]) { case 'c': Sscanf(skt,"%c",buf1); printf(" %sSscanf%s with %%c: rcvd<%s%c%s>\n", YELLOW,CYAN, GREEN,buf1[0],CYAN); break; case 'd': Sscanf(skt,"%d",&i); printf(" %sSscanf%s with %%d: rcvd<%s%d%s>\n", YELLOW,CYAN, GREEN,i,CYAN); break; case 'f': Sscanf(skt,"%lf",&d); printf(" %sSscanf%s with %%lf: rcvd<%s%f%s>\n", YELLOW,CYAN, GREEN,d,CYAN); break; case 's': Sscanf(skt,"%s",buf1); printf(" %sSscanf%s with %%s: rcvd<%s%s%s>\n", YELLOW,CYAN, GREEN,sprt(buf1),CYAN); break; default: error(XTDIO_WARNING,"sktdbg doesn't support format code <%s>\n",sprt(b)); break; } }}/* ------------------------------------------------------------------------- *//* Tprintf: this function tests Sprintf with "%s %d %s" */#ifdef __PROTOTYPE__void Tprintf(char *buf)#else /* __PROTOTYPE__ */void Tprintf(buf)char *buf;#endif /* __PROTOTYPE__ */{int i=7;double d=8.;Sprintf(skt,"%s %d %f itworked!",buf,i,d);printf(" %sSprintf%s: skt<%s> i=%d d=%f itworked!\n", YELLOW,GREEN,Sprtskt(skt),i,d);}/* ------------------------------------------------------------------------- *//* Ttable: this function queries the PortMaster for a table, and then * prints it out */#ifdef __PROTOTYPE__void Ttable(char *buf)#else /* __PROTOTYPE__ */void Ttable(buf)char *buf;#endif /* __PROTOTYPE__ */{int trycnt;Socket *pmskt;SKTEVENT mesg;SKTEVENT cnt;pmskt= Sopen_clientport(buf,"PMClient",PORTMASTER);if(!pmskt) { freeSocket(pmskt); return; }/* send a PM_TABLE request */for(trycnt= 0; trycnt < PM_MAXTRY; ++trycnt) { mesg= PM_TABLE; mesg= htons(mesg); Swrite(pmskt,(char *) &mesg,sizeof(mesg)); Sread(pmskt,(char *) &mesg,sizeof(mesg)); mesg= ntohs(mesg); if(mesg == PM_OK) break; }/* find out how many entries in table there are */Sread(pmskt,(char *) &cnt,sizeof(cnt));cnt= ntohs(cnt);/* begin to receive table */for(; cnt > 0; --cnt) { Sgets(buf,BUFSIZE,pmskt); printf("%2d: %s\n",cnt,buf); }/* close socket to PortMaster */Sclose(pmskt);}/* ------------------------------------------------------------------------- *//* Trmsrvr: this function removes a server from the PortMaster's PortTable */#ifdef __PROTOTYPE__void Trmsrvr(char *buf)#else /* __PROTOTYPE__ */void Trmsrvr(buf)char *buf;#endif /* __PROTOTYPE__ */{SKTEVENT mesg;mesg= Srmsrvr(buf);printf(" %sSrmsrvr%s: buf<%s> mesg=%s\n", YELLOW,GREEN,sprt(buf),(mesg == PM_OK)? "success" : "failure");}/* ------------------------------------------------------------------------- *//* Tisset: this function tests if Smaskisset works: * it does so by using Smaskwait() with zero timeout * and then invokves Smaskisset() to test the * Socket. This function is primarily intended to * debug & test the Smaskisset() function. */#ifdef __PROTOTYPE__void Tisset(char *buf)#elsevoid Tisset(buf)char *buf;#endif{int ret;Smasktime(0L,1L);Smaskset(skt);Smaskwait();ret= Smaskisset(skt);printf(" %ssocket %s%s%s read-ready\n", GREEN, YELLOW, ret? "is" : "is not", GREEN);}/* --------------------------------------------------------------------- */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -