- 论坛徽章:
- 0
|
这是一段socket 基础程序 我有点不太明白~~
#include <stdio.h>;
#include <sys/types.h>;
#include <sys/socket.h>;
#include <errno.h>;
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), ; /* 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);
}
一 、htons(port)什么意思呀?干吗用的?
二 、my_addr.sin_addr.s_addr 这句什么意思?s_addr 重那里来得?htonl(INADDR_ANY) 是个函数么?怎么用?什么意思?
三 、 bzero(&(my_addr.sin_zero), 这句什么意思?
那位大哥,仔细讲讲,里面的过程呀~~~~ |
|