一江春水向东流

做一个有思想的人,期待与每一位热爱思考的人交流,您的关注是对我最大的支持。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  44 随笔 :: 139 文章 :: 81 评论 :: 0 Trackbacks
 

socket编程中需要用到的头文件

sys/types.h:数据类型定义

sys/socket.h:提供socket函数及数据结构

netinet/in.h:定义数据结构sockaddr_in

arpa/inet.h:提供IP地址转换函数

netdb.h:提供设置及获取域名的函数

sys/ioctl.h:提供对I/O控制的函数

sys/poll.h:提供socket等待测试机制的函数

 

其他在网络程序中常见的头文件

unistd.h:提供通用的文件、目录、程序及进程操作的函数

errno.h:提供错误号errno的定义,用于错误处理

fcntl.h:提供对文件控制的函数

time.h:提供有关时间的函数

crypt.h:提供使用DES加密算法的加密函数

pwd.h:提供对/etc/passwd文件访问的函数

shadow.h:提供对/etc/shadow文件访问的函数

pthread.h:提供多线程操作的函数

signal.h:提供对信号操作的函数

sys/wait.h、sys/ipc.h、sys/shm.h:提供进程等待、进程间通讯(IPC)及共享内存的函数

 

建议: 在编写网络程序时,可以直接使用下面这段头文件代码

#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <malloc.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include <fcntl.h>
#include <fcntl.h>
 

涉及到用户权限及密码验证问题时加入如下语句:
#include <shadow.h>
#include <crypt.h>
#include <pwd.h>

需要注意的是,应该在编译时链接加密算法库,即增加编译选项:
-lcrypt

  

涉及到文件及时间操作加入如下语句:
#include <sys/time.h>
#include <utime.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/file.h>
 

涉及到多进程操作时加入如下语句:
#include <sys/wait.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <signal.h>

 

涉及到多线程操作时加入如下语句:
#include <pthread.h>
#include <sys/poll.h>
需要注意的是,应该在编译时链接线程库,即增加编译选项:
-lthread

posted on 2007-08-24 20:54 allic 阅读(3307) 评论(1)  编辑  收藏 所属分类: TCP/IP 开发

评论

# re: socket编程中需要用到的头文件[未登录] 2010-05-30 02:49 han
windows下有这些东西么
matata@sohu.com  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: