www.pudn.com > MyFtpServ.rar > util.h


/*---------------------------------------------------- 
	util.h -- myFtpServ Program 
			     ZhuJiaJun,2002 
  ----------------------------------------------------*/ 
 
#ifndef __UTIL_H 
#define __UTIL_H 
 
#include  
#include "typedef.h" 
 
/*---------------------------------------------------- 
	function claim  
  ----------------------------------------------------*/ 
void EditPrintf (HWND hwndEdit, TCHAR * szFormat, ...); 
int Io_Send(SOCKET sock, char *info, ...); 
int Io_Recv(SOCKET sock, char *buf, int size, int min); 
//将字符串中多余的控制字符去掉 
void Convert_Str(char *buf); 
//将字符串数组清零 
void bZero_Str(char *buf); 
 
//从客户端返回的PORT命令的字符串中得到客户的数据端口 
short int Get_Port(char *buf); 
 
/*---------------------------------------------------- 
	function define 
  ----------------------------------------------------*/ 
void EditPrintf (HWND hwndEdit, TCHAR * szFormat, ...) 
{ 
     TCHAR   szBuffer [1024] ; 
     va_list pArgList ; 
 
     va_start (pArgList, szFormat) ; 
     wvsprintf (szBuffer, szFormat, pArgList) ; 
     va_end (pArgList) ; 
 
     SendMessage (hwndEdit, EM_SETSEL, (WPARAM) -1, (LPARAM) -1) ; 
     SendMessage (hwndEdit, EM_REPLACESEL, FALSE, (LPARAM) szBuffer) ; 
     SendMessage (hwndEdit, EM_SCROLLCARET, 0, 0) ; 
} 
 
int Io_Send(SOCKET sock, char *info, ...) 
{ 
	int		send_bytes; 
	char	buf[MAX_L_STR+1]; 
	va_list msg;	 
	 
	va_start (msg, info); 
	wvsprintf (buf, info, msg); 
	va_end (msg); 
 
	buf[MAX_L_STR] = '\0'; 
	 
	send_bytes = send(sock, &buf[0], strlen(buf), 0); 
	return send_bytes;	 
} 
 
int Io_Recv(SOCKET sock, char *buf, int size, int min) 
{ 
	int iError; 
	iError = recv(sock, buf, size, 0); 
	return iError;	 
} 
 
void Convert_Str(char *buf) 
{ 
	*(buf+strlen(buf)-1) = '\0'; 
	*(buf+strlen(buf)-1) = '\0'; 
} 
 
void bZero_Str(char *buf) 
{ 
	register int i = 0; 
	while(buf[i] != '\0') 
		buf[i++] = '\0';	 
} 
 
//从客户端返回的PORT命令的字符串中得到客户的数据端口 
//例如: PORT 10,111,20,169,4,254\r\n 
//那么客户的数据端口为: 4*256+254 
//客户的ip为: 10.111.20.169  
short int Get_Port(char *buf) 
{ 
	char *last_dot; 
	short int a, b, port; 
 
	last_dot = strrchr(buf,','); 
	Convert_Str(last_dot+1); 
	a = atoi(last_dot+1); 
	b = *(last_dot-1)-48; 
	port = b*256+a; 
 
	return port; 
} 
 
#endif	/* util.h */