亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ping.c

?? linux集群服務器軟件代碼包
?? C
字號:
/* $Id: ping.c,v 1.37 2004/10/24 13:00:13 lge Exp $ *//* * ping.c: ICMP-echo-based heartbeat code for heartbeat. * * Copyright (C) 2000 Alan Robertson <alanr@unix.sh> * * The checksum code in this file code was borrowed from the ping program. * * SECURITY NOTE:  It would be very easy for someone to masquerade as the * device that you're pinging.  If they don't know the password, all they can * do is echo back the packets that you're sending out, or send out old ones. * This does mean that if you're using such an approach, that someone could * make you think you have quorum when you don't during a cluster partition. * The danger in that seems small, but you never know ;-) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. *  * This library 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 * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * */#include <portability.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <errno.h>#include <string.h>#include <ctype.h>#include <fcntl.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/param.h>#ifdef HAVE_NETINET_IN_H#include <netinet/in.h>#endif /* HAVE_NETINET_IN_H */#ifdef HAVE_NETINET_IN_SYSTM_H#	include <netinet/in_systm.h>#endif /* HAVE_NETINET_IN_SYSTM_H */#ifdef HAVE_NETINET_IP_VAR_H#	include <netinet/ip_var.h>#endif /* HAVE_NETINET_IP_VAR_H */#ifdef HAVE_NETINET_IP_FW_H#	include <netinet/ip_fw.h>#endif /* HAVE_NETINET_IP_FW_H */#ifdef HAVE_NETINET_IP_H#	include <netinet/ip.h>#endif /* HAVE_NETINET_IP_H */#include <netinet/ip_icmp.h>#ifdef HAVE_NETINET_IP_COMPAT_H#	include <netinet/ip_compat.h>#endif /* HAVE_NETINET_IP_COMPAT_H */#include <net/if.h>#include <arpa/inet.h>#include <netdb.h>#include <heartbeat.h>#include <HBcomm.h>#ifdef linux#	define	ICMP_HDR_SZ	sizeof(struct icmphdr)	/* 8 */#else#	define	ICMP_HDR_SZ	8#endif#define PIL_PLUGINTYPE          HB_COMM_TYPE#define PIL_PLUGINTYPE_S        HB_COMM_TYPE_S#define PIL_PLUGIN              ping#define PIL_PLUGIN_S            "ping"#define PIL_PLUGINLICENSE	LICENSE_LGPL#define PIL_PLUGINLICENSEURL	URL_LGPL#include <pils/plugin.h>struct ping_private {        struct sockaddr_in      addr;   	/* ping addr */        int    			sock;		/* ping socket */	int			ident;		/* heartbeat pid */	int			iseq;		/* sequence number */};static struct hb_media*	ping_new (const char* interface);static int		ping_open (struct hb_media* mp);static int		ping_close (struct hb_media* mp);static void*		ping_read (struct hb_media* mp, int* lenp);static int		ping_write (struct hb_media* mp, void* p, int len);static struct ping_private *			new_ping_interface(const char * host);static int		in_cksum (u_short * buf, size_t nbytes);static int		ping_mtype(char **buffer);static int		ping_descr(char **buffer);static int		ping_isping(void);#define		ISPINGOBJECT(mp)	((mp) && ((mp)->vf == (void*)&pingOps))#define		PINGASSERT(mp)	g_assert(ISPINGOBJECT(mp))static struct hb_media_fns pingOps ={	ping_new,	/* Create single object function */	NULL,		/* whole-line parse function */	ping_open,	ping_close,	ping_read,	ping_write,	ping_mtype,	ping_descr,	ping_isping,};PIL_PLUGIN_BOILERPLATE2("1.0", Debug)static const PILPluginImports*  PluginImports;static PILPlugin*               OurPlugin;static PILInterface*		OurInterface;static struct hb_media_imports*	OurImports;static void*			interfprivate;#define LOG	PluginImports->log#define MALLOC	PluginImports->alloc#define STRDUP  PluginImports->mstrdup#define FREE	PluginImports->mfreePIL_rcPIL_PLUGIN_INIT(PILPlugin*us, const PILPluginImports* imports);PIL_rcPIL_PLUGIN_INIT(PILPlugin*us, const PILPluginImports* imports){	/* Force the compiler to do a little type checking */	(void)(PILPluginInitFun)PIL_PLUGIN_INIT;	PluginImports = imports;	OurPlugin = us;	/* Register ourself as a plugin */	imports->register_plugin(us, &OurPIExports);  	/*  Register our interface implementation */ 	return imports->register_interface(us, PIL_PLUGINTYPE_S	,	PIL_PLUGIN_S	,	&pingOps	,	NULL		/*close */	,	&OurInterface	,	(void*)&OurImports	,	interfprivate); }static intping_mtype(char **buffer) { 	*buffer = STRDUP(PIL_PLUGIN_S);	if (!*buffer) {		return 0;	}	return strlen(*buffer);}static intping_descr(char **buffer) { 	*buffer = STRDUP("ping membership");	if (!*buffer) {		return 0;	}	return strlen(*buffer);}/* Yes, a ping device */static intping_isping(void) {	return 1;}static struct ping_private *new_ping_interface(const char * host){	struct ping_private*	ppi;	struct sockaddr_in *to;	if ((ppi = (struct ping_private*)MALLOC(sizeof(struct ping_private)))	== NULL) {		return NULL;	}	memset(ppi, 0, sizeof (*ppi));  	to = &ppi->addr;#ifdef HAVE_SOCKADDR_IN_SIN_LEN	ppi->addr.sin_len = sizeof(struct sockaddr_in);#endif	ppi->addr.sin_family = AF_INET;	if (inet_pton(AF_INET, host, (void *)&ppi->addr.sin_addr) <= 0) {		struct hostent *hep;		hep = gethostbyname(host);		if (hep == NULL) {			PILCallLog(LOG, PIL_CRIT, "unknown host: %s: %s"			,	host, strerror(errno));			FREE(ppi); ppi = NULL;			return NULL;		}		ppi->addr.sin_family = hep->h_addrtype;		memcpy(&ppi->addr.sin_addr, hep->h_addr, hep->h_length);	}	ppi->ident = getpid() & 0xFFFF;	return(ppi);}/* *	Create new ping heartbeat object  *	Name of host is passed as a parameter */static struct hb_media *ping_new(const char * host){	struct ping_private*	ipi;	struct hb_media *	ret;	char * 			name;	ipi = new_ping_interface(host);	if (ipi == NULL) {		return(NULL);	}	ret = (struct hb_media *) MALLOC(sizeof(struct hb_media));	if (ret == NULL) {		FREE(ipi); ipi = NULL;		return(NULL);	}	ret->pd = (void*)ipi;	name = STRDUP(host);	if(name == NULL) {		FREE(ipi); ipi = NULL;		FREE(ret); ret = NULL;		return(NULL);	}	ret->name = name;	add_node(host, PINGNODE_I);	return(ret);}/* *	Close UDP/IP broadcast heartbeat interface */static intping_close(struct hb_media* mp){	struct ping_private * ei;	int	rc = HA_OK;	PINGASSERT(mp);	ei = (struct ping_private *) mp->pd;	if (ei->sock >= 0) {		if (close(ei->sock) < 0) {			rc = HA_FAIL;		}	}	return(rc);}/* * Receive a heartbeat ping reply packet. */static void *ping_read(struct hb_media* mp, int *lenp){	struct ping_private *	ei;	union {		char		cbuf[MAXLINE+ICMP_HDR_SZ];		struct ip	ip;	}buf;	const char *		bufmax = ((char *)&buf)+sizeof(buf);	char *			msgstart;	int			addr_len = sizeof(struct sockaddr);   	struct sockaddr_in	their_addr; /* connector's addr information */	struct ip *		ip;	struct icmp		icp;	int			numbytes;	int			hlen;	struct ha_msg *		msg;	const char 		*comment;	char			*pkt;	int			pktlen;		PINGASSERT(mp);	ei = (struct ping_private *) mp->pd;		if ((numbytes=recvfrom(ei->sock, (void *) &buf.cbuf	,	sizeof(buf.cbuf)-1, 0,	(struct sockaddr *)&their_addr	,	&addr_len)) < 0) {		if (errno != EINTR) {			PILCallLog(LOG, PIL_CRIT, "Error receiving from socket: %s"			,	strerror(errno));		}		return NULL;	}	/* Avoid potential buffer overruns */	buf.cbuf[numbytes] = EOS;	/* Check the IP header */	ip = &buf.ip;	hlen = ip->ip_hl * 4;	if (numbytes < hlen + ICMP_MINLEN) {		PILCallLog(LOG, PIL_WARN, "ping packet too short (%d bytes) from %s"		,	numbytes		,	inet_ntoa(*(struct in_addr *)		&		their_addr.sin_addr.s_addr));		return NULL;	}		/* Now the ICMP part */	/* (there may be a better way...) */	memcpy(&icp, (buf.cbuf + hlen), sizeof(icp));		if (icp.icmp_type != ICMP_ECHOREPLY || icp.icmp_id != ei->ident) {		return NULL;	}	if (DEBUGPKT) {		PILCallLog(LOG, PIL_DEBUG, "got %d byte packet from %s"		,	numbytes, inet_ntoa(their_addr.sin_addr));	}	msgstart = (buf.cbuf + hlen + ICMP_HDR_SZ);	if (DEBUGPKTCONT && numbytes > 0) {		PILCallLog(LOG, PIL_DEBUG, "%s", msgstart);	}		pktlen = numbytes - hlen - ICMP_HDR_SZ;	if ((pkt = ha_malloc(pktlen + 1)) == NULL) {		return NULL;	}		pkt[pktlen] = 0;		memcpy(pkt, buf.cbuf + hlen + ICMP_HDR_SZ, pktlen);		*lenp = pktlen + 1; 		msg = wirefmt2msg(msgstart, bufmax - msgstart);	if (msg == NULL) {                ha_free(pkt);		return(NULL);	}	comment = ha_msg_value(msg, F_COMMENT);	if (comment == NULL || strcmp(comment, PIL_PLUGIN_S)) {                ha_free(pkt);		ha_msg_del(msg);		return(NULL);	}		ha_msg_del(msg);	/* return(msg); */		return(pkt);}/* * Send a heartbeat packet over broadcast UDP/IP interface * * The peculiar thing here is that we don't send the packet we're given at all * * Instead, we send out the packet we want to hear back from them, just * as though we were they ;-)  That's what comes of having such a dumb * device as a "member" of our cluster... * * We ignore packets we're given to write that aren't "status" packets. * */static intping_write(struct hb_media* mp, void *p, int len){	struct ping_private *	ei;	int			rc;	char*			pkt;	union{		char*			buf;		struct icmp		ipkt;	}*icmp_pkt;	size_t			size;	struct icmp *		icp;	size_t			pktsize;	const char *		type;	const char *		ts;	struct ha_msg *		nmsg;	struct ha_msg *		msg;			msg = wirefmt2msg(p, len);	if( !msg){		PILCallLog(LOG, PIL_CRIT, "ping_write(): cannot convert wirefmt to msg");		return(HA_FAIL);	}		PINGASSERT(mp);	ei = (struct ping_private *) mp->pd;	type = ha_msg_value(msg, F_TYPE);		if (type == NULL || strcmp(type, T_STATUS) != 0 	|| ((ts = ha_msg_value(msg, F_TIME)) == NULL)) {		ha_msg_del(msg);		return HA_OK;	}	/*	 * We populate the following fields in the packet we create:	 *	 * F_TYPE:	T_NS_STATUS	 * F_STATUS:	ping	 * F_COMMENT:	ping	 * F_ORIG:	destination name	 * F_TIME:	local timestamp (from "msg")	 * F_AUTH:	added by add_msg_auth()	 */	if ((nmsg = ha_msg_new(5)) == NULL) {		PILCallLog(LOG, PIL_CRIT, "cannot create new message");		ha_msg_del(msg);		return(HA_FAIL);	}	if (ha_msg_add(nmsg, F_TYPE, T_NS_STATUS) != HA_OK	||	ha_msg_add(nmsg, F_STATUS, PINGSTATUS) != HA_OK	||	ha_msg_add(nmsg, F_COMMENT, PIL_PLUGIN_S) != HA_OK	||	ha_msg_add(nmsg, F_ORIG, mp->name) != HA_OK	||	ha_msg_add(nmsg, F_TIME, ts) != HA_OK) {		ha_msg_del(nmsg); nmsg = NULL;		PILCallLog(LOG, PIL_CRIT, "cannot add fields to message");		ha_msg_del(msg);		return HA_FAIL;	}	if (add_msg_auth(nmsg) != HA_OK) {		PILCallLog(LOG, PIL_CRIT, "cannot add auth field to message");		ha_msg_del(nmsg); nmsg = NULL;		ha_msg_del(msg);		return HA_FAIL;	}		if ((pkt = msg2wirefmt(nmsg, &size)) == NULL)  {		PILCallLog(LOG, PIL_CRIT, "cannot convert message to string");		ha_msg_del(msg);		return HA_FAIL;	}	ha_msg_del(nmsg); nmsg = NULL;	pktsize = size + ICMP_HDR_SZ;	if ((icmp_pkt = MALLOC(pktsize)) == NULL) {		PILCallLog(LOG, PIL_CRIT, "out of memory");		ha_free(pkt);		ha_msg_del(msg);		return HA_FAIL;	}	icp = &(icmp_pkt->ipkt);	icp->icmp_type = ICMP_ECHO;	icp->icmp_code = 0;	icp->icmp_cksum = 0;	icp->icmp_seq = htons(ei->iseq);	icp->icmp_id = ei->ident;	/* Only used by us */	++ei->iseq;	memcpy(icp->icmp_data, pkt, size);	ha_free(pkt); pkt = NULL;	/* Compute the ICMP checksum */	icp->icmp_cksum = in_cksum((u_short *)icp, pktsize);	if ((rc=sendto(ei->sock, (void *) icmp_pkt, pktsize, 0	,	(struct sockaddr *)&ei->addr	,	sizeof(struct sockaddr))) != (ssize_t)pktsize) {		PILCallLog(LOG, PIL_CRIT, "Error sending packet: %s", strerror(errno));		FREE(icmp_pkt);		ha_msg_del(msg);		return(HA_FAIL);	}	if (DEBUGPKT) {		PILCallLog(LOG, PIL_DEBUG, "sent %d bytes to %s"		,	rc, inet_ntoa(ei->addr.sin_addr));   	}	if (DEBUGPKTCONT) {		PILCallLog(LOG, PIL_DEBUG, "ping pkt: %s", pkt);   	}	FREE(icmp_pkt);	ha_msg_del(msg);	return HA_OK;  }/* *	Open ping socket. */static intping_open(struct hb_media* mp){	struct ping_private * ei;	int sockfd;	struct protoent *proto;	PINGASSERT(mp);	ei = (struct ping_private *) mp->pd;	if ((proto = getprotobyname("icmp")) == NULL) {		PILCallLog(LOG, PIL_CRIT, "protocol ICMP is unknown: %s", strerror(errno));		return HA_FAIL;	}	if ((sockfd = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) {		PILCallLog(LOG, PIL_CRIT, "Can't open RAW socket.: %s", strerror(errno));		return HA_FAIL;    	}	if (fcntl(sockfd, F_SETFD, FD_CLOEXEC)) {		PILCallLog(LOG, PIL_CRIT, "Error setting the close-on-exec flag: %s"		,	strerror(errno));	}	ei->sock = sockfd;	PILCallLog(LOG, PIL_INFO, "ping heartbeat started.");	return HA_OK;}/* * in_cksum -- *	Checksum routine for Internet Protocol family headers (C Version) *	This function taken from Mike Muuss' ping program. */static intin_cksum (u_short *addr, size_t len){	size_t		nleft = len;	u_short *	w = addr;	int		sum = 0;	u_short		answer = 0;	/*	 * The IP checksum algorithm is simple: using a 32 bit accumulator (sum)	 * add sequential 16 bit words to it, and at the end, folding back all	 * the carry bits from the top 16 bits into the lower 16 bits.	 */	while (nleft > 1) {		sum += *w++;		nleft -= 2;	}	/* Mop up an odd byte, if necessary */	if (nleft == 1) {		sum += *(u_char*)w;	}	/* Add back carry bits from top 16 bits to low 16 bits */	sum = (sum >> 16) + (sum & 0xffff);	/* add hi 16 to low 16 */	sum += (sum >> 16);			/* add carry */	answer = ~sum;				/* truncate to 16 bits */	return answer;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91视频观看视频| 亚洲v中文字幕| 欧美婷婷六月丁香综合色| 国产欧美日韩精品一区| 激情五月婷婷综合| 2020日本不卡一区二区视频| 男女男精品视频| 精品国产凹凸成av人导航| 奇米综合一区二区三区精品视频| 欧美一区二区三区日韩| 日本不卡的三区四区五区| 欧美二区三区的天堂| 麻豆精品视频在线| 久久精品在线观看| 91丨国产丨九色丨pron| 亚洲曰韩产成在线| 欧美人与性动xxxx| 久久99久久久久久久久久久| 久久这里只有精品首页| 成人在线综合网站| 一区二区三区中文免费| 欧美人与禽zozo性伦| 国产九九视频一区二区三区| 国产精品理论片在线观看| 色94色欧美sute亚洲13| 午夜日韩在线电影| 欧美成人a∨高清免费观看| 成人精品高清在线| 亚洲第一激情av| 精品国产免费人成电影在线观看四季| 国产成人三级在线观看| 亚洲人成网站色在线观看| 欧美日韩电影一区| 国产美女一区二区| 亚洲黄色小视频| 精品国产一区二区亚洲人成毛片 | 99久久婷婷国产精品综合| 一区二区三区四区在线免费观看| 日韩一级精品视频在线观看| 播五月开心婷婷综合| 首页亚洲欧美制服丝腿| 中文字幕欧美三区| 91精品国产高清一区二区三区蜜臀| 色狠狠色狠狠综合| 国产一区二区三区精品视频 | 伊人色综合久久天天人手人婷| 日韩欧美一卡二卡| 色综合一区二区三区| 久久精品免费看| 亚洲午夜免费电影| 国产目拍亚洲精品99久久精品| 欧美精品 日韩| 91香蕉视频污| 国产一区二区三区四区在线观看| 婷婷六月综合网| 亚洲欧洲无码一区二区三区| 日韩三级电影网址| 在线观看91视频| 国产不卡在线视频| 久久99九九99精品| 亚洲成人资源在线| 亚洲欧美日韩中文播放| 久久只精品国产| 欧美一级二级在线观看| 欧美美女一区二区在线观看| 色婷婷综合视频在线观看| 国产精品66部| 国产精品影音先锋| 久久激情五月婷婷| 日韩不卡一区二区三区| 亚洲午夜精品久久久久久久久| 中文字幕一区三区| 中文字幕一区二区三区色视频| 欧美大片免费久久精品三p| 欧美猛男男办公室激情| 欧美在线高清视频| 在线影视一区二区三区| 91啦中文在线观看| 色一区在线观看| 92国产精品观看| 99久久精品情趣| 成人性生交大片免费看在线播放| 国产一区999| 国产99一区视频免费| 国产成人一区在线| 粉嫩蜜臀av国产精品网站| 国产99久久久国产精品| 国产91精品在线观看| 成人av资源网站| 99在线精品视频| 色噜噜夜夜夜综合网| 欧美性生活久久| 欧美日韩精品一二三区| 91 com成人网| 欧美成人一区二区三区在线观看| www国产成人| 国产精品久久久久久久浪潮网站| 中文字幕在线视频一区| 亚洲精品五月天| 午夜视频在线观看一区二区三区| 毛片av一区二区三区| 精品亚洲国产成人av制服丝袜| 国产精品中文字幕日韩精品| 丁香五精品蜜臀久久久久99网站| proumb性欧美在线观看| 色悠悠久久综合| 欧美日韩二区三区| 亚洲成人三级小说| 日韩av一级电影| 国产乱对白刺激视频不卡| www.欧美精品一二区| 欧美日韩国产天堂| 亚洲精品一区在线观看| 国产精品护士白丝一区av| 亚洲欧美日韩国产手机在线| 无码av中文一区二区三区桃花岛| 美女在线视频一区| 成人国产精品免费网站| 欧美在线观看你懂的| 久久综合久久鬼色中文字| 综合久久国产九一剧情麻豆| 香蕉乱码成人久久天堂爱免费| 狠狠色狠狠色综合系列| 色综合中文综合网| 国产二区国产一区在线观看| 色综合久久久久| 日韩精品一区二区三区四区视频| ...av二区三区久久精品| 日韩电影在线一区| 99r国产精品| 日韩精品一区二区三区老鸭窝| 亚洲女同ⅹxx女同tv| 精品在线观看视频| 在线观看一区不卡| 国产日韩精品一区二区三区| 亚洲成人久久影院| 成人福利电影精品一区二区在线观看| 91精品国产日韩91久久久久久| 国产精品麻豆视频| 青青草91视频| 欧美唯美清纯偷拍| 亚洲欧洲性图库| 国产福利一区二区三区在线视频| 欧美性大战久久久久久久蜜臀| 久久精品在这里| 久久国产人妖系列| 欧美日韩一区三区| 亚洲色图丝袜美腿| 国产传媒久久文化传媒| 91精品国产一区二区| 一区二区三区在线播放| 国产99久久久国产精品潘金| 日韩女优av电影| 丝袜美腿成人在线| 欧美日韩一区中文字幕| 一区二区三区精品在线观看| 高清不卡一区二区| 欧美精品一区二区三| 蜜臀av一级做a爰片久久| 欧美丝袜自拍制服另类| 欧美国产禁国产网站cc| 久久草av在线| 91麻豆精品国产91久久久| 一区二区三区不卡视频在线观看 | 亚洲国产精品一区二区尤物区| 99久久婷婷国产| 中文字幕一区二区三区四区| 国精产品一区一区三区mba视频 | 久久综合色之久久综合| 免费在线欧美视频| 欧美片网站yy| 亚洲福中文字幕伊人影院| 91黄色免费网站| 一区二区成人在线观看| 99精品视频在线观看免费| 国产午夜精品一区二区三区视频 | 日韩精品福利网| 欧美精品色综合| 婷婷开心久久网| 69堂亚洲精品首页| 日本 国产 欧美色综合| 国产精品色在线| 91网站最新网址| 一区二区三区日韩欧美精品| 在线观看亚洲精品| 日本伊人色综合网| 日韩免费视频一区二区| 狠狠狠色丁香婷婷综合激情| 精品国产1区二区| 国产成人精品在线看| 国产精品久久三| 色域天天综合网| 日本va欧美va瓶| 久久久99久久| 91视视频在线观看入口直接观看www | 色综合久久久久久久久久久| 亚洲国产成人精品视频| 91精品国产一区二区三区| 国产一区二区免费在线| 国产精品理论片在线观看|