事先请参阅Wind River Network Stack for VxWorks 6 Programmer's Guide, 6.6的文档!里面的文档说的很详细!

FTP Server

The parameters used to configure the FTP server in Workbench are described in Table 2-9. Authentication callback routine FTPS_AUTH_CALLBACK_HOOK You can use your own routine to authenticate clients. To do this, specify a function pointer for the FTPS_AUTH_CALLBACK_HOOK. The FTP server will call this routine to authenticate clients.

The prototype for this routine is as follows:


int myAuthenticateCallback (Ipftps_session * session, char * password);

It should return 0 (zero) if the password is valid for the session, or 1 (one) if you cannot validate the password. If you do not specify an authentication routine, the server will call its own default authentication callback routine that allows read-only access to the user anonymous with no password.

If you set a function pointer here, you must also set the FTPS_INSTALL_CALLBACK_HOOK to TRUE in order to install this callback hook.


FTPS_INSTALL_CALLBACK_HOOK FALSE

Indicates whether the FTP server uses the authentication callback routine that you specified by the configuration parameter FTPS_AUTH_CALLBACK_HOOK to authenticate clients.

If this is FALSE, the server instead uses its own authentication routine—one that allows the user anonymous with no password.

修改后就是如下面显示:

下载地址

Files:
Date 2022-02-22
File Size 564.78 KB
Download 103

VxWorks 6.9 配置多网口


#include "vxWorks.h"
#include "sockLib.h"
#include "inetLib.h"
#include "stdioLib.h"
#include "strLib.h"
#include "hostLib.h"
#include "ioLib.h"
//#include "tcpExample.h"

#define SERVER_PORT_NUM 5001
#define SERVER_WORK_PRIORITY 100
#define SERVER_STACT_SIZE 10000
#define SERVER_MAX_CONNECTIONS 4
#define REQUEST_MSG_SIZE 1024
#define REPLY_MSG_SIZE 500
#define ERROR (-1)

int tcp_server(void)
{
	struct sockaddr_in serverAddr;
	struct sockaddr_in clientAddr;
	char rcvBuf[REQUEST_MSG_SIZE];
	int sockAddrSize;
	int sFd;
	int newFd;
	int nByte;

	//1 create socket
	if((sFd = socket(AF_INET, SOCK_STREAM, 0)) == ERROR)
	{
		printf("create socket error!\n");
		return ERROR;
	}
	
	//2 init some parameter
	sockAddrSize=sizeof(struct sockaddr_in);
	bzero((char *)&serverAddr, sockAddrSize);
	serverAddr.sin_family = AF_INET;
	serverAddr.sin_port = htons(SERVER_PORT_NUM);
	serverAddr.sin_addr.s_addr=htonl(INADDR_ANY);
	serverAddr.sin_len=(unsigned char)sockAddrSize;
	
	//3 bind socket
	if(bind(sFd,(struct sockaddr*)(&serverAddr),sockAddrSize)== ERROR)
	{
		printf("bind error!\n");
		close(sFd);
		return ERROR;
	}

	//3 listen client
	if(listen(sFd,SERVER_MAX_CONNECTIONS) == ERROR)
	{
		printf("listen error!\n");
		close(sFd);
		return ERROR;
	}	
        //下面可以使用死循环或线程创建accept,并创建相对应的接收线程
	//4.accept server
	newFd = accept(sFd,(struct sockaddr*)(&clientAddr),&sockAddrSize);
	printf("server get connection from %s\n",inet_ntoa(clientAddr.sin_addr));
			
	while(1)
	{

		//5.receive
		nByte = recv(newFd, rcvBuf, REQUEST_MSG_SIZE, 0);//收不到数据阻塞
		rcvBuf[nByte] = '\0';
		printf("server received datas : %s\n", rcvBuf);
		
		if(rcvBuf[0]=='q')
			break;
	}	
	//6.close *Fd
	close(newFd);
	close(sFd);
	
	return 0;
	
}	

int tcp_client(char * serverName)
{
	struct sockaddr_in serverAddr;
	char sendBuf[REQUEST_MSG_SIZE];
	int sockAddrSize;
	int sFd;

	//1 create socket
	if((sFd = socket(AF_INET, SOCK_STREAM, 0)) == ERROR)
	{
		printf("create socket error!\n");
		return ERROR;
	}
	
	//2 init some parameter
	sockAddrSize=sizeof(struct sockaddr_in);
	bzero((char *)&serverAddr, sockAddrSize);
	serverAddr.sin_family = AF_INET;
	serverAddr.sin_port = htons(SERVER_PORT_NUM);
	serverAddr.sin_len=(unsigned char)sockAddrSize;

	if((serverAddr.sin_addr.s_addr = inet_addr(serverName))== ERROR &&
	   (serverAddr.sin_addr.s_addr = hostGetByName(serverName)) == ERROR)
	{
		printf("unknown serverName\n");
		close(sFd);
		return ERROR;
	}
	//3 connnect server
	if(connect(sFd,(struct sockaddr*)(&serverAddr),sockAddrSize) == ERROR)
	{
		printf("connect error\n");
		return ERROR;
	}
	
	//4:send datas to server
	printf("please input chars:\n");

	//send(sFd,sendBuf, strlen(sendBuf), 0);
	while(1){
		fgets(sendBuf,REQUEST_MSG_SIZE,stdin);	
		write(sFd,sendBuf, strlen(sendBuf));
		if(sendBuf[0] == 'q')
			break;
	}
	//5 close sFd
	close(sFd);
	
	return 0;
}

VxWorks Telnet Client Source Code

telnet client连接过程:

  • TCP连接telnet server 23端口
  • NVT扩展自动协商
  • 用户名+密码登录
  • 通过telnet server端命令行交互
  • 退出登录

概述

Telnet 协议是 TCP/IP 协议族中应用最广泛的协议。

它允许用户(Telnet 客户端)通过一个协商过程来与一个远程设备进行通信。

Telnet 协议是基于网络虚拟终端 NVT(Network Virtual Termina1)的实现,NVT 是虚拟设备,连接双方(客户机和服务器)都必须把它们的物理终端和 NVT 进行相互转换。

操作协商

只要客户机或服务器要发送命令序列而不是数据流,它就在数据流中插入一个特殊的保留字符,该保留字符叫做“解释为命令”(IAC ,Interpret As Command) 字符。当接收方在一个入数据流中发现 IAC 字符时,它就把后继的字节处理为一个命令序列。

双方在进行Telnet连接时,要进行选项协商。

比如:使用字符方式、窗口的大小,终端的类型都要进行协商。而协商是通过TELNET所支持的命令来实现的。

协商完成,telnet server才返回登录信息,否则无法登录。

本文协商过程通过程序的一个函数实现自动化。

VxWorks下telnet client实现代码

VxWorks UDP Socket Source Code

UDP为应用程序提供了一种无需建立连接就可以发送封装的IP数据包的方法。UDP是OSI参考模型中一种无连接的传输层协议,它主要用于不要求分组顺序到达的传输中,分组传输顺序的检查与排序由应用层完成,提供面向事务的简单不可靠信息传送服务。UDP协议基本上是IP协议与上层协议的接口。UDP协议适用端口分别运行在同一台设备上的多个应用程序。

UDP提供了无连接通信,且不对传送数据包进行可靠性保证,适合于一次传输少量数据,UDP传输的可靠性由应用层负责。

UDP Server socket通信过程:

  • 创建套接字
  • 绑定套接字
  • 收发数据
  • 关闭套接字

UDP Client socket通信过程:

  • 创建套接字
  • 收发数据
  • 关闭套接字