个人刚开始接触VxWorks,想要利用FTP传输文件,FTP服务端是Windows,客户端是VxWorks(虚拟在与Windows同一台机器上),我在Windows上装了Serv-U,可以实现ftp服务器的功能了(利用cmd,可以与ftp服务器交互操作),但是VxWorks客户端跑起来,利用ftpXfer函数连接服务器时总是出错,我跟进汇编发现在ftpHookup里就错了,于是又跟进ftpHookup里,最后发现是connect函数出了问题,进入了EHOSTUNREACH分支,无法连接服务器,因此问题转化成了TCP连接时无法连接。
我就想问问:
1. 为什么连接不上服务器,参考以前的帖子,难道是因为我Windows上的IP,跟Simulator上的ip不一致,可是我用127.0.0.1也试了呀,也不行(用Windows下cmd命令倒是可以ping通本地IP);
2. 难道VxWorks中编的VIP中还有哪些configuration没有设置到,导致连接不上?(目前我加入了ftp client组件和DHCP组件);
3. 如果connect能够成功,那我利用simulator的ftp能够与Windows上的serv-U ftp服务器交换数据吗?
由于我是VwWorks新手,还请高手们不吝赐教,我贴出tcp连接部分的代码,大家帮忙看看吧
#include "VxWorks.h"
#include "stdio.h"
#include "errnoLib.h"
#include "ftpLib.h"
#include "ioLib.h"
#define HOST "169.254.128.31" //本机的IP,不一定是Simulator的IP
//问题在这里?????
#define USER "sa"
#define PWD "sa"
#define DIR "D:/SYS"
#define RD_CMD "RETR %s"
#define FILE "1.txt"
#include <inetLib.h>
#include <socket.h>
#include <inetLib.h>
#include <remLib.h>
typedef struct sockaddr_in SOCKADDR_IN;
int ftpTest()
{
FAST int ctrlSock;
FAST int inetAddr;
UINT32 retryCount = 0;
int a = 0;
SOCKADDR_IN ctrlAddr;
struct linger optVal;
int ctrlOptval;
if (((inetAddr = (int) inet_addr (HOST)) == ERROR))
{
return (ERROR);
}
ctrlSock = socket (AF_INET, SOCK_STREAM, 0);
if (ctrlSock < 0)
{
return (ERROR);
}
optVal.l_onoff = 1;
optVal.l_linger = 0;
if (setsockopt (ctrlSock, SOL_SOCKET, SO_LINGER, (char*)&optVal,
sizeof (optVal)) == ERROR)
{
close (ctrlSock);
return (ERROR);
}
ctrlOptval = 1;
if (setsockopt (ctrlSock, SOL_SOCKET, SO_KEEPALIVE, (char*)&ctrlOptval,
sizeof (ctrlOptval)) == ERROR)
{
close(ctrlSock);
return (ERROR);
}
ctrlAddr.sin_family = AF_INET;
ctrlAddr.sin_addr.s_addr = INADDR_ANY;
ctrlAddr.sin_port = htons (0);
ctrlAddr.sin_len = sizeof (struct sockaddr_in);
if (bind (ctrlSock, (struct sockaddr *)&ctrlAddr, sizeof (ctrlAddr)) < 0)
{
close (ctrlSock);
return (ERROR);
}
ctrlAddr.sin_addr.s_addr = inetAddr;
ctrlAddr.sin_port = htons (21);
for (;;)
{
//就在这句出现问题,connect始终无法成功
if (connect (ctrlSock, (struct sockaddr *)&ctrlAddr, sizeof (ctrlAddr)) < 0)
{
switch (errno)
{
case EHOSTUNREACH: //进入这个分支
a = 1;
case ENETUNREACH:
a = 2;
case ENETDOWN:
/* could be due to DHCP negotiation not complete, retry */
if (retryCount++ < 5)
{
a = 3;
continue;
}
default:
close (ctrlSock);
return (ERROR);
}
}