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

📄 brocas.c

📁 飞鸽传书for linux X图形界面下源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * brocas.c - IP Messenger 1.20 protocol * Copyright (C) 1996, 1997 by Toshihiro Kanda. */char rcsid_brocas[] = "$Id: brocas.c,v 3.7 1997/05/02 05:47:43 candy Exp candy $";#include <ctype.h>#ifdef USE_VARARGS#include <varargs.h>#else#include <stdarg.h>#endif#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>#include <sys/time.h> /* setitimer() *//* includes below are order dependent */#include <sys/param.h> /* htons() */#include <sys/types.h> /* socket() */#include <sys/socket.h> /* socket() */#include <netinet/in.h> /* inet_addr() INADDR_ANY */#include <arpa/inet.h> /* inet_addr() */#ifdef SOCKS#include <socks.h>#endif#include "xipmsg.h"#include "kanji.h"#include "brocas.h"#ifdef BOGUS_REALLOC#undef realloc#define realloc(p,s) ((p)?((realloc)(p,s)):malloc(s))#endif#ifdef NO_SSIZE_T#define ssize_t int#endif#ifdef NO_MEMMOVE#define memmove(d,s,l) bcopy(s,d,l)#endif#include "dyna.h"#if defined BSD4_4#define SENDTO(s,msg,len,flags,to,tolen) sendto(s,msg,len,flags,to,tolen)#define SETSOCKOPT(s,level,optname,optval,optlen) setsockopt(s,level,optname,optval,optlen)#else#define SENDTO(s,msg,len,flags,to,tolen) sendto(s,msg,len,flags,(struct sockaddr *)to,tolen)#define SETSOCKOPT(s,level,optname,optval,optlen) setsockopt(s,level,optname,(char *)optval,optlen)#endifint debug_flag;static int bro_socket;static int bro_port;static char *bro_user; /* SJIS */static const char *bro_host;static int bro_disabled;static unsigned long bro_tic;char *myname;#define HH(s) ((int)(((s) % 86400)/3600))#define MM(s) ((int)(((s) % 3600)/60))#define SS(s) ((int)((s) % 60))/* * */static int#ifdef USE_VARARGSwarning(va_alist)va_dcl#elsewarning(const char *fmt, ...)#endif{	struct timeval tv;	va_list ap;#ifdef USE_VARARGS	const char *fmt;	va_start(ap);	fmt = va_arg(ap, const char *);#else	va_start(ap, fmt);#endif	gettimeofday(&tv, NULL);	fprintf(stderr, "%02d:%02d:%02d.%06lu ", HH(tv.tv_sec), MM(tv.tv_sec), SS(tv.tv_sec), tv.tv_usec);	vfprintf(stderr, fmt, ap);	va_end(ap);	return 0;}/* warning *//* * 矢机误を len バイト笆柒にコピ〖し、'\0' タ〖ミネ〖トする。 */char *strncpyz(char *dst, const char *src, size_t len){	strncpy(dst, src, len);	dst[len - 1] = '\0';	return dst;}/* strncpyz *//* * */static int#ifdef USE_VARARGSerror(va_alist)va_dcl#elseerror(const char *fmt, ...)#endif{	va_list ap;#ifdef USE_VARARGS	const char *fmt;	va_start(ap);	fmt = va_arg(ap, const char *);#else	va_start(ap, fmt);#endif	fprintf(stderr, "%s: ", myname);	vfprintf(stderr, fmt, ap);	fprintf(stderr, ": ");	perror(NULL);	va_end(ap);	return 0;}/* error *//* * 矢机误を malloc() して剩澜する。 * あとで free(3) してちょ。 */char *str_dup(const char *s){	char *p = malloc(strlen(s) + 1);	if (p != NULL)		strcpy(p, s);	return p;}/* str_dup *//* * 矢机误の n 改誊の ch の疤弥を手す。 * n == 1 なら strchr() と票じ。n == 0 なら NULL */char *strnchr(const char *s, int ch, size_t n){	if (n == 0)		s = NULL;	while (s != NULL && n-- != 0) {		s = strchr(s, ch);		if (s != NULL && *s != '\0' && n != 0)			s++;	}/* while */	return (char *)s;}/* strnchr *//* * 矢机误票晃を tolower() しながら孺秤する。 */intstrcmpi(const char *d_, const char *s_){	const unsigned char *d = (const unsigned char *)d_, *s = (const unsigned char *)s_;	int cp;	while ((cp = tolower(*d) - tolower(*s)) == 0 && *d != '\0') {		d++;		s++;	}/* while */	return cp;}/* strcmpi *//* * 矢机误票晃を tolower() しながら、墓くとも n バイト孺秤する。 */intstrncmpi(const char *d_, const char *s_, size_t n){	const unsigned char *d = (const unsigned char *)d_, *s = (const unsigned char *)s_;	int cp = 0;	while (n-- != 0 && (cp = tolower(*d) - tolower(*s)) == 0 && *d != '\0') {		d++;		s++;	}/* while */	return cp;}/* strcmpi *//* * 琐萨の鄂球矢机の误を痰くす。 */static char *strtrim(char *str){	char *p = strchr(str, '\0');	while (p-- != str && isascii(*p) && isspace(*p))		*p = '\0';	return str;}/* strtrim *//* * シフトJIS 矢机误を EUC にして剩澜する。 * あとで free(3) してちょ。 */static char *strstedup(const char *s){	size_t len = strstoelen(s);	char *p = malloc(len + 1);	if (p != NULL)		strstoe(p, s);	return p;}/* strstedup */#if 0 /* [ *//* * bit 事びを瓤啪させながらの memcpy */static unsigned char *rev_memcpy(void *d_, const void *s_, size_t n){	static unsigned char byte_rev[256] = {		0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 		0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0, 		0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 		0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8, 		0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 		0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4, 		0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 		0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc, 		0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 		0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2, 		0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 		0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa, 		0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 		0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6, 		0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 		0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe, 		0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 		0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1, 		0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 		0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9, 		0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 		0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5, 		0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 		0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd, 		0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 		0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3, 		0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 		0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb, 		0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 		0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7, 		0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 		0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff, 	};	int i;	unsigned char *d = d_;	const unsigned char *s = s_;	for (i = 0; i < n; i++)		*d++ = byte_rev[*s++];	return d_;}/* rev_memcpy */#endif /* ] *//* * EUC の 2 byte もじをぶった磊らないように、 column で猖乖する。 */static char *wrap_euc(char *d_, const char *s_, int column){	unsigned char *d = (unsigned char *)d_;	const unsigned char *s = (const unsigned char *)s_;	size_t c = 0;	while (*s != '\0') {		if (*s == '\n') {			*d++ = *s++;			c = 0;		}		else if (is1euc(*s)) {			if ((c + 2) > column) {				*d++ = '\n';				c = 0;			}			*d++ = *s++;			c++;			if (*s != '\0') {				*d++ = *s++;				c++;			}		}		else {			if ((c + 1) > column) {				*d++ = '\n';				c = 0;			}			*d++ = *s++;			c++;		}	}/* while */	*d = '\0';	return d_;}/* wrap_euc *//* * wrap_euc() する箕の墓さ。 */static size_twrap_euclen(const char *s_, int column){	size_t ins = 0, c = 0;	const unsigned char *s = (const unsigned char *)s_;	while (*s != '\0') {		if (*s == '\n') {			s++;			c = 0;		}		else if (is1euc(*s)) {			if ((c + 2) > column) {				ins++;				c = 0;			}			s++;			c++;			if (*s != '\0') {				s++;				c++;			}		}		else {			if ((c + 1) > column) {				ins++;				c = 0;			}			s++;			c++;		}	}/* while */	return strlen(s_) + ins;}/* wrap_euclen *//* * コ〖ルバック [ */struct bro_cb_t {	bro_callback_t cb_proc;	void *cb_closure;};struct bro_cb_t bro_cbacks[BRO_EV_MAX];/* * イベント e が弹きた箕のコ〖ルバックル〖チンと、 * クライアントデ〖タ closure を判峡する。 */intbro_add_callback(enum bro_event_t e, bro_callback_t callback, void *closure){	int err = -1;	if (e < BRO_EV_MAX) {		bro_cbacks[e].cb_proc = callback;		bro_cbacks[e].cb_closure = closure;		err = 0;	}	return err;}/* bro_add_callback *//* * イベント e に滦炳するコ〖ルバックル〖チンを钙び叫す。 */static intcall_cback(enum bro_event_t e, void *call_data){	int err = -1;	if (e < BRO_EV_MAX) {		bro_callback_t cback = bro_cbacks[e].cb_proc;		if (cback != NULL) {			cback(e, bro_cbacks[e].cb_closure, call_data);		}	}	return err;}/* call_cback *//* ] コ〖ルバック *//* * パケット浩流慨 [ */#define XQ_REXMT 2 /* 浩流する粗持 [500msec 帽疤] */#define XQ_KEEP 40 /* あきらめる箕粗 [500msec 帽疤] */struct xq_t {	struct xq_t *xq_next;	unsigned long xq_id; /* 急侍灰 */	int xq_so;	union saddr xq_saddr; 	void *xq_buf; /* malloc()'ed */	size_t xq_size;	int xq_keep; /* 0 になったら、あきらめる。 */	int xq_rexmt; /* 0 になったら、浩流慨する。 */	int xq_rexmt0;	int xq_givenup; /* あきらめたフラグ */};/* * 菇陇挛を介袋步する。 */static struct xq_t *xq_initone(struct xq_t *xq){	memset(xq, '\0', sizeof(*xq));	xq->xq_rexmt0 = XQ_REXMT;	xq->xq_rexmt = XQ_REXMT;	xq->xq_keep = XQ_KEEP;	return xq;}/* xq_initone */struct xq_t *xq_base; /* キュ〖 *//* * キュ〖に掐れる。 */struct xq_t *xq_enq(struct xq_t *xq){	xq->xq_next = xq_base;	xq_base = xq;	return xq;}/* xq_enq *//* * キュ〖から嘲す。 */static voidxq_deq(struct xq_t *dst){	if (dst != NULL) {		if (dst == xq_base) {			xq_base = dst->xq_next;		}		else {			struct xq_t *xq = xq_base;			while (xq != NULL && xq->xq_next != dst)				xq = xq->xq_next;			if (xq != NULL)				xq->xq_next = dst->xq_next;		}	}}/* xq_deq *//* * 急侍灰 id を积つエントリを玫す。 */static struct xq_t *xq_lookup(unsigned long id){	struct xq_t *xq = xq_base;	while (xq != NULL && xq->xq_id != id)		xq = xq->xq_next;	return xq;}/* xq_lookup *//* * パケット流慨する。 */

⌨️ 快捷键说明

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