#define SERVER_PORT_NUM 5002
#define REQUEST_MSG_SIZE 1024
struct request
{
int display;
char message[REQUEST_MSG_SIZE];
};
#include "vxworks.h"
#include "sockLib.h"
#include "inetLib.h"
#include "stdioLib.h"
#include "strLib.h"
#include "hostLib.h"
#include "ioLib.h"
STATUS udpServer()
{
struct sockaddr_in serverAddr;
struct sockaddr_in clientAddr;
struct request clientRequest;
int sockAddrSize_s;
int sockAddrSize_c;
int sFd;
char inetAddr[1024];
sockAddrSize_s=sizeof(struct sockaddr_in);
sockAddrSize_c=sizeof(struct sockaddr_in);
printf("size =%d\n",sockAddrSize_c);
bzero((char*)&serverAddr,sockAddrSize_s);
/*serverAddr.sin_len=(u_char)sockAddrSize_s;*/
serverAddr.sin_family=AF_INET;
serverAddr.sin_port=htons(SERVER_PORT_NUM);
serverAddr.sin_addr.s_addr=inet_addr("0.0.0.0");
if((sFd=socket(AF_INET,SOCK_DGRAM,0))==ERROR)
{
perror("error in create server socket!\n");
return(ERROR);
}
bind(sFd,(struct sockaddr*)&serverAddr,sockAddrSize_s);
printf("waitting...\n");
for(;;)
{
recvfrom(sFd,(char*)&clientRequest,sizeof(clientRequest),0,(struct sockaddr*)&clientAddr,&sockAddrSize_c);
if(clientRequest.display)
{
inet_ntoa_b(clientAddr.sin_addr,inetAddr);
printf("MSG FROM CLIENT (internet address %s ,port %d):\n%s\n",inet_ntoa(clientAddr.sin_addr),ntohs(clientAddr.sin_port),clientRequest.message);
}
}
}
服务器是在目标机上运行的,目标机的IP是:169.254.43.254,主机(客户端)是:169.254.43.215,
但是通过recvfrom得到的IP地址却是169.254.43.254,而不是169.254.43.215???请教大家了,忙了一下午都没解决这个问题。谢谢了!!!
繁花不似锦
慕森王