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 4000
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)
42 static char pbuf[IGNET_PACKET_SIZE];
43 char tempfilename[64];
47 sprintf(tempfilename, "/tmp/netpoll.%ld", (long) getpid());
53 download_len = extract_long(&buf[4], 0);
56 fp = fopen(tempfilename, "w");
58 perror("cannot open download file locally");
61 while (bytes_received < download_len) {
62 sprintf(buf, "READ %ld|%ld",
64 ((download_len - bytes_received > IGNET_PACKET_SIZE)
65 ? IGNET_PACKET_SIZE : (download_len - bytes_received)));
69 plen = extract_long(&buf[4], 0);
70 serv_read(pbuf, plen);
71 fwrite((char *) pbuf, plen, 1, fp);
72 bytes_received = bytes_received + plen;
80 sprintf(buf, "mv %s %s/network/spoolin/netpoll.%ld",
81 tempfilename, BBSDIR, (long) getpid());
83 system("exec nohup ./netproc >/dev/null 2>&1 &");
87 * transmit network spool to the remote system
89 void transmit_spool(char *remote_nodename)
94 long bytes_to_write, thisblock;
104 sprintf(sfname, "%s/network/spoolout/%s", BBSDIR, remote_nodename);
105 fd = open(sfname, O_RDONLY);
107 if (errno == ENOENT) {
108 printf("Nothing to send.\n");
110 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;
142 int main(int argc, char **argv)
145 char remote_nodename[32];
150 "%s: usage: %s <address> <port number> <remote netpassword>\n",
156 attach_to_server(argc, argv);
159 if ((buf[0] != '2') && (strncmp(buf, "551", 3))) {
160 fprintf(stderr, "%s: %s\n", argv[0], &buf[4]);
167 while (serv_gets(buf), strcmp(buf, "000")) {
169 strcpy(remote_nodename, buf);
171 printf("Connected to: %s ", buf);
173 printf("(%s) ", buf);
179 if (!strcmp(remote_nodename, config.c_nodename)) {
180 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);