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ù)
sys/ioctl.h:提供對I/O控制的函數(shù)
sys/poll.h:提供socket等待測試機制的函數(shù)
其他在網(wǎng)絡程序中常見的頭文件
unistd.h:提供通用的文件、目錄、程序及進程操作的函數(shù)
errno.h:提供錯誤號errno的定義,用于錯誤處理
fcntl.h:提供對文件控制的函數(shù)
time.h:提供有關(guān)時間的函數(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:提供進程等待、進程間通訊(IPC)及共享內(nèi)存的函數(shù)
建議: 在編寫網(wǎng)絡程序時,可以直接使用下面這段頭文件代碼
#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)限及密碼驗證問題時加入如下語句:
#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
總結(jié)
以上所述是小編給大家介紹的linux下socket編程常用頭文件(推薦),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- C/C++?Linux?Socket網(wǎng)絡編程流程分析
- 詳解從Linux源碼看Socket(TCP)的bind
- 詳解Linux使用ss命令結(jié)合zabbix對socket做監(jiān)控
- 從Linux源碼看Socket(TCP)Client端的Connect的示例詳解
- 局域網(wǎng)內(nèi)python socket實現(xiàn)windows與linux間的消息傳送
- Linux進程間通信方式之socket使用實例
- linux socket通訊獲取本地的源端口號的實現(xiàn)方法
- Linux UDP socket 設置為的非阻塞模式與阻塞模式區(qū)別
- Linux?socket函數(shù)詳解
相關(guān)文章
bash shell命令行選項與修傳入?yún)?shù)處理
本文介紹了bash shell命令行參數(shù)與命令行選項的操作方法,有關(guān)shell 命令行參數(shù)的實例教程,有需要的朋友參考下。2014-04-04shell腳本學習指南[六](Arnold Robbins & Nelson H
這篇文章主要介紹了shell腳本學習指南[六](Arnold Robbins & Nelson H.F. Beebe著),需要的朋友可以參考下2014-02-02