www.pudn.com > tftp.rar > INIT.C
/* ** This product contains: ** "Restricted Materials of IBM" ** (c) Copyright IBM Corp. 1987 ** All Rights Reserved ** Licensed Materials-Property of IBM ** ** See Copyright Instructions, G120-2083 ** */ /* ** File: ** init.c ** ** Routines: ** initialize (argv) - Initialize the tftp session ** */ #include#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tftpdefs.h" /* ** Routine: ** initialize (argv) ** ** Purpose: ** To initialize the tftp session ** ** Input Parameters: ** argv - a (char **) pointing to the command line parameter list ** ** External Dependencies: ** conn - a (struct tftpcon) that contains the session connection info ** ** Return Value: ** none ** ** Side Effects: ** To enable backward compatibility, the old form of tftp is supported ** This may cause the program to exit from this routine without returning ** ** Notes: ** The old form of tftp used the format: ** tftp {get|put|-g|-p} {filename1} {remote host} {filename2} [image] ** or ** tftp {serve|spool} */ void initialize (argv) char *argv[]; { int parmcnt; int c; char temp[FILENAMELEN]; char parms[6][FILENAMELEN]; /* ** figure out who I am */ whosme(argv[0],"tftp"); /* ** Initialize the network stuff */ NBUF = 12; Netinit(800); in_init(); IcmpInit(); GgpInit(); UdpInit(); nm_init(); /* ** Initialize the tftp session connection information */ conn.hostname[0] = '\0'; conn.host = 0; conn.flags = F_VERBOSE | F_EOFMARK; conn.mode = M_UNDEFINED; parmcnt = 0; /* ** get options off the command line */ o_delims = "-"; while ((c = getopt(argv,"?gptvbaczs","")) != O_END_OF_OPTS) switch (c) { case '?': /* help */ usage(); exit(1); case 'g': /* get a file (batch mode) */ if (parmcnt == 0) parms[parmcnt++][0] = 'g'; else message ("Invalid option placement\n",ERR,use); break; case 'p': /* put a file (batch mode) */ if (parmcnt == 0) parms[parmcnt++][0] = 'p'; else message ("Invalid option placement\n",ERR,use); break; case 't': /* toggle trace flag on */ conn.flags = conn.flags ^ F_TRACE; break; case 'v': /* toggle verbose flag */ conn.flags = conn.flags ^ F_VERBOSE; break; case 'b': /* set mode to binary */ if (conn.mode == M_UNDEFINED || conn.mode == M_BINARY) conn.mode = M_BINARY; else message ("Conflicting options: -b and -a\n",ERR,use); break; case 'a': /* set mode to ascii */ if (conn.mode == M_UNDEFINED || conn.mode == M_ASCII) conn.mode = M_ASCII; else message ("Conflicting options: -a and -b\n",ERR,use); break; case 'c': /* toggle clobber flag */ conn.flags = conn.flags ^ F_CLOBBER; break; case 'z': /* toggle write end of file mark (^Z) flag */ conn.flags = conn.flags ^ F_EOFMARK; break; case 's': /* enter server mode, do not pass go, ... */ server (S_NOSPOOL); exit (0); case O_PARAMETER: if (parmcnt == 0) if (strcmpi("get",argument) == 0 || strcmpi("put",argument) == 0) parms[parmcnt++][0] = tolower(argument[0]); else if (strcmpi("serve",argument) == 0) { server( S_NOSPOOL ); exit(0); } else if (strcmpi("spool",argument) == 0) { server( S_SPOOL ); exit (0); } else strcpy(conn.hostname,argument); else strcpy(parms[parmcnt++],argument); case O_OPTS_END: break; case O_OPT_EXPECTED: message ("Option expected\n",ERR,use); case O_UNKNOWN: sprintf (temp,"Unknown option -- %c\n",*argument); message (temp,ERR,use); default: sprintf (temp,"Bad getopt() return -- %d\n",c); message (temp,INT_ERR,NULL); } /* ** The following nastiness is here for backward compatibility. May the ** person who came up with the original idea for this slime develope some ** new form of permanent bad breath. */ if (parmcnt != 0) { if (parmcnt < 4) message ("Missing parameters",ERR,use); connect (parms[2]); if (parmcnt == 5) if (strcmpi(parms[4],"image") == 0) conn.mode = M_BINARY; else if (strcmpi(parms[4],"ascii") == 0) conn.mode = M_ASCII; else message ("Unknown transfer mode specified\n",ERR,use); else conn.mode = M_ASCII; sprintf (temp,"%s %s",parms[1],parms[3]); if (parms[0][0] == 'g') transfer (D_GET,temp); else transfer (D_PUT,temp); exit (0); } else if (*conn.hostname != '\0') connect (conn.hostname); if (conn.mode == M_UNDEFINED) conn.mode = M_ASCII; }