/**************************************************************************** OS/A65 Version 1.3.13 Multitasking Operating System for 6502 Computers Copyright (C) 1989-1997 Andre Fachat This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ****************************************************************************/ /* * This file is a server FSTCP filesystem implementation, to be * used with the FSTCP program on an OS/A65 computer. * * usage: * fstcp [options] exported_directory * * options: * -ro export read-only */ #define PORT 8090 #include #include #include #include #include #include #include #include #include #include #include #include #include "fstcp.h" #include "oa1fs.h" #define min(a,b) (((a)<(b))?(a):(b)) typedef struct { int state; FILE *fp; DIR *dp; } File; File files[MAXFILES]; void usage(void) { printf("Usage: fstcp [options] exported_directory hostname_to_export_to\n" " options=\n" " -ro export read-only\n" ); exit(1); } void do_cmd(char *buf, int fd) { int tfd, cmd, len; char retbuf[200]; char *nm; FILE *fp; DIR *dp; int n; struct dirent *de; struct stat sbuf; struct tm *tp; cmd = buf[FSP_CMD]; tfd = buf[FSP_FD]; len = buf[FSP_LEN]; fp = files[tfd].fp; dp = files[tfd].dp; printf("got cmd=%d, fd=%d, name=%s\n",cmd,tfd, cmdd_name, &sbuf); /* TODO: check return value */ retbuf[FSP_DATA+FS_DIR_LEN] = sbuf.st_size & 255; retbuf[FSP_DATA+FS_DIR_LEN+1] = (sbuf.st_size >> 8) & 255; retbuf[FSP_DATA+FS_DIR_LEN+2] = (sbuf.st_size >> 16) & 255; retbuf[FSP_DATA+FS_DIR_LEN+3] = (sbuf.st_size >> 24) & 255; tp = localtime(&sbuf.st_mtime); retbuf[FSP_DATA+FS_DIR_YEAR] = tp->tm_year; retbuf[FSP_DATA+FS_DIR_MONTH] = tp->tm_mon; retbuf[FSP_DATA+FS_DIR_DAY] = tp->tm_mday; retbuf[FSP_DATA+FS_DIR_HOUR] = tp->tm_hour; retbuf[FSP_DATA+FS_DIR_MIN] = tp->tm_min; retbuf[FSP_DATA+FS_DIR_SEC] = tp->tm_sec; retbuf[FSP_DATA+FS_DIR_MODE] = S_ISDIR(sbuf.st_mode) ? FS_DIR_MOD_DIR : FS_DIR_MOD_FIL; strncpy(retbuf+FSP_DATA+FS_DIR_NAME, de->d_name, min(strlen(de->d_name)+1, 199-FSP_DATA-FS_DIR_NAME)); retbuf[199]=0; retbuf[FSP_LEN] = FSP_DATA+FS_DIR_NAME+ strlen(retbuf+FSP_DATA+FS_DIR_NAME) + 1; retbuf[FSP_CMD] = FS_WRITE; } else if(fp) { n = fread(retbuf+FSP_DATA, 1, 64, fp); retbuf[FSP_LEN] = n+FSP_DATA; if(n<64) { retbuf[FSP_CMD] = FS_EOF; fclose(fp); files[tfd].fp = NULL; } else { retbuf[FSP_CMD] = FS_WRITE; } } break; case FS_WRITE: case FS_EOF: if(fp) { n = fwrite(buf+FSP_DATA, 1, len-FSP_DATA, fp); retbuf[FSP_DATA] = 0; if(cmd == FS_EOF) { fclose(fp); files[tfd].fp = NULL; } } break; case FS_CLOSE: if(fp) fclose(fp); if(dp) closedir(dp); files[tfd].fp = NULL; files[tfd].dp = NULL; retbuf[FSP_DATA] = 0; break; } write(fd, retbuf, retbuf[FSP_LEN]); printf("write %02x %02x %02x %02x\n", retbuf[0], retbuf[1], retbuf[2], retbuf[3]); } int main(int argc, char *argv[]) { int sock, err; struct sockaddr_in serv_addr, client_addr, host_addr; int client_addr_len; int port=PORT; int fd; int i, ro=0; char *dir, *hname; struct hostent *he; i=1; while(ih_name); if(he->h_addrtype != AF_INET) { fprintf(stderr, "Address type for %s not Internet!\n", hname); exit(2); } memcpy((char*)&host_addr.sin_addr.s_addr, he->h_addr_list[0], he->h_length); /* host_addr.sin_addr.s_addr = ntohl(*(long*)(he->h_addr_list[0]));*/ printf("ok, want connection to %08lx\n", host_addr.sin_addr.s_addr); for(i=0;i FSP_LEN) { plen = buf[rdp+FSP_LEN]; printf("wrp-rdp=%d, plen=%d\n",wrp-rdp,plen); if(wrp-rdp >= plen) { do_cmd(buf+rdp, fd); rdp +=plen; } else { break; } } } exit(0); } else { printf("connect trial rejected!\n"); close(fd); } } close(sock); return 0; }