tinyhttpd源码分析
2016-09-14 21:09
489 查看
一边学一边写,慢慢更新
TinyHttpd是一个轻量级HTTP服务器,主要部分只有500行
项目下载地址
点击打开链接
the port is 51963
the port is 51963
httpd running on port 51963
也就是说getsockname()函数只在port等于0的时候才会返回本地端口号,当端口号本身不为0的时候不会再去修改端口号
getsockname()与getpeername()的作用可参考《Unix网络编程卷1》
TinyHttpd是一个轻量级HTTP服务器,主要部分只有500行
项目下载地址
点击打开链接
if (*port == 0) /* if dynamically allocating a port */ { socklen_t namelen = sizeof(name); if (getsockname(httpd, (struct sockaddr *)&name, &namelen) == -1) error_die("getsockname"); *port = ntohs(name.sin_port); printf("the port is %d\n",*port); if (getsockname(httpd, (struct sockaddr *)&name, &namelen) == -1) error_die("getsockname"); *port = ntohs(name.sin_port); printf("the port is %d\n",*port); }修改httpd.c部分代码,再运行httpd,最终的输出结果:
the port is 51963
the port is 51963
httpd running on port 51963
也就是说getsockname()函数只在port等于0的时候才会返回本地端口号,当端口号本身不为0的时候不会再去修改端口号
getsockname()与getpeername()的作用可参考《Unix网络编程卷1》
相关文章推荐
- 源码分析之tinyhttpd(一)
- tinyhttpd源码分析
- HTTP服务器的本质:tinyhttpd源码分析及拓展
- TinyHTTPd源码分析
- 源码分析之tinyhttpd-0.1
- TinyHTTPd--超轻量型Http Server源码分析
- mini-httpd源码分析-port.h
- tinyhttpd源码学习1
- tinyhttp源码分析
- http服务器雏形tinyhttpd源码
- Tinyhttpd源码解析
- mini_httpd源码分析
- CSAPP Tiny web 服务器源码分析及搭建运行
- tinyhttpd服务器源码学习
- mini-httpd源码分析-mini-httpd.c
- Tinyhttpd源码剖析(二)
- mini-httpd源码分析-match.h
- tinyhttpd源码学习1
- mini-httpd源码分析-tdate_parse.h
- lighttpd高性能Web服务器源码分析?坑爹啊,原来是light httpd!-0 -