- 论坛徽章:
- 0
|
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netdb.h>
#include<netinet/in.h>
#include<errno.h>
#include<string.h>
#include<sys/wait.h>
#define MYPORT 5000
int main(int argc,char *argv[])
{
int sockfd;
struct sockaddr_in their_addr;
struct hosten *he;
int numbytes;
if(argc!=3)
{
fprintf(stderr,"usage :talker hostname message\n"
exit(1);
}
if((he=gethostbyname(argv[1]))==NULL)
{
herror("gethostbyname"
exit(1);
}
if((sockfd=socket(AF_INET,SOCK_DGRAM,0))==-1)
{
perror("socket"
exit(1);
}
their_addr.sin_family=AF_INET;
their_addr.sin_port=htons(MYPORT);
their_addr.sin_addr=((struct in_addr*)he->h_addr);
bzero(&(their_addr.sin_zero),;
if((numbytes=sendto(sockfd,argv[2],strlen(argv[2]),0,(struct sockaddr*)&their_addr,sizeof(struct sockaddr)))==-1)
{
perror("sendto"
exit(1);
}
printf("send %d bytes to %s\n",numbytes,inet_ntoa(their_addr.sin_addr));
close(sockfd);
return 0;
}
编译的时候:
taller.c: 在函数 ‘main’ 中:
taller.c:23: 警告:从不兼容的指针类型赋值
taller.c:35: 错误:提领指向不完全类型的指针
taller.c:42: 警告:隐式声明函数 ‘inet_ntoa’
taller.c:42: 警告:格式 ‘%s’ 需要类型 ‘char *’,但实参 3 的类型为 ‘int’
出现的那个错误应该怎么解决呀?麻烦大家帮忙一下,谢谢! |
|