linux網路編程常用標頭檔

來源:互聯網
上載者:User

標籤:des   使用   io   檔案   資料   ar   問題   代碼   

sys/types.h:資料類型定義  

sys/socket.h:提供socket函數及資料結構 

netinet/in.h:定義資料結構sockaddr_in 

arpa/inet.h:提供IP地址轉換函式 

netdb.h:提供設定及擷取網域名稱的函數 

sys/ioctl.h:提供對I/O控制的函數  

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:提供進程等待、進程間通訊(IPC)及共用記憶體的函數

 

建議: 在編寫網路程式時,可以直接使用下面這段標頭檔代碼 

#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>    

 

涉及到使用者權限及密碼驗證問題時加入如下語句: 

#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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.