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

📄 wigclient.c

📁 tornado2.0 for PPC VxWorks socket 源代码
💻 C
字号:

#ifdef	__cplusplus
extern "C"{
#endif

#include <vxWorks.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysLib.h>
#include "wigtest.h"
#include <sockLib.h>
#include <socklib.h>
#include <ioLib.h >
#include <socket.h>
#include <sysLib.h>
#include <logLib.h>
#include <errno.h>
#include <string.h>
#include "wdLib.h"
#include "in.h"		
#include "ioLib.h"
#include "arpa/inet.h"
#include "inetlib.h"



struct sockaddr_in	stSin;
int    nSockClientfd = 0;
char   *szpBuffer = 	NULL;
int nWriteLenth = 0;
int nSendLength = 0;	

int socketclient
(
 char    *stpTargetAddr, /* targetAddress is the IP address of destination */
                            /*target that needs to be blasted */
 int	    nPort,       /* port number to send to */
 int      nSize,       /* size of the message to be sent */
 int      nBlen        /* maximum size of socket-level send szpBuffer */
)
{

   memset (&stSin, '\0',sizeof( stSin) );
   

   if (nSockClientfd < 0)
        {
					perror ("client cannot open socket");
        	exit (1);
        }
        
    stSin.sin_family 	= AF_INET;
    stSin.sin_addr.s_addr	= inet_addr (stpTargetAddr);
    stSin.sin_port	= htons (nPort);
    
  if ((szpBuffer = (char *) malloc (sizeof(char) * 10)) == NULL)
	{
		perror ("client cannot allocate szpBuffer of size ");
		exit (1);
	}
	
	nSockClientfd = socket (AF_INET, SOCK_STREAM, 0);
	 if (setsockopt (nSockClientfd, SOL_SOCKET, SO_SNDBUF, (char *)&nBlen, sizeof (nBlen)) < 0)
	{
		perror ("client setsockopt SO_SNDBUF failed");
		free (szpBuffer);
		exit (1);
	}
	
	  if (connect (nSockClientfd, (struct sockaddr  *)&stSin, sizeof (stSin)) < 0)
	{
    perror ("client connect failed");
    printf ("host %s port %d\n", inet_ntoa (stSin.sin_addr),
		ntohs (stSin.sin_port));
		free (szpBuffer);
		exit (1);
	}
	
	for (;;)
	{			
		while (1)
		{
			if ((nSendLength = write(nSockClientfd, szpBuffer, 1)) < 0)
			    {
				    perror ("blaster write error");
				    break;
			    }			   
		} 		
		nSendLength += nWriteLenth;
		if (nSendLength == nSize)
			break;		    
	}
	    
	 close (nSockClientfd);
	 free (szpBuffer);
	 printf ("blaster exit.\n");
	 
	 return 0x55;
	
}




#ifdef	__cplusplus
}
#endif	/* end of __cplusplus */

⌨️ 快捷键说明

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