红联Linux门户
Linux帮助

socket 问题

发布时间:2008-03-22 10:01:15来源:红联作者:yunlerini
#include
#include
#include
#include

int sockfd, port = 23;
struct sockaddr_in my_addr;

if((sockfd=socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("Socket Error, %d\n", errno);
exit(1);
}

my_addr.sin_family = AF_INET; /* host byte order */
my_addr.sin_port = htons(port); /* see man htons for more information
*/
my_addr.sin_addr.s_addr = htonl(INADDR_ANY); /* get our address */
bzero(&(my_addr.sin_zero), 8); /* zero out the rest of the space */

if((bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))
== -1)
{
printf("Bind Error, %d\n", errno);
close(sockfd);
exit(1);
}
用gcc编译出错了 但哪有错呢
bind.c:9: parse error before "if"
bind.c:12: parse error before numeric constant
bind.c:12: warning: data definition has no type or storage class
bind.c:18: parse error before '&' token
bind.c:18: warning: conflicting types for built-in function `bzero'
bind.c:23: warning: parameter names (without types) in function declaration
bind.c:23: warning: data definition has no type or storage class
bind.c:24: parse error before numeric constant
bind.c:24: warning: data definition has no type or storage class
bind.c:7: storage size of `my_addr' isn't known
文章评论

共有 1 条评论

  1. yunlerini 于 2008-03-24 08:46:57发表:

    还是没人解答一下啊