sys/types.h:數(shù)據(jù)類型定義
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:提供對I/O控制的函數(shù)
sys/poll.h:提供socket等待測試機(jī)制的函數(shù)
其他在網(wǎng)絡(luò)程序中常見的頭文件
unistd.h:提供通用的文件、目錄、程序及進(jìn)程操作的函數(shù)
errno.h:提供錯(cuò)誤號errno的定義,用于錯(cuò)誤處理
fcntl.h:提供對文件控制的函數(shù)
time.h:提供有關(guān)時(shí)間的函數(shù)
crypt.h:提供使用DES加密算法的加密函數(shù)
pwd.h:提供對/etc/passwd文件訪問的函數(shù)
shadow.h:提供對/etc/shadow文件訪問的函數(shù)
pthread.h:提供多線程操作的函數(shù)
signal.h:提供對信號操作的函數(shù)
sys/wait.h、sys/ipc.h、sys/shm.h:提供進(jìn)程等待、進(jìn)程間通訊(IPC)及共享內(nèi)存的函數(shù)
建議: 在編寫網(wǎng)絡(luò)程序時(shí),可以直接使用下面這段頭文件代碼
#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>
涉及到用戶權(quán)限及密碼驗(yàn)證問題時(shí)加入如下語句:
#include shadow.h> #include crypt.h> #include pwd.h>
需要注意的是,應(yīng)該在編譯時(shí)鏈接加密算法庫,即增加編譯選項(xiàng):
-lcrypt
涉及到文件及時(shí)間操作加入如下語句:
#include sys/time.h> #include utime.h> #include time.h> #include sys/stat.h> #include sys/file.h>
涉及到多進(jìn)程操作時(shí)加入如下語句:
#include sys/wait.h> #include sys/ipc.h> #include sys/shm.h> #include signal.h>
涉及到多線程操作時(shí)加入如下語句:
#include pthread.h> #include sys/poll.h>
需要注意的是,應(yīng)該在編譯時(shí)鏈接線程庫,即增加編譯選項(xiàng):
-lthread
總結(jié)
以上所述是小編給大家介紹的linux下socket編程常用頭文件(推薦),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
標(biāo)簽:昌都 烏蘭察布 廣東 海北 臨沂 撫州 贛州 連云港
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《linux下socket編程常用頭文件(推薦)》,本文關(guān)鍵詞 linux,下,socket,編程,常用頭,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。