From: Robert W. <wrw...@us...> - 2006-12-11 18:12:30
|
Update of /cvsroot/linuxisns/iscsiClient/src In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2579/src Modified Files: initiator.c Added Files: config.c Log Message: added filename option --- NEW FILE: config.c --- /*********************************************************************** * Copyright (c) Novell, Inc 2006 * * This file derived from code originally in initiator.c * * Copyright (c) IBM Corporation 2001 * Licensed Material - Program Property of IBM * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of IBM Corporation or Novell Inc, nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ***********************************************************************/ #include <stdlib.h> #include <pthread.h> #include <errno.h> #include "isns.h" #include "config.h" #define CLIENT_VERSION "1.1" #define MAX_VERSION 6 #define MIN_VERSION 0 #define HANDLE pthread_t* /*************************************** Globals **************************************/ char p_ip[256]; /******************************** ********************************/ extern int isns_port; extern int tcpFlag; extern ISNS_CMD cmd; /************************************************************************* *************************************************************************/ int config_init (char * filename, configuration * current, char ip[]) { FILE* configFile; current->hb_flag = TRUE; current->Port = 0; current->portalFlag = FALSE; current->EntityPeriod = 0; memset (current->iscsiID, (int) NULL, 256); memset (current->Alias, (int) NULL, 256); memset (current->PortalIP, (int) NULL, 256); memset (current->EntityID, (int) NULL, 256); memset (current->DDAlias, (int) NULL, 256); memset (current->DDSAlias, (int) NULL, 256); memset (current->Initiator, (int) NULL, 256); /* Open the file for reading */ configFile = fopen (filename, "r"); /* Read in the target information */ ReadFile (configFile, current, ip); fclose (configFile); return current->hb_flag; } /*********************************************************************** Accepts a pointer to an open file and a target object /***********************************************************************/ void ReadFile (FILE* ifp, configuration * thisInit, char ip_addr[]) { char temp, word[256], line[256]; int ii = 0; while (fscanf(ifp, "%c" , &temp) != EOF) { switch (temp) { /* This line is a comment */ case '*': fgets (line, 80, ifp); break; /* This line has the IP address of the iSNS Server */ case '1': fscanf (ifp, "%s", line); strcpy (ip_addr, line); thisInit->hb_flag = FALSE; break; /* This line has the iscsi ID and the iscsi Alias */ case '2': fscanf (ifp, "%s", line); strcpy (thisInit->iscsiID, line); fscanf (ifp, "%s", line); strcpy (thisInit->Alias, line); break; /* This line has the portal IP address and the port number */ case '3': fscanf (ifp, "%s", line); strcpy (thisInit->PortalIP, line); fscanf (ifp, "%d", &(thisInit->Port)); thisInit->portalFlag = TRUE; break; case '4': fscanf (ifp, "%s", line); /* formating only - gets rid of a newline */ for (ii = 0; ii < 256; ii++) if (line[ii] == '\n') line[ii] = '\0'; thisInit->listPtr = AddItem (thisInit->listPtr, line); break; case '5': fscanf (ifp, "%d", &(thisInit->EntityPeriod)); break; case '6': fscanf (ifp, "%s", line); strcpy (thisInit->EntityID, line); break; default: break; } } } listelement * AddItem (listelement * listpointer, char data[]) { listelement * lp = listpointer; if (listpointer != NULL) { while (listpointer->link != NULL) listpointer = (listelement*) listpointer->link; listpointer->link = (struct listelement *) malloc (sizeof (listelement)); listpointer = (listelement*) listpointer->link; listpointer->link = NULL; strncpy (listpointer->InitiatorName, data, 256); return lp; } else { listpointer = (listelement *) malloc (sizeof (listelement)); listpointer->link = NULL; strncpy (listpointer->InitiatorName, data, 256); return listpointer; } } void ClearQueue (listelement * listpointer) { while (listpointer != NULL) { listpointer = RemoveItem (listpointer); } } listelement * RemoveItem (listelement * listpointer) { listelement * tempp; printf ("Added %s to the initiator list.\n", listpointer->InitiatorName); tempp = (listelement*) listpointer->link; free (listpointer); return tempp; } void PrintList (listelement* TheList) { /* for keeping track of the head of the list */ listelement* temp; temp = TheList; while (TheList != NULL) { printf ("DD: %d\n", TheList->DDS); TheList = (listelement*)TheList->link; } /* TheList still points to the head of the list */ TheList = temp; } Index: initiator.c =================================================================== RCS file: /cvsroot/linuxisns/iscsiClient/src/initiator.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** initiator.c 11 Dec 2006 18:01:08 -0000 1.5 --- initiator.c 11 Dec 2006 18:12:27 -0000 1.6 *************** *** 50,53 **** --- 50,54 ---- **************************************/ char p_ip[256]; + char filename[256]="init.cfg"; /******************************** *************** *** 80,87 **** while (optind != argc) { ! c = getopt (argc, argv, "h:s:"); switch (c) { case EOF: optarg = argv[optind]; --- 81,94 ---- while (optind != argc) { ! c = getopt (argc, argv, "h:s:f:"); switch (c) { + case 'f': + printf ("optarg: %s\n", optarg); + strcpy (filename, optarg); + printf ("filename: %s\n", filename); + break; + case EOF: optarg = argv[optind]; *************** *** 94,98 **** } ! hb_flag = config_init ("init.cfg",&config, p_ip); /* Init the Communications sockets */ --- 101,105 ---- } ! hb_flag = config_init (filename,&config, p_ip); /* Init the Communications sockets */ |