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

📄 config.c

📁 在Linux/Unix下面访问WINDOWS SQLSERVER 的ODBC驱动程序
💻 C
📖 第 1 页 / 共 3 页
字号:
		tds_inet_ntoa_r(*ptr, ip, 17);	}}				/* tds_lookup_host()  *//** * Given a portname lookup the port. * * If we can't determine the port number than function return 0. */static inttds_lookup_port(const char *portname){	int num = 0;	if (portname) {		num = atoi(portname);		if (!num) {			char buffer[4096];			struct servent serv_result;			struct servent *service = tds_getservbyname_r(portname, "tcp", &serv_result, buffer, sizeof(buffer));			if (service)				num = ntohs(service->s_port);		}	}	return num;}/* TODO same code in convert.c ?? */static inthexdigit(int c){	if (c >= '0' && c <= '9')		return c - '0';	/* ascii optimization, 'A' -> 'a', 'a' -> 'a' */	c |= 0x20;	if (c >= 'a' && c <= 'f')		return c - 'a' + 10;	return 0;	/* bad hex digit */}static inthex2num(char *hex){	return hexdigit(hex[0]) * 16 + hexdigit(hex[1]);}/** * Open and read the file 'file' searching for a logical server * by the name of 'host'.  If one is found then lookup * the IP address and port number and store them in 'connection' * * \param dir name of base directory for interface file * \param file name of the interface file * \param host logical host to search for * \return 0 if not fount 1 if found */static intsearch_interface_file(TDSCONNECTION * connection, const char *dir, const char *file, const char *host){	char *pathname;	char line[255];	char tmp_ip[sizeof(line)];	char tmp_port[sizeof(line)];	char tmp_ver[sizeof(line)];	FILE *in;	char *field;	int found = 0;	int server_found = 0;	char *lasts;	line[0] = '\0';	tmp_ip[0] = '\0';	tmp_port[0] = '\0';	tmp_ver[0] = '\0';	tdsdump_log(TDS_DBG_INFO1, "Searching interfaces file %s/%s.\n", dir, file);	pathname = (char *) malloc(strlen(dir) + strlen(file) + 10);	if (!pathname)		return 0;	/*	 * create the full pathname to the interface file	 */	if (file[0] == '\0') {		pathname[0] = '\0';	} else {		if (dir[0] == '\0') {			pathname[0] = '\0';		} else {			strcpy(pathname, dir);			strcat(pathname, TDS_SDIR_SEPARATOR);		}		strcat(pathname, file);	}	/*	 * parse the interfaces file and find the server and port	 */	if ((in = fopen(pathname, "r")) == NULL) {		tdsdump_log(TDS_DBG_INFO1, "Couldn't open %s.\n", pathname);		free(pathname);		return 0;	}	tdsdump_log(TDS_DBG_INFO1, "Interfaces file %s opened.\n", pathname);	while (fgets(line, sizeof(line) - 1, in)) {		if (line[0] == '#')			continue;	/* comment */		if (!TDS_ISSPACE(line[0])) {			field = strtok_r(line, "\n\t ", &lasts);			if (!strcmp(field, host)) {				found = 1;				tdsdump_log(TDS_DBG_INFO1, "Found matching entry for host %s.\n", host);			} else				found = 0;		} else if (found && TDS_ISSPACE(line[0])) {			field = strtok_r(line, "\n\t ", &lasts);			if (field != NULL && !strcmp(field, "query")) {				field = strtok_r(NULL, "\n\t ", &lasts);	/* tcp or tli */				if (!strcmp(field, "tli")) {					tdsdump_log(TDS_DBG_INFO1, "TLI service.\n");					field = strtok_r(NULL, "\n\t ", &lasts);	/* tcp */					field = strtok_r(NULL, "\n\t ", &lasts);	/* device */					field = strtok_r(NULL, "\n\t ", &lasts);	/* host/port */					if (strlen(field) >= 18) {						sprintf(tmp_port, "%d", hex2num(&field[6]) * 256 + hex2num(&field[8]));						sprintf(tmp_ip, "%d.%d.%d.%d", hex2num(&field[10]),							hex2num(&field[12]), hex2num(&field[14]), hex2num(&field[16]));						tdsdump_log(TDS_DBG_INFO1, "tmp_port = %s. tmp_ip = %s.\n", tmp_port, tmp_ip);					}				} else {					field = strtok_r(NULL, "\n\t ", &lasts);	/* ether */					strcpy(tmp_ver, field);					field = strtok_r(NULL, "\n\t ", &lasts);	/* host */					strcpy(tmp_ip, field);					tdsdump_log(TDS_DBG_INFO1, "host field %s.\n", tmp_ip);					field = strtok_r(NULL, "\n\t ", &lasts);	/* port */					strcpy(tmp_port, field);				}	/* else */				server_found = 1;			}	/* if */		}		/* else if */	}			/* while */	fclose(in);	free(pathname);	/*	 * Look up the host and service	 */	if (server_found) {		tds_dstr_copy(&connection->server_host_name, tmp_ip);		tds_lookup_host(tmp_ip, line);		tdsdump_log(TDS_DBG_INFO1, "Resolved IP as '%s'.\n", line);		tds_dstr_copy(&connection->ip_addr, line);		if (tmp_port[0])			connection->port = tds_lookup_port(tmp_port);		if (tmp_ver[0])			tds_config_verstr(tmp_ver, connection);	}	return server_found;}				/* search_interface_file()  *//** * Try to find the IP number and port for a (possibly) logical server name. * * @note This function uses only the interfaces file and is deprecated. */static voidtds_read_interfaces(const char *server, TDSCONNECTION * connection){	int founded = 0;	/* read $SYBASE/interfaces */	if (!server || strlen(server) == 0) {		server = getenv("TDSQUERY");		if (!server || strlen(server) == 0) {			server = "SYBASE";		}		tdsdump_log(TDS_DBG_INFO1, "Setting server to %s from $TDSQUERY.\n", server);	}	tdsdump_log(TDS_DBG_INFO1, "Looking for server %s....\n", server);	/*	 * Look for the server in the interf_file iff interf_file has been set.	 */	if (interf_file) {		tdsdump_log(TDS_DBG_INFO1, "Looking for server in file %s.\n", interf_file);		founded = search_interface_file(connection, "", interf_file, server);	}	/*	 * if we haven't found the server yet then look for a $HOME/.interfaces file	 */	if (!founded) {		char *path = tds_get_home_file(".interfaces");		if (path) {			tdsdump_log(TDS_DBG_INFO1, "Looking for server in %s.\n", path);			founded = search_interface_file(connection, "", path, server);			free(path);		}	}	/*	 * if we haven't found the server yet then look in $SYBBASE/interfaces file	 */	if (!founded) {		const char *sybase = getenv("SYBASE");#ifdef __VMS		/* We've got to be in unix syntax for later slash-joined concatenation. */		#include <unixlib.h>		const char *unixspec = decc$translate_vms(sybase);		if ( (int)unixspec != 0 && (int)unixspec != -1 ) sybase = unixspec;#endif		if (!sybase || !sybase[0])			sybase = interfaces_path;		tdsdump_log(TDS_DBG_INFO1, "Looking for server in %s/interfaces.\n", sybase);		founded = search_interface_file(connection, sybase, "interfaces", server);	}	/*	 * If we still don't have the server and port then assume the user	 * typed an actual server name.	 */	if (!founded) {		char ip_addr[255];		int ip_port;		const char *env_port;		/*		 * Make a guess about the port number		 */		if (connection->port == 0) {			/*			 * Not set in the [global] section of the			 * configure file, take a guess.			 */#ifdef TDS50			ip_port = 4000;#else			ip_port = 1433;#endif		} else {			/*			 * Preserve setting from the [global] section			 * of the configure file.			 */			ip_port = connection->port;		}		if ((env_port = getenv("TDSPORT")) != NULL) {			ip_port = tds_lookup_port(env_port);			tdsdump_log(TDS_DBG_INFO1, "Setting 'ip_port' to %s from $TDSPORT.\n", env_port);		} else			tdsdump_log(TDS_DBG_INFO1, "Setting 'ip_port' to %d as a guess.\n", ip_port);		/*		 * lookup the host		 */		tds_lookup_host(server, ip_addr);		if (ip_addr[0])			tds_dstr_copy(&connection->ip_addr, ip_addr);		if (ip_port)			connection->port = ip_port;	}}/** * Check the server name to find port info first * Warning: connection-> & login-> are all modified when needed * \return 1 when found, else 0 */static intparse_server_name_for_port(TDSCONNECTION * connection, TDSLOGIN * login){	const char *pSep;	const char *server;	/* seek the ':' in login server_name */	server = tds_dstr_cstr(&login->server_name);	pSep = strrchr(server, ':');	if (pSep && pSep != server) {	/* yes, i found it! */		/* modify connection-> && login->server_name & ->port */		login->port = connection->port = atoi(pSep + 1);		tds_dstr_copy(&connection->instance_name, "");	} else {		/* handle instance name */		pSep = strrchr(server, '\\');		if (!pSep || pSep == server)			return 0;		login->port = connection->port = 0;		tds_dstr_copy(&connection->instance_name, pSep + 1);	}	tds_dstr_setlen(&login->server_name, pSep - server);	if (!tds_dstr_dup(&connection->server_name, &login->server_name))		return 0;	return 1;}/** * Return a structure capturing the compile-time settings provided to the * configure script.   */const TDS_COMPILETIME_SETTINGS *tds_get_compiletime_settings(void){	static const TDS_COMPILETIME_SETTINGS settings = {		  TDS_VERSION_NO		, FREETDS_SYSCONFDIR		, "unknown"	/* need fancy script in makefile */#		ifdef MSDBLIB			, 1#		else			, 0#		endif#		ifdef TDS_SYBASE_COMPAT			, 1#		else			, 0#		endif#		ifdef _REENTRANT			, 1#		else			, 0#		endif#		ifdef HAVE_ICONV			, 1#		else			, 0#		endif#		ifdef TDS46			, "4.6"#		else#		ifdef TDS50			, "5.0"#		else#		ifdef TDS70			, "7.0"#		else#		ifdef TDS80			, "8.0"#		else			, "4.2"#		endif#		endif#		endif#		endif#		ifdef IODBC			, 1#		else			, 0#		endif#		ifdef UNIXODBC			, 1#		else			, 0#		endif	};	assert(settings.tdsver);	return &settings;}/** @} */

⌨️ 快捷键说明

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