5.2. socket()-取得 File Descriptor!
#include <sys/types.h>
#include <sys/socket.h>
int socket(int domain, int type, int protocol);int s;
struct addrinfo hints, *res;
// 執行查詢
// [假裝我們已經填好 "hints" struct]
getaddrinfo("www.example.com", "http", &hints, &res);
// [再來,你應該要對 getaddrinfo() 進行錯誤檢查, 並走到 "res" 鏈結串列查詢能用的資料,
// 而不是假設第一筆資料就是好的[像這些範例一樣]
// 實際的範例請參考 client/server 章節。
s = socket(res->ai_family, res->ai_socktype, res->ai_protocol);Last updated