void main() { int gm,i,count, gd=DETECT,choice=1,width=0; char **buffer; initgraph(&gd,&gm,"c:\\tc\\bgi"); if(initmouse()==0) { printf("\nUnable to intialize Mouse......"); exit(); } count=sizeof(menu)/sizeof(char*); settextstyle(TRIPLEX_FONT,0,3); displaymenu(menu,count,100,100); for(i=0;i<count;i++) { if (textwidth(menu[i])>width) width=textwidth(menu[i]); } buffer=malloc(sizeof(menu)); savemenu(menu,buffer,width,count,100,100); while(choice!=6) { choice=getresponse(menu,buffer,width,count,100,100); gotoxy(50,15); printf("\n\n\nYou have selected %s",menu[choice-1]); } }
static int ftpsendpassive(int ctl, struct sockaddr_in *data_addr, char *buf, int buflen) { char *pt, *start; if ( ftpsend(ctl,"PASV\r\n")==-1 ) return( -1 ); if ( getresponse(ctl,buf,buflen)== -1 ) return( -1 ); start = buf; while ( (pt = strchr(start,'\n' ))!=NULL ) { if ( start[3]==' ' ) break; start = pt+1; } if ( strtol(buf,NULL,10) == 227 ) { /* 227 Entering Passive Mode (h1,h2,h3,h4,p1,p2) */ int h1,h2,h3,h4,p1,p2; for ( pt=buf+4; !isdigit(*pt) && *pt!='\n' ; ++pt ); if ( *pt=='\n' ) return( -2 ); /* can't parse it */ sscanf(pt,"%d,%d,%d,%d,%d,%d", &h1, &h2, &h3, &h4, &p1, &p2 ); data_addr->sin_family = AF_INET; data_addr->sin_port = htons((p1<<8)|p2); data_addr->sin_addr.s_addr = htonl((h1<<24)|(h2<<16)|(h3<<8)|h4); return( 1 ); } else if ( *start=='4' || *start=='5' ) return( 0 ); return( 0 ); /* shouldn't get here */ }
int main(){ char *response; char buf[1024]; int exersocket, getsocket; socklen_t getsocketlen; struct sockaddr_in exer_addr, get_addr; iserror = 0; bzero((char *)&exer_addr,sizeof(exer_addr)); exer_addr.sin_family = AF_INET; exer_addr.sin_port = getexerport(); exer_addr.sin_addr.s_addr = getexerip(); printf("\nexer: to ip: %x port: %d h ip: %x port: %d\n", exer_addr.sin_addr.s_addr, exer_addr.sin_port, getexerip(), getexerport()); exersocket = socket(AF_INET,SOCK_STREAM,0); if (exersocket < 0) { printf("\nexer: fail to create server socket, socketid: %d\n", exersocket); exit(1); } printf("\nexer: succeed to create server socket, socketid: %d\n", exersocket); if (bind(exersocket,(struct sockaddr *)&exer_addr,sizeof(exer_addr)) < 0) { printf("\nexer: fail to bind server socket\n"); exit(1); } printf("\nexer: succeed to bind server socket\n"); if (listen(exersocket, 5) < 0) { printf("\nexer: fail to listen %x : %d\n", exer_addr.sin_addr.s_addr, exer_addr.sin_port); exit(1); } bzero(&get_addr, sizeof(get_addr)); while (1) { if ((getsocket = accept(exersocket, (sockaddr *)&get_addr, &getsocketlen)) < 0) { printf("\nexer: fail to accept\n"); exit(1); } //recv command if (recv(getsocket, buf, 1024, 0) < 0) { printf("\nexer: fail to recv response\n"); exit(1); } printf("\nsayer: %s\n", buf); //do command doonecommand(buf); initbuf(buf); //say back to sayer response = getresponse(); if (send(getsocket, response, strlen(response), 0) < 0) { printf("\nexer: fail to send back\n"); exit(1); } printf("\nexer: succeed to send back: %s\n", response); close(getsocket); } close(exersocket); return 0; }
void getresults1(int recv, int socket_fd, char * response, struct timeval * times){ if(!recv){ puts("timeout"); } else { getresponse(&socket_fd, response); int err = gettimeofday(×[1], NULL); if(err < 0){ perror("Error getting time @getresults()"); exit(1); } printresults1(times); } }
int nast_upd(nasth *s, const char *key, nast_array *valarray) { char buffer[512]; int i; short bufflen, n_bufflen; if (s == NULL) { fprintf(stderr, "ERROR: Can't update: no sphincter.\n"); return -1; } bufflen = sizeof(short); bufflen += add_reqid(buffer+bufflen); snprintf(buffer+bufflen, sizeof(buffer)-bufflen, "%c%c%s%c", NASTCMD, NASTUPD, key, NASTSEP); bufflen += (3 + strlen(key))*sizeof(char); for (i = 0; i < valarray->nitems; i++) { char *str; short slen; str = valarray->items[i]->strdata; slen = valarray->items[i]->strlen; if (bufflen + slen > sizeof(buffer)) { nast_set_error(s, thread_id(), NAST_NOMEM); return -1; } memcpy(buffer+bufflen, str, slen); bufflen += slen; if (i < valarray->nitems - 1) { buffer[bufflen] = NASTSEP; bufflen += sizeof(char); } } n_bufflen = htons(bufflen); memcpy(buffer, &n_bufflen, sizeof(short)); sendcmd(s, buffer, bufflen); return getresponse(s); }
int nast_stats(nasth *s) { char buffer[512]; short bufflen, n_bufflen; if (s == NULL) { fprintf(stderr, "ERROR: Can't get stats: no sphincter.\n"); return -1; } bufflen = sizeof(short); bufflen += add_reqid(buffer+bufflen); snprintf(buffer+bufflen, sizeof(buffer)-bufflen, "%c%c", NASTCMD, NASTSTATS); bufflen += 2 * sizeof(char); n_bufflen = htons(bufflen); memcpy(buffer, &n_bufflen, sizeof(short)); sendcmd(s, buffer, bufflen); return getresponse(s); }
int nast_get(nasth *s, const char *query) { char buffer[512]; short bufflen, n_bufflen; if (s == NULL) { fprintf(stderr, "ERROR: Can't get: no sphincter.\n"); return -1; } bufflen = sizeof(short); bufflen += add_reqid(buffer+bufflen); snprintf(buffer+bufflen, sizeof(buffer)-bufflen, "%c%c%s", NASTCMD, NASTGET, query); bufflen += (2 + strlen(query))*sizeof(char); n_bufflen = htons(bufflen); memcpy(buffer, &n_bufflen, sizeof(short)); sendcmd(s, buffer, bufflen); return getresponse(s); }
/* * doquery - send a request and process the response */ int doquery( int implcode, int reqcode, int auth, int qitems, int qsize, char *qdata, int *ritems, int *rsize, char **rdata, int quiet_mask, int esize ) { int res; char junk[512]; fd_set fds; struct sock_timeval tvzero; /* * Check to make sure host is open */ if (!havehost) { (void) fprintf(stderr, "***No host open, use `host' command\n"); return -1; } /* * Poll the socket and clear out any pending data */ again: do { tvzero.tv_sec = tvzero.tv_usec = 0; FD_ZERO(&fds); FD_SET(sockfd, &fds); res = select(sockfd+1, &fds, (fd_set *)0, (fd_set *)0, &tvzero); if (res == -1) { warning("polling select", "", ""); return -1; } else if (res > 0) (void) recv(sockfd, junk, sizeof junk, 0); } while (res > 0); /* * send a request */ res = sendrequest(implcode, reqcode, auth, qitems, qsize, qdata); if (res != 0) return res; /* * Get the response. If we got a standard error, print a message */ res = getresponse(implcode, reqcode, ritems, rsize, rdata, esize); /* * Try to be compatible with older implementations of ntpd. */ if (res == INFO_ERR_FMT && req_pkt_size != 48) { int oldsize; oldsize = req_pkt_size; switch(req_pkt_size) { case REQ_LEN_NOMAC: req_pkt_size = 160; break; case 160: req_pkt_size = 48; break; } if (impl_ver == IMPL_XNTPD) { fprintf(stderr, "***Warning changing to older implementation\n"); return INFO_ERR_IMPL; } fprintf(stderr, "***Warning changing the request packet size from %d to %d\n", oldsize, req_pkt_size); goto again; } /* log error message if not told to be quiet */ if ((res > 0) && (((1 << res) & quiet_mask) == 0)) { switch(res) { case INFO_ERR_IMPL: /* Give us a chance to try the older implementation. */ if (implcode == IMPL_XNTPD) break; (void) fprintf(stderr, "***Server implementation incompatable with our own\n"); break; case INFO_ERR_REQ: (void) fprintf(stderr, "***Server doesn't implement this request\n"); break; case INFO_ERR_FMT: (void) fprintf(stderr, "***Server reports a format error in the received packet (shouldn't happen)\n"); break; case INFO_ERR_NODATA: (void) fprintf(stderr, "***Server reports data not found\n"); break; case INFO_ERR_AUTH: (void) fprintf(stderr, "***Permission denied\n"); break; case ERR_TIMEOUT: (void) fprintf(stderr, "***Request timed out\n"); break; case ERR_INCOMPLETE: (void) fprintf(stderr, "***Response from server was incomplete\n"); break; default: (void) fprintf(stderr, "***Server returns unknown error code %d\n", res); break; } } return res; }
int nast_options_set(nasth *s, nast_options *opts) { char buffer[512]; short bufflen, n_bufflen; if (s == NULL) { fprintf(stderr, "ERROR: Can't set options: no sphincter.\n"); return -1; } bufflen = sizeof(short); bufflen += add_reqid(buffer+bufflen); snprintf(buffer+bufflen, sizeof(buffer)-bufflen, "%c%c", NASTCMD, NASTOPTSET); bufflen += 2*sizeof(char); buffer[bufflen] = OPTQCACHE; if (opts->use_qcache) buffer[bufflen+1] = OPTTRUE; else buffer[bufflen+1] = OPTFALSE; bufflen += 2; buffer[bufflen] = OPTLOCALDB; if (opts->use_localdb) buffer[bufflen+1] = OPTTRUE; else buffer[bufflen+1] = OPTFALSE; bufflen += 2; buffer[bufflen] = OPTFALLASYNC; if (opts->fallthrough_async) buffer[bufflen+1] = OPTTRUE; else buffer[bufflen+1] = OPTFALSE; bufflen += 2; buffer[bufflen] = OPTALWAYSFALL; if (opts->always_fallthrough) buffer[bufflen+1] = OPTTRUE; else buffer[bufflen+1] = OPTFALSE; bufflen += 2; buffer[bufflen] = OPTFAILONCE; if (opts->fail_once) buffer[bufflen+1] = OPTTRUE; else buffer[bufflen+1] = OPTFALSE; bufflen += 2; buffer[bufflen] = OPTNOFALLTHROUGH; if (opts->no_fallthrough) buffer[bufflen+1] = OPTTRUE; else buffer[bufflen+1] = OPTFALSE; bufflen += 2; n_bufflen = htons(bufflen); memcpy(buffer, &n_bufflen, sizeof(short)); sendcmd(s, buffer, bufflen); return getresponse(s); }
int nast_options_get(nasth *s, nast_options *opts) { nast_array *aa; char buffer[512]; short bufflen, n_bufflen, i; if (s == NULL) { fprintf(stderr, "ERROR: Can't get options: no sphincter.\n"); return -1; } bufflen = sizeof(short); bufflen += add_reqid(buffer+bufflen); snprintf(buffer+bufflen, sizeof(buffer)-bufflen, "%c%c", NASTCMD, NASTOPTGET); bufflen += 2 * sizeof(char); n_bufflen = htons(bufflen); memcpy(buffer, &n_bufflen, sizeof(short)); sendcmd(s, buffer, bufflen); if (getresponse(s) == -1) return -1; /* Copy out results and free them. */ aa = nast_get_result(s); if (aa->nitems != 1) { nast_set_error(s, thread_id(), NAST_UNKNOWN_RESPONSE); return -1; } if (sizeof(buffer) < aa->items[0]->strlen) bufflen = sizeof(buffer); else bufflen = aa->items[0]->strlen; memcpy(buffer, aa->items[0]->strdata, bufflen); nast_free_result(aa); /* Parse return into options. */ for (i = 0; i < bufflen; i+=2) { switch (buffer[i]) { case OPTQCACHE: if (buffer[i+1] == OPTFALSE) opts->use_qcache = NASTFALSE; else opts->use_qcache = NASTTRUE; break; case OPTLOCALDB: if (buffer[i+1] == OPTFALSE) opts->use_localdb = NASTFALSE; else opts->use_localdb = NASTTRUE; break; case OPTFALLASYNC: if (buffer[i+1] == OPTFALSE) opts->fallthrough_async = NASTFALSE; else opts->fallthrough_async = NASTTRUE; break; case OPTALWAYSFALL: if (buffer[i+1] == OPTFALSE) opts->always_fallthrough = NASTFALSE; else opts->always_fallthrough = NASTTRUE; break; case OPTFAILONCE: if (buffer[i+1] == OPTFALSE) opts->fail_once = NASTFALSE; else opts->fail_once = NASTTRUE; break; case OPTNOFALLTHROUGH: if (buffer[i+1] == OPTFALSE) opts->no_fallthrough = NASTFALSE; else opts->no_fallthrough = NASTTRUE; break; default: nast_set_error(s, thread_id(), NAST_UNKNOWN_OPT); return -1; } } return 0; }
main(int argc,char **argv){ char buffer[10000],tmp[1024],*ifile,*ofile,*b,*p; int sck,i,c,arg,flag=-1,fd; struct sockaddr_in adr; struct hostent *hp; FILE *f; struct stat sbuf; printf("copyright LAST STAGE OF DELIRIUM oct 1998 poland //lsd-pl.net/\n"); printf("sdrd for aix 4.1 4.2 PowerPC/POWER\n\n"); if(argc!=5){ printf("usage: %s address -g|-p|-r ifile ofile\n",argv[0]); exit(-1); } while((c=getopt(argc-1,&argv[1],"gpr"))!=-1){ switch(c){ case 'g': flag=1; break; case 'p': flag=2; break; case 'r': flag=3; break; default : exit(-1); } } if(flag==-1) exit(-1); ifile=argv[optind+1]; ofile=argv[optind+2]; sck=socket(AF_INET,SOCK_STREAM,0); adr.sin_family=AF_INET; adr.sin_port=htons(5712); if((adr.sin_addr.s_addr=inet_addr(argv[1]))==-1){ if((hp=gethostbyname(argv[1]))==NULL){ errno=EADDRNOTAVAIL;perror("error");exit(-1); } memcpy(&adr.sin_addr.s_addr,hp->h_addr,4); } if(connect(sck,(struct sockaddr*)&adr,sizeof(struct sockaddr_in))<0){ perror("error");exit(-1); } switch(flag){ case 1: printf("getting %s from %s\n",ifile,argv[1]); sprintf(tmp,"SDRFiles/../../../../../../../../../../../../..%s",ifile); sprintf(buffer,"3 %d %s",strlen(tmp),tmp); write(sck,buffer,strlen(buffer)); if(getresponse(sck,&arg)){ printf("error: no file %s:%s\n",argv[1],ifile);exit(-1); } if((fd=open(ofile,O_RDWR|O_CREAT,0600))<0){ printf("error: create %s\n",ofile);exit(-1); } while(arg){ if((i=read(sck,buffer,arg))<0) {perror("error");exit(-1);} write(fd,buffer,i); arg-=i; } break; case 2: printf("putting %s to %s:%s\n",ifile,argv[1],ofile); goto common; case 3: printf("replace %s:%s with %s\n",argv[1],ofile,ifile); goto common; common: gethostname(tmp,sizeof(tmp)); sprintf(buffer,"8 18 0 %s:%d:1",tmp,getpid()); write(sck,buffer,strlen(buffer)); if(getresponse(sck,&arg)){ printf("error: auth\n");exit(-1); } if((fd=open(ifile,O_RDONLY))<0){ printf("error: open %s\n",ifile);exit(-1); } fstat(fd,&sbuf); sprintf(tmp,"SDRFiles/../../../../../../../../../..%s",ofile); if(!(b=(char*)malloc(strlen(tmp)+sbuf.st_size+32))){ printf("error: memory alloc");exit(-1); } if(flag==3) sprintf(b,"2 %d %s ",strlen(tmp)+sbuf.st_size,tmp); else sprintf(b,"19 %d %s ",strlen(tmp)+sbuf.st_size,tmp); p=b+strlen(b); arg=sbuf.st_size; while(arg){ if((i=read(fd,p,arg))<0) {perror("error");exit(-1);} arg-=i;p+=i; } close(fd); *p=0; write(sck,b,strlen(b)); if(flag==3) while(arg){ if((i=read(sck,buffer,arg))<0) {perror("error");exit(-1);} arg-=i; } if(getresponse(sck,&arg)){ printf("error: create %s:%s\n",argv[1],ofile);exit(-1); } } printf("ok!\n"); close(fd); }
static int FtpURLAndTempFile(const char *url,FILE **to,FILE *from) { struct sockaddr_in addr, data_addr; char *host, *filename, *username, *password; int port; FILE *ret; char buffer[300]; int soc, data; int datalen, len; char *databuf, *cmd; if ( from==NULL ) { snprintf(buffer,sizeof(buffer),_("Downloading from %s"), url); *to = NULL; } else snprintf(buffer,sizeof(buffer),_("Uploading to %s"), url); if ( strncasecmp(url,"ftp://",6)!=0 ) { ff_post_error(_("Could not parse URL"),_("Got something else when expecting an ftp URL")); return( false ); } filename = decomposeURL(url, &host, &port, &username, &password); ff_progress_start_indicator(0,_("Font Download..."),buffer, _("Resolving host"),1,1); ff_progress_enable_stop(false); ff_progress_allow_events(); ff_progress_allow_events(); if ( !findFTPhost(&addr, host, port)) { ff_progress_end_indicator(); ff_post_error(_("Could not find host"),_("Could not find \"%s\"\nAre you connected to the internet?"), host ); free( host ); free( filename ); return( false ); } soc = makeConnection(&addr); if ( soc==-1 ) { ff_progress_end_indicator(); ff_post_error(_("Could not connect to host"),_("Could not connect to \"%s\"."), host ); free( host ); free( filename ); return( false ); } datalen = 8*8*1024; databuf = malloc(datalen+1); cmd = databuf; ChangeLine2_8(_("Logging in...")); if ( getresponse(soc,databuf,datalen) == -1 ) { /* ftp servers say "Hi" when then connect */ ff_progress_end_indicator(); ff_post_error(_("Could not connect to host"),_("Could not connect to \"%s\"."), host ); free( host ); free( filename ); free(username); free(password); close( soc ); return( false ); } free( host ); if ( username==NULL ) { username=copy("anonymous"); if ( password==NULL ) password=copy("FontForge"); } else if ( password==NULL ) password = copy(""); sprintf(cmd,"USER %s\r\n", username); if ( ftpsendr(soc,cmd,databuf,datalen)== -1 ) { ff_progress_end_indicator(); close( soc ); free(filename); free(databuf); free(username); free(password); return( false ); } sprintf(cmd,"PASS %s\r\n", password); free(username); free(password); if ( ftpsendr(soc,cmd,databuf,datalen)<=0 ) { ff_progress_end_indicator(); LogError(_("Bad Username/Password\n")); close( soc ); free(filename); free(databuf); return( false ); } if ( ftpsendr(soc,"TYPE I\r\n",databuf,datalen)==-1 ) { /* Binary */ ff_progress_end_indicator(); close( soc ); free(filename); free(databuf); return( false ); } if ( from==NULL ) ChangeLine2_8(_("Requesting font...")); else ChangeLine2_8(_("Transmitting font...")); if ( ftpsendpassive(soc,&data_addr,databuf,datalen)<= 0 ) { ff_progress_end_indicator(); close( soc ); free(filename); free(databuf); return( false ); } if (( data = socket(PF_INET,SOCK_STREAM,0))==-1 || connect(data,(struct sockaddr *) &data_addr,sizeof(data_addr))== -1 ) { ff_progress_end_indicator(); if ( data!=-1 ) close(data); close( soc ); free(filename); free(databuf); LogError(_("FTP passive Data Connect failed\n")); return( 0 ); } if ( from==NULL ) { sprintf(cmd,"RETR %s\r\n", filename); if ( ftpsendr(soc,cmd, databuf, datalen)<=0 ) { ff_progress_end_indicator(); ff_post_error(_("Could not download data"),_("Could not find file.") ); close(data); close( soc ); free(filename); free(databuf); return( false ); } ChangeLine2_8(_("Downloading font...")); ret = tmpfile(); while ((len = read(data,databuf,datalen))>0 ) { fwrite(databuf,1,len,ret); } *to = ret; rewind(ret); } else { sprintf(cmd,"STOR %s\r\n", filename); if ( ftpsendr(soc,cmd, databuf, datalen)<=0 ) { ff_progress_end_indicator(); ff_post_error(_("Could not download data"),_("Could not find file.") ); close(data); close( soc ); free(filename); free(databuf); return( false ); } ChangeLine2_8(_("Uploading font...")); rewind(from); while ((len = fread(databuf,1,datalen,from))>0 ) { if ( (len = write(data,databuf,len))<0 ) break; } ret = NULL; } ff_progress_end_indicator(); close( soc ); close( data ); free( databuf ); free( filename ); if ( len==-1 ) { ff_post_error(_("Could not transmit data"),_("Could not transmit data.") ); if ( ret!=NULL ) fclose(ret); return( false ); } return( true ); }
static int ftpsendr(int ctl, char *cmd, char *buf, int buflen) { if ( ftpsend(ctl,cmd)==-1 ) return( -1 ); return( getresponse(ctl,buf,buflen)); }