⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 网络数据管理协议的开发
💻 C
字号:
/*                               -*- Mode: C -*-  * main.c *  * Description     : ndmpc main(). *                   NDMP client application for testing NDMP server *                   implementations. *  *    usage: ndmpc [-d debug-level] [-f tcl-script-file]        *                 [-h ndmp-server] [-p port-number]            *							        *    where:                                                    *      debug-level - The least significant 4 bits of the       *		    level specify the detail. 0 will          *		    result in mimimal messages for enabled    *		    components being output. 15 will          *		    result in all messages for enabled        *		    components being output.                  *		    The remaining bits in the level specify   *		    the components for which messages are     *		    to be output. Refer to ../common/log.h    *		    for defined components.                   *		    Default is all messages disabled.         *							        *      tcl-script-file - Tcl file to source upon startup. After sourcing *			the file, the application will enter interactive mode. *			If no file is specified, the application will *			immediately enter interactive mode. *							        *      ndmp-server - name of the host running the NDMP server  *		    that ndmpc is to connect to.              *		    Default is localhost.                     *							        *      port-number - TCP port number on which the NDMP server  *		    is listening for connection requests.     *		    Default is 10000.                         * * Copyright (c) 1996,1997 PDC, Network Appliance. All Rights Reserved. * * $Id: main.c,v 1.4 1997/02/03 06:11:52 tim Exp $ */#if !defined(lint) && !defined(SABER)static char rcsId[] __attribute__ ((unused)) = "@(#) $Id: main.c,v 1.4 1997/02/03 06:11:52 tim Exp $";#endif#include <stdlib.h>#include <unistd.h>#include <stdio.h>#include <errno.h>#include <fcntl.h>#include <sys/types.h>#include <sys/socket.h>#include <stropts.h>#include <poll.h>#include <rpc/rpc.h>#include <rpc/xdr.h>#include <string.h>#include <sys/uio.h>#include <tcl.h>#include "ndmp_common.h"#include "ndmpc.h"extern NdmpMsgHandler	ndmpcMsgHandlerTable[];intmain(int	argc,	 char*	argv[]){	char				c;	char*				host = "localhost";	char*				file = 0;	char*				initFile = 0;	u_long				port = 10000;    char            	linebuf[1024];    fd_set				rfds;    fd_set				efds;    NdmpConnection		connection;	int					input_fd = 0;	int					err;	Tcl_Interp*			interp;		while ((c = getopt(argc, argv, "d:f:h:p:s:")) != EOF)	{		switch (c)		{			case 'd':			{				SetDebugLevel(strtol(optarg, 0, 0));				break;			}						case 'p':			{				port = strtol(optarg, 0, 0);				break;			}			case 'h':			{				host = optarg;				break;			}			case 'f':			{				file = optarg;				break;			}			case 's':			{				initFile = optarg;				break;			}			default:			{				(void) fprintf(stderr,							   "usage: %s [-p port] [-h host] [-f file]\n",							   argv[0]);				exit(1);			}		}	}		if ((connection = ndmpCreateConnection(ndmpcMsgHandlerTable)) == 0)	{		Error(LOG_ERR, "creating connection.\n");		exit(1);	}		if (ndmpConnect(connection, host, port) < 0)	{		Error(LOG_ERR, "connecting to NDMP server on %s:%d.\n",			  host, port);		exit(1);	}		/*	 * Open the Tcl script file.	 */	if (file)	{		if ((input_fd = open(file, O_RDONLY)) < 0)		{			Error(LOG_ERR, "Error opening %s: %s",				  file, strerror(errno));			input_fd = 0;		}	}	    interp = ndmpcTclInit((void*)connection);	if (initFile)		Tcl_EvalFile(interp, initFile);	    while (1)    {		FD_ZERO(&rfds);		FD_ZERO(&efds);		FD_SET(input_fd, &rfds);		FD_SET(input_fd, &efds);		FD_SET(ndmpGetFd(connection), &rfds);		FD_SET(ndmpGetFd(connection), &efds);				err = select(32, &rfds, 0, &efds, 0);				if (err < 0)		{			if (errno == EINTR)				continue;			Error(LOG_ERR, "poll: %s.\n", strerror(errno));			exit(1);		}				if (FD_ISSET(input_fd, &efds))		{			/*			 * No more input. If inputting from a file,			 * set the input back to stdin.			 */			if (input_fd)			{				close(input_fd);				input_fd = 0;			}			else			{				Error(LOG_ERR, "on command input file.\n");				exit(1);			}		}				if (FD_ISSET(ndmpGetFd(connection), &efds))		{			Error(LOG_ERR, "on socket to NDMP server.\n");			exit(1);		}				if (FD_ISSET(ndmpGetFd(connection), &rfds))		{			if (ndmpProcessRequests(connection) < 0)				exit(1);		}				if (FD_ISSET(input_fd, &rfds))		{			u_long		i;						err = 0;						for (i = 0; i < sizeof(linebuf)-1; i++)			{				if (read(input_fd, &linebuf[i], 1) <= 0)				{					err = 1;					break;				}								if (linebuf[i] == '\n')				{					linebuf[i] = '\0'; 					/*linebuf[i+1] = '\0';*/					break;				}			}						if (!err)			{				/* Echo the input if inputting from a file. */				if (input_fd)					puts(linebuf);								ndmpcProcessTclCmdString(interp, linebuf);			}			else			{				/*				 * No more input. If inputting from a file,				 * set the input back to stdin.				 */				if (input_fd)				{					close(input_fd);					input_fd = 0;				}			}		}    }    exit(0);}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -