10 * This variable defines the amount of network spool data that may be carried
11 * in one server transfer command. For some reason, some networks get hung
12 * up on larger packet sizes. We don't know why. In any case, never set the
13 * packet size higher than 4096 or your server sessions will crash.
15 #define IGNET_PACKET_SIZE 64
19 void attach_to_server();
27 * num_parms() - discover number of parameters...
34 for (a=0; a<strlen(source); ++a)
35 if (source[a]=='|') ++count;
41 * extract() - extract a parameter from a series of "|" separated...
43 void extract(dest,source,parmnum)
51 n = num_parms(source);
58 if ( (parmnum == 0) && (n == 1) ) {
63 while (count++ < parmnum) do {
65 } while( (strlen(buf)>0) && (buf[0]!='|') );
66 if (buf[0]=='|') strcpy(buf,&buf[1]);
67 for (count = 0; count<strlen(buf); ++count)
68 if (buf[count] == '|') buf[count] = 0;
73 * extract_int() - extract an int parm w/o supplying a buffer
75 int extract_int(source,parmnum)
80 extract(buf,source,parmnum);
85 * extract_long() - extract a long parm w/o supplying a buffer
87 long extract_long(source,parmnum)
92 extract(buf,source,parmnum);
104 * receive network spool from the remote system
106 void receive_spool() {
110 static char pbuf[IGNET_PACKET_SIZE];
111 char tempfilename[64];
115 sprintf(tempfilename,"/tmp/netpoll.%d",getpid());
119 if (buf[0]!='2') return;
120 download_len = extract_long(&buf[4],0);
123 fp = fopen(tempfilename,"w");
125 perror("cannot open download file locally");
129 while (bytes_received < download_len) {
130 sprintf(buf,"READ %ld|%ld",
132 ( (download_len - bytes_received > IGNET_PACKET_SIZE)
133 ? IGNET_PACKET_SIZE : (download_len - bytes_received) ) );
137 plen = extract_long(&buf[4],0);
138 serv_read(pbuf,plen);
139 fwrite((char *)pbuf,plen,1,fp);
140 bytes_received = bytes_received + plen;
148 sprintf(buf,"mv %s %s/network/spoolin/netpoll.%d",
149 tempfilename,BBSDIR,getpid());
151 system("exec nohup ./netproc >/dev/null 2>&1 &");
155 * transmit network spool to the remote system
157 void transmit_spool(remote_nodename)
158 char *remote_nodename; {
162 long bytes_to_write, thisblock;
169 if (buf[0]!='2') return;
171 sprintf(sfname,"%s/network/spoolout/%s",BBSDIR,remote_nodename);
172 fd = open(sfname,O_RDONLY);
174 if (errno == ENOENT) {
175 printf("Nothing to send.\n");
178 perror("cannot open upload file locally");
183 while ( plen=(long)read(fd,pbuf,IGNET_PACKET_SIZE), plen>0L) {
184 bytes_to_write = plen;
185 while (bytes_to_write > 0L) {
186 sprintf(buf,"WRIT %ld", bytes_to_write);
189 thisblock = atol(&buf[4]);
191 serv_write(pbuf, (int)thisblock);
192 bytes_to_write = bytes_to_write - thisblock;
205 if (buf[0]=='2') unlink(sfname);
215 char remote_nodename[32];
220 "%s: usage: %s <address> <port number> <remote netpassword>\n",
227 attach_to_server(argc,argv);
230 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
231 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
239 while (serv_gets(buf), strcmp(buf,"000")) {
240 if (a==1) strcpy(remote_nodename,buf);
241 if (a==1) printf("Connected to: %s ",buf);
242 if (a==2) printf("(%s) ",buf);
243 if (a==6) printf("%s\n",buf);
248 if (!strcmp(remote_nodename,config.c_nodename)) {
249 fprintf(stderr,"Connected to local system\n");
252 sprintf(buf,"NETP %s|%s",config.c_nodename,argv[3]);
257 /* only do the transfers if we authenticated correctly! */
260 transmit_spool(remote_nodename);