sys/types.h: 資料類型定義
sys/socket.h: 提供socket函數及資料結構
netinet/in.h : 定義資料結構sockaddr_in
arpa/inet.h : 提供IP位址轉換函數
netdb.h : 提供設定及擷取域名的函數
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 : 提供程序等待,程序間通信及共享記憶體的函數
在編寫網絡程式時,可以直接使用下面頭檔案代碼:
#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<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