12 * This variable defines the amount of network spool data that may be carried
13 * in one server transfer command. For some reason, some networks get hung
14 * up on larger packet sizes. We don't know why. In any case, never set the
15 * packet size higher than 4096 or your server sessions will crash.
17 #define IGNET_PACKET_SIZE 64
19 long atol(const char *);
21 void attach_to_server(int argc, char **argv);
22 void serv_read(char *buf, int bytes);
23 void serv_write(char *buf, int nbytes);
24 void get_config(void);
35 * receive network spool from the remote system
37 void receive_spool(void) {
41 static char pbuf[IGNET_PACKET_SIZE];
42 char tempfilename[64];
46 sprintf(tempfilename,"/tmp/netpoll.%ld",(long)getpid());
50 if (buf[0]!='2') return;
51 download_len = extract_long(&buf[4],0);
54 fp = fopen(tempfilename,"w");
56 perror("cannot open download file locally");
60 while (bytes_received < download_len) {
61 sprintf(buf,"READ %ld|%ld",
63 ( (download_len - bytes_received > IGNET_PACKET_SIZE)
64 ? IGNET_PACKET_SIZE : (download_len - bytes_received) ) );
68 plen = extract_long(&buf[4],0);
70 fwrite((char *)pbuf,plen,1,fp);
71 bytes_received = bytes_received + plen;
79 sprintf(buf,"mv %s %s/network/spoolin/netpoll.%ld",
80 tempfilename,BBSDIR,(long)getpid());
82 system("exec nohup ./netproc >/dev/null 2>&1 &");
86 * transmit network spool to the remote system
88 void transmit_spool(char *remote_nodename)
93 long bytes_to_write, thisblock;
100 if (buf[0]!='2') return;
102 sprintf(sfname,"%s/network/spoolout/%s",BBSDIR,remote_nodename);
103 fd = open(sfname,O_RDONLY);
105 if (errno == ENOENT) {
106 printf("Nothing to send.\n");
109 perror("cannot open upload file locally");
114 while ( plen=(long)read(fd,pbuf,IGNET_PACKET_SIZE), plen>0L) {
115 bytes_to_write = plen;
116 while (bytes_to_write > 0L) {
117 sprintf(buf,"WRIT %ld", bytes_to_write);
120 thisblock = atol(&buf[4]);
122 serv_write(pbuf, (int)thisblock);
123 bytes_to_write = bytes_to_write - thisblock;
136 if (buf[0]=='2') unlink(sfname);
142 int main(int argc, char **argv)
145 char remote_nodename[32];
150 "%s: usage: %s <address> <port number> <remote netpassword>\n",
157 attach_to_server(argc,argv);
160 if ((buf[0]!='2')&&(strncmp(buf,"551",3))) {
161 fprintf(stderr,"%s: %s\n",argv[0],&buf[4]);
169 while (serv_gets(buf), strcmp(buf,"000")) {
170 if (a==1) strcpy(remote_nodename,buf);
171 if (a==1) printf("Connected to: %s ",buf);
172 if (a==2) printf("(%s) ",buf);
173 if (a==6) printf("%s\n",buf);
178 if (!strcmp(remote_nodename,config.c_nodename)) {
179 fprintf(stderr,"Connected to local system\n");
182 sprintf(buf,"NETP %s|%s",config.c_nodename,argv[3]);
187 /* only do the transfers if we authenticated correctly! */
190 transmit_spool(remote_nodename);