00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "maloc/maloc.h"
00038
00039 #define VEMBED(rctag) VPRIVATE const char* rctag; \
00040 static void* use_rcsid=(0 ? &use_rcsid : (void*)&rcsid);
00041 VEMBED(rcsid="$Id: main.c,v 1.12 2008/02/22 23:06:00 fetk Exp $")
00042
00043
00044
00045 int main(int argc, char *argv[])
00046 {
00047 char inType[80], outType[80], hostname[64], buf[VMAX_BUFSIZE];
00048 int ok, inputWasFile, done, firstTime, bufsize;
00049 Vio *inSock, *outSock;
00050
00051 inputWasFile = 0;
00052 ok = 1;
00053 if (argc == 4) {
00054 strncpy(hostname,"localhost",sizeof(hostname));
00055 fprintf(stderr,"%s: Starting up on host <%s>\n", argv[0], hostname);
00056 if (!strcmp(argv[1],"-u2i")) {
00057 strcpy(inType,"UNIX");
00058 strcpy(outType,"INET");
00059 } else if (!strcmp(argv[1],"-i2u")) {
00060 strcpy(inType,"INET");
00061 strcpy(outType,"UNIX");
00062 } else if (!strcmp(argv[1],"-u2u")) {
00063 strcpy(inType,"UNIX");
00064 strcpy(outType,"UNIX");
00065 } else if (!strcmp(argv[1],"-i2i")) {
00066 strcpy(inType,"INET");
00067 strcpy(outType,"INET");
00068 } else if (!strcmp(argv[1],"-f2u")) {
00069 strcpy(inType,"FILE");
00070 strcpy(outType,"UNIX");
00071 inputWasFile = 1;
00072 } else if (!strcmp(argv[1],"-f2i")) {
00073 strcpy(inType,"FILE");
00074 strcpy(outType,"INET");
00075 inputWasFile = 1;
00076 } else ok = 0;
00077 } else ok = 0;
00078
00079 VJMPERR1( ok );
00080
00081
00082 Vio_start();
00083
00084
00085 if ( VNULL==(inSock=Vio_ctor(inType,"ASC",hostname,argv[2],"r")) ) {
00086 fprintf(stderr,"%s: Problem open input socket <%s>\n",
00087 argv[0],argv[2]);
00088 VJMPERR1(0);
00089 } else {
00090 firstTime = 1;
00091 done = 0;
00092 while (!done) {
00093
00094
00095 if (firstTime) {
00096 firstTime = 0;
00097
00098
00099 if (inputWasFile) done = 1;
00100
00101
00102 } else {
00103
00104
00105 }
00106
00107
00108 if ( 0 > Vio_accept(inSock,0) ) {
00109 fprintf(stderr,"%s: Problem accept input socket <%s>\n",
00110 argv[0], argv[3]);
00111 VJMPERR1(0);
00112 } else {
00113
00114
00115 fprintf(stderr,"%s: Hit on %s port <%s> from <%s>\n",
00116 argv[0],inType,inSock->file,inSock->rhost);
00117
00118
00119 if ( VNULL==(outSock=Vio_ctor(outType,"ASC",
00120 hostname,argv[3],"w")) ) {
00121 fprintf(stderr,"%s: Problem open output socket <%s>\n",
00122 argv[0], argv[3]);
00123 VJMPERR1(0);
00124 } else {
00125
00126
00127 if ( 0 > Vio_connect(outSock,0) ) {
00128 fprintf(stderr,"%s: Problem conn output socket <%s>\n",
00129 argv[0], argv[3]);
00130 VJMPERR1(0);
00131 } else {
00132
00133
00134 fprintf(stderr,"%s: Pass to %s port <%s> on <%s>\n",
00135 argv[0],outType,outSock->file,outSock->lhost);
00136
00137
00138 memset(buf, '\0', sizeof(buf));
00139 while (0<(bufsize=Vio_read(inSock,buf,sizeof(buf)))) {
00140 VJMPERR2(bufsize==Vio_write(outSock,buf,bufsize));
00141 memset(buf, '\0', sizeof(buf));
00142 }
00143
00144
00145 VERROR2:
00146 Vio_connectFree(outSock);
00147 }
00148
00149 Vio_dtor(&outSock);
00150 }
00151
00152 Vio_acceptFree(inSock);
00153 }
00154 }
00155 }
00156
00157 Vio_dtor(&inSock);
00158
00159
00160 Vio_stop();
00161
00162
00163 fprintf(stderr,"%s: Shutting down on host <%s>\n", argv[0], hostname);
00164 return 1;
00165
00166 VERROR1:
00167 fprintf(stderr,"Usage: %s -u2i unixSocket inetSocket\n", argv[0]);
00168 fprintf(stderr," or: %s -i2u inetSocket unixSocket\n", argv[0]);
00169 fprintf(stderr," or: %s -u2u unixSocket unixSocket\n", argv[0]);
00170 fprintf(stderr," or: %s -i2i inetSocket inetSocket\n", argv[0]);
00171 fprintf(stderr," or: %s -f2u fileName unixSocket\n", argv[0]);
00172 fprintf(stderr," or: %s -f2i fileName inetSocket\n", argv[0]);
00173 return 0;
00174 }
00175