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
總結
以上所述是小編給大家介紹的linux下socket編程常用頭文件(推薦),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
您可能感興趣的文章:- Linux進程間通信方式之socket使用實例
- Linux UDP socket 設置為的非阻塞模式與阻塞模式區別
- Linux下高并發socket最大連接數所受的各種限制(詳解)
- Linux中使用C語言實現基于UDP協議的Socket通信示例
- 詳解Linux的SOCKET編程
- C語言實現Linux下的socket文件傳輸實例
- Linux網絡編程之UDP Socket程序示例
- Linux網絡編程之socket文件傳輸示例
- 詳解從Linux源碼看Socket(TCP)的bind