14 * This variable defines the amount of network spool data that may be carried
15 * in one server transfer command. For some reason, some networks get hung
16 * up on larger packet sizes. We don't know why. In any case, never set the
17 * packet size higher than 4096 or your server sessions will crash.
19 #define IGNET_PACKET_SIZE 4000
21 long atol(const char *);
23 void serv_read(char *buf, int bytes);
24 void serv_write(char *buf, int nbytes);
25 void get_config(void);
36 * receive network spool from the remote system
38 void receive_spool(void)
43 static char pbuf[IGNET_PACKET_SIZE];
44 char tempfilename[PATH_MAX];
48 sprintf(tempfilename, tmpnam(NULL));
54 download_len = extract_long(&buf[4], 0);
57 fp = fopen(tempfilename, "w");
59 perror("cannot open download file locally");
62 while (bytes_received < download_len) {
63 sprintf(buf, "READ %ld|%ld",
65 ((download_len - bytes_received > IGNET_PACKET_SIZE)
66 ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
70 plen = extract_long(&buf[4], 0);
71 serv_read(pbuf, plen);
72 fwrite((char *) pbuf, plen, 1, fp);
73 bytes_received = bytes_received + plen;
81 sprintf(buf, "mv %s %s/network/spoolin/netpoll.%ld",
82 tempfilename, BBSDIR, (long) getpid());
84 system("exec nohup ./netproc >/dev/null 2>&1 &");
88 * transmit network spool to the remote system
90 void transmit_spool(char *remote_nodename)
95 long bytes_to_write, thisblock;
105 sprintf(sfname, "%s/network/spoolout/%s", BBSDIR, remote_nodename);
106 fd = open(sfname, O_RDONLY);
108 if (errno == ENOENT) {
109 printf("Nothing to send.\n");
111 perror("cannot open upload file locally");
115 while (plen = (long) read(fd, pbuf, IGNET_PACKET_SIZE), plen > 0L) {
116 bytes_to_write = plen;
117 while (bytes_to_write > 0L) {
118 sprintf(buf, "WRIT %ld", bytes_to_write);
121 thisblock = atol(&buf[4]);
123 serv_write(pbuf, (int) thisblock);
124 bytes_to_write = bytes_to_write - thisblock;
143 int main(int argc, char **argv)
146 char remote_nodename[32];
151 "%s: usage: %s <address> <port number> <remote netpassword>\n",
157 attach_to_server(argc, argv, NULL, NULL);
160 if ((buf[0] != '2') && (strncmp(buf, "551", 3))) {
161 fprintf(stderr, "%s: %s\n", argv[0], &buf[4]);
168 while (serv_gets(buf), strcmp(buf, "000")) {
170 strcpy(remote_nodename, buf);
172 printf("Connected to: %s ", buf);
174 printf("(%s) ", buf);
180 if (!strcmp(remote_nodename, config.c_nodename)) {
181 fprintf(stderr, "Connected to local system\n");
183 sprintf(buf, "NETP %s|%s", config.c_nodename, argv[3]);
188 /* only do the transfers if we authenticated correctly! */
191 transmit_spool(remote_nodename);