int ftp_port_connect(void) { uint32 host,h1,h2,h3,h4; int16 p1,p2; /* port */ int rc; CIB *cib; char buff[100]; /* get local ip address */ cib = CNgetinfo( fpi ); if (cib!=NULL) { host = cib->lhost; } else { host = stik_cfg->client_ip; } h1 = host>>24 & 0x000000ff; h2 = host>>16 & 0x000000ff; h3 = host>>8 & 0x000000ff; h4 = host & 0x000000ff; p1 = 4; /* can't be zero? */ p2 = FTP_DATA_PORT; sprintf( buff, "PORT %ld,%ld,%ld,%ld,%d,%d", h1, h2, h3, h4, p1, p2 ); /* fprintf( log, "%s\n", buff ); fflush(log); */ rc = news_send_command( fpi, buff ); header[0]='\0'; rc = ftp_receive_continuations( fpi, "dummy", FALSE ); /* if (header[0]!='\0') { fprintf( log, "PORT: %s\n", header ); fflush( log ); } */ /* if (memcmp(header,"200",3)!=0) { return(E_REFUSE); } /* can't open PORT */ rc = TCP_open( 0, FTP_DATA_PORT+1024, 0, FTP_OBUFF_SIZE ); /* open in 'Listen' mode on default port */ /* fprintf( log, "PORT connection: %d\n", rc ); fflush( log ); */ return(rc); }
int ftp_listen_connect(void) { int rc; rc = TCP_open( 0, FTP_DATA_PORT, 0, FTP_OBUFF_SIZE ); /* open in 'Listen' mode on default port */ return(rc); }
int ftp_passive_connect(void) { uint32 host,h1,h2,h3,h4; int16 port,p1,p2; int rc; CIB *cib; char *p; if (pasv_failed) { return(E_REFUSE); } rc = news_send_command( fpi, "PASV" ); header[0]='\0'; rc = ftp_receive_continuations( fpi, "dummy", FALSE ); if (header[0]!='\0') { fprintf( log, "PASV: %s\n", header ); fflush( log ); } if (memcmp(header,"227",3)!=0) { pasv_failed++; return(E_REFUSE); } /* can't open PASV */ if (1) /*(rc==0)*/ { p = strtok( header, "(" ); p = strtok( NULL, "\n" ); sscanf( p, "%ld%*c%ld%*c%ld%*c%ld%*c%d%*c%d", &h1,&h2,&h3,&h4,&p1,&p2 ); /* fprintf( log, "host=%ld,%ld,%ld,%ld port=%d,%d\n", h1,h2,h3,h4,p1,p2 ); */ host = (h1<<24) | (h2<<16) | (h3<<8) | h4; if (host==0) { /* support for cahan's VAX */ cib = CNgetinfo( fpi ); if (cib!=NULL) { host = cib->rhost; } } port = (p1<<8) | p2; /* fprintf( log, "host=%p port=%x\n", host,port ); fflush( log ); */ rc = TCP_open( host, port, 0, FTP_OBUFF_SIZE ); return(rc); } return(E_CONNECTFAIL); }
int16 lprConnect(char* host) { CAB cab; int16 tcpHndl, state; /* remote and local port numbers for lpr connection */ cab.rport = LPR_REM_PORT; cab.lport = LPR_LOC_PORT+(int)(Random() % 10); cab.lhost = 0; if (resolve(host, NULL, &(cab.rhost), 1) < 1) { uiPrintf(uiH, uiPrERR, "unknown remote host"); return 0; } if( (tcpHndl = TCP_open((uint32)&cab, TCP_ACTIVE, 0, tcpBuffSize)) <= 0 ) { uiPrintf(uiH, uiPrERR, "could not open connection"); return 0; } if ( (state = TCP_wait_state(tcpHndl, TESTABLISH, 30)) < 0 ) { uiPrintf(uiH, uiPrERR, "%s", get_err_text(state)); return 0; } return tcpHndl; }
int initiatedccchat(char *usr){ short blah; uint32 cip; char temps2[2048]; blah=findfreedccchat(); if(blah==-1){form_alert(1,"[1][No free chats :(][Oh dear]");return 0;} chan[blah].cn=TCP_open(0L,0,0,2048); cb=CNgetinfo(cn[wn[cwin].cnn].cn); cip=stik_cfg->client_ip; if(cip==0 || cip==0x7F000001)cip=cb->lhost; cb = CNgetinfo(chan[blah].cn); sprintf(temps2,":%s PRIVMSG %s :\001DCC CHAT chat %lu %u\001\r",cn[wn[cwin].cnn].nick,usr,cip,cb->lport); srt(temps2,cn[wn[cwin].cnn].cn); chan[blah].stat=SAWAIT; strcpy(chan[blah].name,usr); chan[blah].win=cwin; return 1; }
int initiatedcc(char *usr,char *ftg){ short temp; struct FILEINFO finf; uint32 length; uint32 cip; char temps2[2048]; if(!strlen(ftg)){form_alert(1,"[1][DCC Error:|Please specify a file][Okay]");return 0;} if(!strlen(usr)){form_alert(1,"[1][DCC Error:|Please specify recipient][Okay]");return 0;} temp=findfreedc(); if(temp==-1){form_alert(1,"[1][DCC Error:|No free channels!][Okay]");return 0;} dcc[temp].dcfh=Fopen(ftg,0); if(dcc[temp].dcfh<0){form_alert(1,"[DCC Error:|Unable to open file][Okay]");return 0;} dcc[temp].cn=TCP_open(0L,0,0,4096); if(dcc[temp].cn<0){form_alert(1,"[1][DCC Error:|Unable to open socket][Okay]");return 0;} dcc[temp].stat=SAWAIT; dcc[temp].dir=DCOUT; Fsetdta(&finf); Fsfirst(ftg,0); length=finf.size; strcpy(dname,ftg); basename(dname); cb=CNgetinfo(cn[wn[cwin].cnn].cn); cip=stik_cfg->client_ip; if(cip==0||cip==0x7F000001) cip=cb->lhost; cb=CNgetinfo(dcc[temp].cn); sprintf(temps2,":%s PRIVMSG %s :\001DCC SEND %s %lu %u %lu\001\n",cn[wn[cwin].cnn].nick,usr,dname,cip,cb->lport,length); TCP_send(cn[wn[cwin].cnn].cn,(char *)&temps2,(int16)strlen(temps2)); dcc[temp].rport=cb->lport; dcc[temp].rip=cip; strcpy(dcc[temp].fname,dname); dcc[temp].len=length; strcpy(dcc[temp].avec,usr); if(!conf.boldnicks) sprintf(temps2,"--Initiating DCC send to %s: %s",usr,dname); else sprintf(temps2,"--Initiating DCC send to %s: %s",usr,dname); sendout(temps2,cwin,col[CDCCINFO]); if(conf.autodcd)opendccsenddialog(temp,dname); return 0; }
void test01(WORD testNo, char *testName, BYTE tcpNotUdp, DWORD *blockSizes, WORD blockSizesCount) { DWORD start = getTicks(); //---------- out_test_header(testNo, testName); // show test header //---------- // find out the largest block size int i; int maxBlockSize = 0; for(i=0; i<blockSizesCount; i++) { if(maxBlockSize < (int)blockSizes[i]) { // if current max block size is smaller than this block size, store it maxBlockSize = blockSizes[i]; } } //---------- // open socket int handle; if(tcpNotUdp) { handle = TCP_open(SERVER_ADDR, SERVER_PORT_START, 0, maxBlockSize); } else { handle = UDP_open(SERVER_ADDR, SERVER_PORT_START + 4); } if(handle < 0) { out_result_string(0, "TCP/UDP open() failed"); return; } //---------- // if TCP (not UDP), wait for connected state if(tcpNotUdp) { // wait until connected int res; while(1) { res = TCP_wait_state(handle, TESTABLISH, 1); if(res == E_NORMAL) { break; } DWORD now = getTicks(); if((now - start) > 5*200) { out_result_string(0, "TCP_wait_state() timeout"); goto test01close; } } if(res != E_NORMAL) { out_result_error_string(0, res, "TCP_wait_state() failed"); goto test01close; } } //--------------------- int res; for(i=0; i<blockSizesCount; i++) { res = sendAndReceive(tcpNotUdp, blockSizes[i], handle, 1); if(!res) { // if single block-send-and-receive operation failed, quit and close goto test01close; } } //--------------------- out_result(1); // success! test01close: if(tcpNotUdp) { res = TCP_close(handle, 0, 0); // close } else { res = UDP_close(handle); // close } if(res != E_NORMAL) { out_result_error_string(0, res, "TCP/UDP close() failed"); } }
static void waitRequests(void) { int16 cnId, state; int16 nInQueue; int toggle, proceed=1; do { /* listen again */ if( (cnId = TCP_open(0, LPR_LOC_PORT, 0, tcpBuffSize)) <= 0 ) { uiPrintf(uiH, uiPrERR, "waitRequests|TCP_open"); return; } if ( (state = TCP_wait_state(cnId, TLISTEN, 30)) < 0 ) { uiPrintf(uiH, uiPrERR, "waitRequests|%s", get_err_text(state)); return; } toggle = 10; /* every ten waits look also for an AES message */ while ( (nInQueue = CNbyte_count(cnId)) != E_EOF ) { /* poll for input */ /* listening or no data yet cause us to wait */ if (nInQueue == E_LISTEN || nInQueue == 0 || nInQueue == E_NODATA) { if (--toggle>0) { uiYield(uiH, YIELDMS); } else { WORD msgbuff[8]; WORD event; /* Ergebnis mit Ereignissen */ WORD mx, my, /* Mauskoordinaten */ mbutton, /* Mausknopf */ mkstate, /* keyb shift status for mouse button */ mclicks; /* Anzahl Mausklicks */ UWORD keycode; /* scancode + asciicode */ toggle=10; event = evnt_multi( MU_MESAG | MU_TIMER, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, msgbuff, YIELDMS, 0, &mx, &my, &mbutton, &mkstate, &keycode, &mclicks); if ( (event & MU_MESAG) && msgbuff[0] == AP_TERM ) { proceed=0; /* no more new connections */ break; /* end listening */ } } } else { if (nInQueue > 0) { /* otherwise there is valid data */ NDB* ndb; if ( (ndb = CNget_NDB(cnId)) != NULL ) { dispatchD(cnId, ndb); } else { uiPrintf(uiH, uiPrERR, "waitRequests|get_NDB"); break; } } else { /* catch other errors */ uiPrintf(uiH, uiPrERR, "waitRequests|%s", get_err_text(nInQueue)); break; } /* if valid data */ } /* if any data */ } /* while wait for a request */ TCP_close(cnId, TIMEOUT, NULL); /* disconnect */ } while (proceed); /* while new connection shall be done */ } /* waitRequests */