当前位置: 技术问答>linux和unix
linux inet_ntoa()函数返回值问题
来源: 互联网 发布时间:2016-07-09
本文导语: 本人写代码于下: #include #include #include #include #include #include typedef struct _nvdContent { unsigned char nvdFlag; char content[512]; } NvdContent; int main() { int sockfd,n; struct sockaddr_in servaddr,froma...
本人写代码于下:
#include
#include
#include
#include
#include
#include
typedef struct _nvdContent {
unsigned char nvdFlag;
char content[512];
} NvdContent;
int main()
{
int sockfd,n;
struct sockaddr_in servaddr,fromaddr;
socklen_t len;
char buf[1024],string[1024], temp[1024], *pChar;
NvdContent nvdBuf;
int option=1, tmp=0xFFFFFFFF;
unsigned int i;
fd_set rset, wset;
struct timeval tval;
int file;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if(sockfd==-1){printf("flasfjn");return -1;}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(55566);
memcpy((void*)&servaddr.sin_addr, (void*)&tmp, 4);
char *b= inet_ntoa(fromaddr.sin_addr); printf("*b is %dn",b);
printf("b is %sn",b);
#ifdef BEN_DEBUG
printf("##########fromaddr.sin_addr is %s+++++++++++++++n",inet_ntoa(fromaddr.sin_addr));
#endif
int a;
a=setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,&option, sizeof(option));
if(a==-1){printf("flasfjn");return -1;}
while(1)
{
sleep(1);
strcpy(buf,"hellon");
len=sizeof(servaddr);
n=sendto(sockfd,buf,1024,0,(struct sockaddr *)&servaddr,len);
len=sizeof(fromaddr);
FD_ZERO(&rset);
FD_SET(sockfd, &rset);
wset = rset;
tval.tv_sec = 1;
tval.tv_usec = 0; //timeout is 2 seconds
#ifdef BEN_DEBUG
printf("##########fromaddr.sin_addr is %s+++++++++++++++n",inet_ntoa(fromaddr.sin_addr));
#endif
if (select(sockfd + 1, &rset, NULL, NULL, &tval )
#include
#include
#include
#include
#include
#include
typedef struct _nvdContent {
unsigned char nvdFlag;
char content[512];
} NvdContent;
int main()
{
int sockfd,n;
struct sockaddr_in servaddr,fromaddr;
socklen_t len;
char buf[1024],string[1024], temp[1024], *pChar;
NvdContent nvdBuf;
int option=1, tmp=0xFFFFFFFF;
unsigned int i;
fd_set rset, wset;
struct timeval tval;
int file;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if(sockfd==-1){printf("flasfjn");return -1;}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(55566);
memcpy((void*)&servaddr.sin_addr, (void*)&tmp, 4);
char *b= inet_ntoa(fromaddr.sin_addr); printf("*b is %dn",b);
printf("b is %sn",b);
#ifdef BEN_DEBUG
printf("##########fromaddr.sin_addr is %s+++++++++++++++n",inet_ntoa(fromaddr.sin_addr));
#endif
int a;
a=setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST,&option, sizeof(option));
if(a==-1){printf("flasfjn");return -1;}
while(1)
{
sleep(1);
strcpy(buf,"hellon");
len=sizeof(servaddr);
n=sendto(sockfd,buf,1024,0,(struct sockaddr *)&servaddr,len);
len=sizeof(fromaddr);
FD_ZERO(&rset);
FD_SET(sockfd, &rset);
wset = rset;
tval.tv_sec = 1;
tval.tv_usec = 0; //timeout is 2 seconds
#ifdef BEN_DEBUG
printf("##########fromaddr.sin_addr is %s+++++++++++++++n",inet_ntoa(fromaddr.sin_addr));
#endif
if (select(sockfd + 1, &rset, NULL, NULL, &tval )