socket编程accept提示

accept原型:

int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);

这个addrlen要小心,看上去是传指针,似乎用于输出长度,但是它不仅用来传出地址长度,本身也是作为输入的——等于传入addr的长度。用法类似:

struct sockaddr addr;
socklen_t addrlen = sizeof(struct sockaddr);

int fd = accept(sockfd, &addr, &addrlen);
....



相关文章

分类

留言:

关于文章

This page contains a single entry by DongHao published on 05 11, 2009 4:32 PM.

leapftp was the previous entry in this blog.

用virtualbox安装freedos is the next entry in this blog.

Find recent content on the main index or look in the 存档 to find all content.