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
17 long atol(const char *);
19 void attach_to_server(int argc, char **argv);
20 void serv_read(char *buf, int bytes);
21 void serv_write(char *buf, int nbytes);
22 void get_config(void);
27 * num_parms() - discover number of parameters...
29 int num_parms(char *source)
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(char *dest, char *source, int parmnum)
49 n = num_parms(source);
56 if ( (parmnum == 0) && (n == 1) ) {
61 while (count++ < parmnum) do {
63 } while( (strlen(buf)>0) && (buf[0]!='|') );
64 if (buf[0]=='|') strcpy(buf,&buf[1]);
65 for (count = 0; count<strlen(buf); ++count)
66 if (buf[count] == '|') buf[count] = 0;
71 * extract_int() - extract an int parm w/o supplying a buffer
73 int extract_int(char *source, int parmnum)
77 extract(buf,source,parmnum);
82 * extract_long() - extract a long parm w/o supplying a buffer
84 long extract_long(char *source, int parmnum)
88 extract(buf,source,parmnum);
100 * receive network spool from the remote system
102 void receive_spool(void) {
106 static char pbuf[IGNET_PACKET_SIZE];
107 char tempfilename[64];
111 sprintf(tempfilename,"/tmp/netpoll.%d",getpid());
115 if (buf[0]!='2') return;
116 download_len = extract_long(&buf[4],0);
119 fp = fopen(tempfilename,"w");
121 perror("cannot open download file locally");
125 while (bytes_received < download_len) {
126 sprintf(buf,"READ %ld|%ld",
128 ( (download_len - bytes_received > IGNET_PACKET_SIZE)
129 ? IGNET_PACKET_SIZE : (download_len - bytes_received) ) );
133 plen = extract_long(&buf[4],0);
134 serv_read(pbuf,plen);
135 fwrite((char *)pbuf,plen,1,fp);
136 bytes_received = bytes_received + plen;
144 sprintf(buf,"mv %s %s/network/spoolin/netpoll.%d",
145 tempfilename,BBSDIR,getpid());
147 system("exec nohup ./netproc >/dev/null 2>&1 &");
151 * transmit network spool to the remote system
153 void transmit_spool(char *remote_nodename)
158 long bytes_to_write, thisblock;
165 if (buf[0]!='2') return;
167 sprintf(sfname,"%s/network/spoolout/%s",BBSDIR,remote_nodename);
168 fd = open(sfname,O_RDONLY);
170 if (errno == ENOENT) {
171 printf("Nothing to send.\n");
174 perror("cannot open upload file locally");
179 while ( plen=(long)read(fd,pbuf,IGNET_PACKET_SIZE), plen>0L) {
180 bytes_to_write = plen;
181 while (bytes_to_write > 0L) {
182 sprintf(buf,"WRIT %ld", bytes_to_write);
185 thisblock = atol(&buf[4]);
187 serv_write(pbuf, (int)thisblock);
188 bytes_to_write = bytes_to_write - thisblock;
201 if (buf[0]=='2') unlink(sfname);
207 void main(int argc, char **argv)
210 char remote_nodename[32];
215 "%s: usage: %s <address> <port number> <remote netpassword>\n",
222 attach_to_server(argc,argv);
225 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
226 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
234 while (serv_gets(buf), strcmp(buf,"000")) {
235 if (a==1) strcpy(remote_nodename,buf);
236 if (a==1) printf("Connected to: %s ",buf);
237 if (a==2) printf("(%s) ",buf);
238 if (a==6) printf("%s\n",buf);
243 if (!strcmp(remote_nodename,config.c_nodename)) {
244 fprintf(stderr,"Connected to local system\n");
247 sprintf(buf,"NETP %s|%s",config.c_nodename,argv[3]);
252 /* only do the transfers if we authenticated correctly! */
255 transmit_spool(remote_nodename);