11 * This variable defines the amount of network spool data that may be carried
12 * in one server transfer command. For some reason, some networks get hung
13 * up on larger packet sizes. We don't know why. In any case, never set the
14 * packet size higher than 4096 or your server sessions will crash.
16 #define IGNET_PACKET_SIZE 64
18 long atol(const char *);
20 void attach_to_server(int argc, char **argv);
21 void serv_read(char *buf, int bytes);
22 void serv_write(char *buf, int nbytes);
23 void get_config(void);
28 * num_parms() - discover number of parameters...
30 int num_parms(char *source)
35 for (a=0; a<strlen(source); ++a)
36 if (source[a]=='|') ++count;
42 * extract() - extract a parameter from a series of "|" separated...
44 void extract(char *dest, char *source, int parmnum)
50 n = num_parms(source);
57 if ( (parmnum == 0) && (n == 1) ) {
62 while (count++ < parmnum) do {
64 } while( (strlen(buf)>0) && (buf[0]!='|') );
65 if (buf[0]=='|') strcpy(buf,&buf[1]);
66 for (count = 0; count<strlen(buf); ++count)
67 if (buf[count] == '|') buf[count] = 0;
72 * extract_int() - extract an int parm w/o supplying a buffer
74 int extract_int(char *source, int parmnum)
78 extract(buf,source,parmnum);
83 * extract_long() - extract a long parm w/o supplying a buffer
85 long extract_long(char *source, int parmnum)
89 extract(buf,source,parmnum);
101 * receive network spool from the remote system
103 void receive_spool(void) {
107 static char pbuf[IGNET_PACKET_SIZE];
108 char tempfilename[64];
112 sprintf(tempfilename,"/tmp/netpoll.%d",getpid());
116 if (buf[0]!='2') return;
117 download_len = extract_long(&buf[4],0);
120 fp = fopen(tempfilename,"w");
122 perror("cannot open download file locally");
126 while (bytes_received < download_len) {
127 sprintf(buf,"READ %ld|%ld",
129 ( (download_len - bytes_received > IGNET_PACKET_SIZE)
130 ? IGNET_PACKET_SIZE : (download_len - bytes_received) ) );
134 plen = extract_long(&buf[4],0);
135 serv_read(pbuf,plen);
136 fwrite((char *)pbuf,plen,1,fp);
137 bytes_received = bytes_received + plen;
145 sprintf(buf,"mv %s %s/network/spoolin/netpoll.%d",
146 tempfilename,BBSDIR,getpid());
148 system("exec nohup ./netproc >/dev/null 2>&1 &");
152 * transmit network spool to the remote system
154 void transmit_spool(char *remote_nodename)
159 long bytes_to_write, thisblock;
166 if (buf[0]!='2') return;
168 sprintf(sfname,"%s/network/spoolout/%s",BBSDIR,remote_nodename);
169 fd = open(sfname,O_RDONLY);
171 if (errno == ENOENT) {
172 printf("Nothing to send.\n");
175 perror("cannot open upload file locally");
180 while ( plen=(long)read(fd,pbuf,IGNET_PACKET_SIZE), plen>0L) {
181 bytes_to_write = plen;
182 while (bytes_to_write > 0L) {
183 sprintf(buf,"WRIT %ld", bytes_to_write);
186 thisblock = atol(&buf[4]);
188 serv_write(pbuf, (int)thisblock);
189 bytes_to_write = bytes_to_write - thisblock;
202 if (buf[0]=='2') unlink(sfname);
208 int main(int argc, char **argv)
211 char remote_nodename[32];
216 "%s: usage: %s <address> <port number> <remote netpassword>\n",
223 attach_to_server(argc,argv);
226 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
227 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
235 while (serv_gets(buf), strcmp(buf,"000")) {
236 if (a==1) strcpy(remote_nodename,buf);
237 if (a==1) printf("Connected to: %s ",buf);
238 if (a==2) printf("(%s) ",buf);
239 if (a==6) printf("%s\n",buf);
244 if (!strcmp(remote_nodename,config.c_nodename)) {
245 fprintf(stderr,"Connected to local system\n");
248 sprintf(buf,"NETP %s|%s",config.c_nodename,argv[3]);
253 /* only do the transfers if we authenticated correctly! */
256 transmit_spool(remote_nodename);