linux網(wǎng)絡(luò)編程常用頭文件
linux 下socket 編程常用頭文件sys/types.h:數(shù)據(jù)類(lèi)型定義sys/socket.h:提供socket 函數(shù)及數(shù)據(jù)結(jié)構(gòu)netinet/in.h:定義數(shù)據(jù)結(jié)構(gòu)sockaddr_inar
linux 下socket 編程常用頭文件
sys/types.h:數(shù)據(jù)類(lèi)型定義
sys/socket.h:提供socket 函數(shù)及數(shù)據(jù)結(jié)構(gòu)
netinet/in.h:定義數(shù)據(jù)結(jié)構(gòu)sockaddr_in
arpa/inet.h:提供IP 地址轉(zhuǎn)換函數(shù)
netdb.h :提供設(shè)置及獲取域名的函數(shù)
sys/ioctl.h:提供對(duì)I/O控制的函數(shù)
sys/poll.h:提供socket 等待測(cè)試機(jī)制的函數(shù)
其他在網(wǎng)絡(luò)程序中常見(jiàn)的頭文件
unistd.h :提供通用的文件、目錄、程序及進(jìn)程操作的函數(shù)errno.h :提供錯(cuò)誤號(hào)errno 的定義,用于錯(cuò)誤處理
fcntl.h :提供對(duì)文件控制的函數(shù)
time.h :提供有關(guān)時(shí)間的函數(shù)
crypt.h :提供使用DES 加密算法的加密函數(shù)
pwd.h :提供對(duì)/etc/passwd文件訪(fǎng)問(wèn)的函數(shù)
shadow.h :提供對(duì)/etc/shadow文件訪(fǎng)問(wèn)的函數(shù)
pthread.h :提供多線(xiàn)程操作的函數(shù)
signal.h :提供對(duì)信號(hào)操作的函數(shù)
sys/wait.h、sys/ipc.h、sys/shm.h:提供進(jìn)程等待、進(jìn)程間通訊(內(nèi)存的函數(shù)
IPC )及共享
,建議: 在編寫(xiě)網(wǎng)絡(luò)程序時(shí),可以直接使用下面這段頭文件代碼 #include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
涉及到用戶(hù)權(quán)限及密碼驗(yàn)證問(wèn)題時(shí)加入如下語(yǔ)句:
#include
#include
#include
需要注意的是,應(yīng)該在編譯時(shí)鏈接加密算法庫(kù),即增加編譯選項(xiàng): -lcrypt
涉及到文件及時(shí)間操作加入如下語(yǔ)句:
#include
#include
#include
#include
#include
涉及到多進(jìn)程操作時(shí)加入如下語(yǔ)句:
#include
#include
#include
#include
涉及到多線(xiàn)程操作時(shí)加入如下語(yǔ)句:
#include
#include
需要注意的是,應(yīng)該在編譯時(shí)鏈接線(xiàn)程庫(kù),即增加編譯選項(xiàng):-lthread