linux下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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值