4 * Perform data transfer between our Citadel server and another.
20 * This variable defines the amount of network spool data that may be carried
21 * in one server transfer command. For some reason, some networks get hung
22 * up on larger packet sizes. We don't know why. In any case, never set the
23 * packet size higher than 4096 or your server sessions will crash.
25 #define IGNET_PACKET_SIZE 4000
27 long atol(const char *);
29 void serv_read(char *buf, int bytes);
30 void serv_write(char *buf, int nbytes);
31 void get_config(void);
42 * receive network spool from the remote system
44 void receive_spool(void)
49 static char pbuf[IGNET_PACKET_SIZE];
50 char tempfilename[PATH_MAX];
54 sprintf(tempfilename, tmpnam(NULL));
60 download_len = extract_long(&buf[4], 0);
63 fp = fopen(tempfilename, "w");
65 perror("cannot open download file locally");
68 while (bytes_received < download_len) {
69 sprintf(buf, "READ %ld|%ld",
71 ((download_len - bytes_received > IGNET_PACKET_SIZE)
72 ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
76 plen = extract_long(&buf[4], 0);
77 serv_read(pbuf, plen);
78 fwrite((char *) pbuf, plen, 1, fp);
79 bytes_received = bytes_received + plen;
87 sprintf(buf, "mv %s %s/network/spoolin/netpoll.%ld",
88 tempfilename, BBSDIR, (long) getpid());
90 system("exec nohup ./netproc >/dev/null 2>&1 &");
94 * transmit network spool to the remote system
96 void transmit_spool(char *remote_nodename)
101 long bytes_to_write, thisblock;
111 sprintf(sfname, "%s/network/spoolout/%s", BBSDIR, remote_nodename);
112 fd = open(sfname, O_RDONLY);
114 if (errno == ENOENT) {
115 printf("Nothing to send.\n");
117 perror("cannot open upload file locally");
121 while (plen = (long) read(fd, pbuf, IGNET_PACKET_SIZE), plen > 0L) {
122 bytes_to_write = plen;
123 while (bytes_to_write > 0L) {
124 sprintf(buf, "WRIT %ld", bytes_to_write);
127 thisblock = atol(&buf[4]);
129 serv_write(pbuf, (int) thisblock);
130 bytes_to_write = bytes_to_write - thisblock;
149 int main(int argc, char **argv)
152 char remote_nodename[32];
157 "%s: usage: %s <address> <port number> <remote netpassword>\n",
163 attach_to_server(argc, argv, NULL, NULL);
166 if ((buf[0] != '2') && (strncmp(buf, "551", 3))) {
167 fprintf(stderr, "%s: %s\n", argv[0], &buf[4]);
174 while (serv_gets(buf), strcmp(buf, "000")) {
176 strcpy(remote_nodename, buf);
178 printf("Connected to: %s ", buf);
180 printf("(%s) ", buf);
186 if (!strcmp(remote_nodename, config.c_nodename)) {
187 fprintf(stderr, "Connected to local system\n");
189 sprintf(buf, "NETP %s|%s", config.c_nodename, argv[3]);
194 /* only do the transfers if we authenticated correctly! */
197 transmit_spool(remote_nodename);