linux下socket編程常用頭文件(推薦)
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:提供對(duì)I/O控制的函數(shù)
sys/poll.h:提供socket等待測(cè)試機(jī)制的函數(shù)
其他在網(wǎng)絡(luò)程序中常見的頭文件
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文件訪問(wèn)的函數(shù)
shadow.h:提供對(duì)/etc/shadow文件訪問(wèn)的函數(shù)
pthread.h:提供多線程操作的函數(shù)
signal.h:提供對(duì)信號(hào)操作的函數(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)證問(wèn)題時(shí)加入如下語(yǔ)句:
#include <shadow.h> #include <crypt.h> #include <pwd.h>
需要注意的是,應(yīng)該在編譯時(shí)鏈接加密算法庫(kù),即增加編譯選項(xiàng):
-lcrypt
涉及到文件及時(shí)間操作加入如下語(yǔ)句:
#include <sys/time.h> #include <utime.h> #include <time.h> #include <sys/stat.h> #include <sys/file.h>
涉及到多進(jìn)程操作時(shí)加入如下語(yǔ)句:
#include <sys/wait.h> #include <sys/ipc.h> #include <sys/shm.h> #include <signal.h>
涉及到多線程操作時(shí)加入如下語(yǔ)句:
#include <pthread.h> #include <sys/poll.h>
需要注意的是,應(yīng)該在編譯時(shí)鏈接線程庫(kù),即增加編譯選項(xiàng):
-lthread
總結(jié)
以上所述是小編給大家介紹的linux下socket編程常用頭文件(推薦),希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
- C/C++?Linux?Socket網(wǎng)絡(luò)編程流程分析
- 詳解從Linux源碼看Socket(TCP)的bind
- 詳解Linux使用ss命令結(jié)合zabbix對(duì)socket做監(jiān)控
- 從Linux源碼看Socket(TCP)Client端的Connect的示例詳解
- 局域網(wǎng)內(nèi)python socket實(shí)現(xiàn)windows與linux間的消息傳送
- Linux進(jìn)程間通信方式之socket使用實(shí)例
- linux socket通訊獲取本地的源端口號(hào)的實(shí)現(xiàn)方法
- Linux UDP socket 設(shè)置為的非阻塞模式與阻塞模式區(qū)別
- Linux?socket函數(shù)詳解
相關(guān)文章
Linux下使用shell腳本自動(dòng)執(zhí)行腳本文件
這篇文章主要介紹了Linux下使用shell腳本自動(dòng)執(zhí)行腳本文件的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-12-12bash shell命令行選項(xiàng)與修傳入?yún)?shù)處理
本文介紹了bash shell命令行參數(shù)與命令行選項(xiàng)的操作方法,有關(guān)shell 命令行參數(shù)的實(shí)例教程,有需要的朋友參考下。2014-04-04shell腳本學(xué)習(xí)指南[六](Arnold Robbins & Nelson H
這篇文章主要介紹了shell腳本學(xué)習(xí)指南[六](Arnold Robbins & Nelson H.F. Beebe著),需要的朋友可以參考下2014-02-02