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

📄 getdnsname.c

📁 这个程序实现了FLUTE协议
💻 C
字号:
/* $Author: peltotal $ $Date: 2006/02/17 08:07:16 $ $Revision: 1.2 $ *//* *   MAD-FLUTELIB: Implementation of FLUTE protocol. *   Copyright (c) 2003-2006 TUT - Tampere University of Technology *   main authors/contacts: jani.peltotalo@tut.fi and sami.peltotalo@tut.fi * *   This program is free software; you can redistribute it and/or modify *   it under the terms of the GNU General Public License as published by *   the Free Software Foundation; either version 2 of the License, or *   (at your option) any later version. * *   This program is distributed in the hope that it will be useful, *   but WITHOUT ANY WARRANTY; without even the implied warranty of *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with this program; if not, write to the Free Software *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "flute_inc.h"/* * This function returns DNS name for host. * * Params:	void * * Return:	char*: Pointer to buffer containing host's  DNS name,  *			NULL: In error cases. */char* getdnsname() {	char *hostname = NULL;	char host[MAX_PATH];	struct hostent *hptr;#ifdef WIN32    int d;    WSADATA ws;    d = WSAStartup(0x0202, &ws);#endif	memset(host, 0, MAX_PATH);    gethostname(host, MAX_PATH);    if((hptr = gethostbyname(host)) == NULL) {				if(!(hostname = (char*)calloc((strlen(host) + 1), sizeof(char)))) {			printf("Could not alloc memory for hostname!\n");			fflush(stdout);			return NULL;		}		memcpy(hostname, host, strlen(host));		return hostname;    } else {		memset(host, 0, MAX_PATH);        memcpy(host, hptr->h_name, strlen(hptr->h_name));	}	if(!(hostname = (char*)calloc((strlen(host) + 1), sizeof(char)))) {		printf("Could not alloc memory for hostname!\n");		fflush(stdout);		return NULL;	}	memcpy(hostname, host, strlen(host));        return hostname;}

⌨️ 快捷键说明

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