- 论坛徽章:
- 0
|
郁闷,aix5.2 xlc编译\r\n\r\n\r\ntest.c testclient.c \r\n\r\ntest.c编译没有问题。客户端提示错误见程序最后两行注释。请帮忙解决,谢谢!\r\n\r\n\r\ntest.c\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <errno.h>\r\n#include <string.h>\r\n#include <sys/types.h>\r\n#include <netinet/in.h>\r\n#include <sys/socket.h>\r\n#include <sys/wait.h>\r\n\r\n#define MYPORT 34900\r\n#define MAXBUFLEN 100\r\nmain()\r\n{\r\n int sockfd;\r\n struct sockaddr_in my_addr;\r\n struct sockaddr_in their_addr;\r\n int numbytes;\r\n unsigned long addr_len;\r\n char buf[MAXBUFLEN];\r\n if((sockfd=socket(AF_INET,SOCK_DGRAM,0))==-1){\r\n perror(\"socket\");\r\n exit(1);\r\n }\r\n my_addr.sin_family=AF_INET;\r\n my_addr.sin_port=htons(MYPORT);\r\n my_addr.sin_addr.s_addr=INADDR_ANY;\r\n bzero(&(my_addr.sin_zero));\r\n if(bind(sockfd,(struct sockaddr*)&my_addr,sizeof(struct sockaddr))==-1){\r\n perror(\"bind\");\r\n exit(1);\r\n }\r\n addr_len=sizeof(struct sockaddr);\r\n if((numbytes=recvfrom(sockfd,buf,MAXBUFLEN,0,(struct sockaddr*)&their_addr,&addr_len))==-1){\r\n perror(\"recvfrom\");\r\n exit(1);\r\n }\r\n printf(\"got packet from %s\\n\",inet_ntoa(their_addr.sin_addr));\r\n printf(\"packet is %d bytes long\\n\",numbytes);\r\n buf[numbytes]=\'\\0\';\r\n printf(\"packet contains \\\"%s\\\"\\n\",buf);\r\n close(sockfd);\r\n}\r\n\r\n\r\n\r\ntestclient.c\r\n\r\n\r\n#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <errno.h>\r\n#include <string.h>\r\n#include <sys/types.h>\r\n#include <netinet/in.h>\r\n#include <sys/socket.h>\r\n#include <sys/wait.h>\r\n#define MYPORT 34900\r\nint main(int argc,char *argv[])\r\n{\r\n int sockfd;\r\n struct sockaddr_in their_addr;\r\n struct hostent *he;\r\n int numbytes;\r\n if(argc !=3){\r\n fprintf(stderr,\"usage:talker hostname message\\n\");\r\n exit(1);\r\n }\r\n if((he->h_addr=gethostbyname(argv[1]))==NULL){\r\n herror(\"gethostbyname\");\r\n exit(1);\r\n }\r\n\r\n\r\n\r\n \r\n\r\n if((sockfd=socket(AF_INET,SOCK_DGRAM,0))==-1){\r\n perror(\"socket\");\r\n exit(1);\r\n }\r\n their_addr.sin_family=AF_INET;\r\n their_addr.sin_port=htons(MYPORT);\r\n \r\n their_addr.sin_addr=*((struct in_addr*)he->h_addr);\r\n // their_addr.sin_addr.s_addr=1721613926;\r\n\r\n bzero(&(their_addr.sin_zero));\r\n if((numbytes=sendto(sockfd,argv[2],strlen(argv[2]),0,(struct sockaddr*)&their_addr,sizeof(struct sockaddr)))==-1){\r\n perror(\"sendto\");\r\n exit(1);\r\n }\r\n printf(\"send %d bytes to %s\\n\",numbytes,inet_ntoa(their_addr.sin_addr));\r\n close(sockfd);\r\n return 0;\r\n}\r\n\r\n\r\n/*\r\nif ( phe = gethostbyname( uTcpIpAddr ) )\r\n memcpy( &serv_addr.sin_addr,\r\n phe->h_addr,phe->h_length );\r\n \r\n\"testclient.c\", line 20.13: 1506-285 (S) The indirection operator cannot be applied to a pointer to an incomplete struct or union.\r\n\"testclient.c\", line 30.56: 1506-285 (S) The indirection operator cannot be applied to a pointer to an incomplete struct or union.\r\n*/ |
|