国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Unix Network Programming Episode 79

這篇具有很好參考價值的文章主要介紹了Unix Network Programming Episode 79。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報違法"按鈕提交疑問。

‘gai_strerror’ Function

The nonzero error return values from getaddrinfo have the names and meanings shown in Figure 11.7. The function gai_strerror takes one of these values as an argument and returns a pointer to the corresponding error string.

#include <netdb.h>
const char *gai_strerror (int error);
‘freeaddrinfo’ Function

All the storage returned by getaddrinfo, the addrinfo structures, the ai_addr structures, and the ai_canonname string are obtained dynamically (e.g., from malloc). This storage is returned by calling freeaddrinfo.

#include <netdb.h>
void freeaddrinfo (struct addrinfo *ai);

ai should point to the first addrinfo structure returned by getaddrinfo. All the structures in the linked list are freed, along with any dynamic storage pointed to by those structures (e.g., socket address structures and canonical hostnames).

‘getaddrinfo’ Function: IPv6

The POSIX specification defines the getaddrinfo function and the information it returns for both IPv4 and IPv6.

  • getaddrinfo is dealing with two different inputs: the type of socket address structure the caller wants back and the type of records that should be searched for in the DNS or other database.
  • The address family in the hints structure provided by the caller specifies the type of socket address structure that the caller expects to be returned. If the caller specifies AF_INET, the function must not return any sockaddr_in6 structures; if the caller specifies AF_INET6, the function must not return any sockaddr_in structures.
  • POSIX says that specifying AF_UNSPEC will return addresses that can be used with any protocol family that can be used with the hostname and service name. This implies that if a host has both AAAA records and A records, the AAAA records are returned as sockaddr_in6 structures and the A records are returned as sockaddr_in structures. It makes no sense to also return the A records as IPv4-mapped IPv6 addresses in sockaddr_in6 structures because no additional information is being returned: These addresses are already being returned in sockaddr_in structures.
  • This statement in the POSIX specification also implies that if the AI_PASSIVE flag is specified without a hostname, then the IPv6 wildcard address (IN6ADDR_ANY_INIT or 0::0) should be returned as a sockaddr_in6 structure, along with the IPv4 wildcard address (INADDR_ANY or 0.0.0.0), which is returned as a sockaddr_in structure. It also makes sense to return the IPv6 wildcard address first because we will see in Section 12.2(See 9.1.2) that an IPv6 server socket can handle both IPv6 and IPv4 clients on a dual-stack host.
  • The address family specified in the hint structure’s ai_family member, along with the flags such as AI_V4MAPPED and AI_ALL specified in the ai_flags member, dictate the type of records that are searched for in the DNS (A and/or AAAA) and what type of addresses are returned (IPv4, IPv6, and/or IPv4-mapped IPv6). We summarize this in Figure 11.8.
  • The hostname can also be either an IPv6 hex string or an IPv4 dotted-decimal string. The validity of this string depends on the address family specified by the caller. An IPv6 hex string is not acceptable if AF_INET is specified, and an IPv4 dotted-decimal string is not acceptable if AF_INET6 is specified. But, if AF_UNSPEC is specified, either is acceptable and the appropriate type of socket address structure is returned.
‘getaddrinfo’ Function: Examples

We will now show some examples of getaddrinfo using a test program that lets us enter all the parameters: the hostname, service name, address family, socket type, and AI_CANONNAME and AI_PASSIVE flags. (We do not show this test program, as it is about 350 lines of uninteresting code. It is provided with the source code for the book, as described in the Preface.) The test program outputs information on the variable number of addrinfo structures that are returned, showing the arguments for a call to socket and the address in each socket address structure.

‘host_serv’ Function

Our first interface to getaddrinfo does not require the caller to allocate a hints structure and fill it in. Instead, the two fields of interest, the address family and the socket type, are arguments to our host_serv function.

#include "unp.h"
struct addrinfo *host_serv (const char *hostname, const char *service, int family, ints socktype);
#include "unp.h"

struct addrinfo* host_serv(const char *host, const char *serv, int family, int socktype)
{
    int n;
    struct addrinfo hints, *res;
    bzero(&hints, sizeof(struct addrinfo));
    hints.ai_flags=AI_CANONNAME;
    hints.ai_family=family;
    hints.ai_socktype=socktype;

    if((n=getaddrinfo(host, serv, &hints, &res))!=0)
    {
        return NULL;
    }
    return res;
}

host_serv function文章來源地址http://www.zghlxwxcb.cn/news/detail-727759.html

到了這里,關(guān)于Unix Network Programming Episode 79的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • Unix Network Programming Episode 76

    We encourage the use of getaddrinfo (Section 11.6(See 8.9.6)) in new programs. The non-null pointer returned by this function points to the following hostent structure: gethostbyname differs from the other socket functions that we have described in that it does not set errno when an error occurs. Instead, it sets the global integer h_errno to one of the foll

    2024年02月09日
    瀏覽(17)
  • unix網(wǎng)絡(luò)編程-簡易服務(wù)器與客戶端程序解析

    a -- address f -- file? ? ? ? eg: fputs() -- file put stream fd -- file descriptor h - host(主機(jī)) in/inet -- internet? ? ? ? eg: sockaddr_in; inet_aton n -- network(網(wǎng)絡(luò)字節(jié)序)/numeric(數(shù)值) p -- protocol(協(xié)議)/presentation(表達(dá)/呈現(xiàn)形式) s -- socket? ? ? ? eg: sin -- socket internet t -- type,用于指定某種

    2024年01月16日
    瀏覽(30)
  • UNIX網(wǎng)絡(luò)編程卷一 學(xué)習(xí)筆記 第三十章 客戶/服務(wù)器程序設(shè)計范式

    UNIX網(wǎng)絡(luò)編程卷一 學(xué)習(xí)筆記 第三十章 客戶/服務(wù)器程序設(shè)計范式

    開發(fā)一個Unix服務(wù)器程序時,我們本書做過的進(jìn)程控制: 1.迭代服務(wù)器(iterative server),它的適用情形極為有限,因?yàn)檫@樣的服務(wù)器在完成對當(dāng)前客戶的服務(wù)前無法處理已等待服務(wù)的新客戶。 2.并發(fā)服務(wù)器(concurrent server),為每個客戶調(diào)用fork派生一個子進(jìn)程。傳統(tǒng)上大多U

    2024年02月09日
    瀏覽(24)
  • 【開源與項(xiàng)目實(shí)戰(zhàn):開源實(shí)戰(zhàn)】79 | 開源實(shí)戰(zhàn)二(中):從Unix開源開發(fā)學(xué)習(xí)應(yīng)對大型復(fù)雜項(xiàng)目開發(fā)

    我們知道,項(xiàng)目越復(fù)雜、代碼量越多、參與開發(fā)人員越多、開發(fā)維護(hù)時間越長,我們就越是要重視代碼質(zhì)量。代碼質(zhì)量下降會導(dǎo)致項(xiàng)目研發(fā)困難重重,比如:開發(fā)效率低,招了很多人,天天加班,出活卻不多;線上 bug 頻發(fā),查找 bug 困難,領(lǐng)導(dǎo)發(fā)飆,中層束手無策,工程師抱

    2024年02月11日
    瀏覽(36)
  • 【Socket】Unix環(huán)境下搭建簡易本地時間獲取服務(wù)

    本文搭建一個Unix環(huán)境下的、局域網(wǎng)內(nèi)的、簡易的本地時間獲取服務(wù)。 主要用于驗(yàn)證: 當(dāng)TCP連接成功后,可以在兩個線程中分別進(jìn)行讀操作、寫操作動作 當(dāng)客戶端自行終止連接后,服務(wù)端會在寫操作時收到 SIGPIPE 信號 當(dāng)客戶端執(zhí)行shutdown寫操作后,客戶端會在寫操作時收到

    2024年02月04日
    瀏覽(21)
  • MobaXterm連接服務(wù)器:Network error: Connection refused

    centos7: ubuntu20.04

    2024年02月16日
    瀏覽(17)
  • 【Hello Network】DNS協(xié)議 NAT技術(shù) 代理服務(wù)器

    【Hello Network】DNS協(xié)議 NAT技術(shù) 代理服務(wù)器

    本篇博客簡介:介紹DNS協(xié)議 NAT技術(shù)和代理服務(wù)器 DNS是一整套從域名映射到IP的系統(tǒng) 為什么要有域名 其實(shí)作為我們程序員來說 使用域名還是IP地址是無所謂的 但是站在商業(yè)公司和用戶的角度就不這么認(rèn)為了 商業(yè)公司希望用戶能夠快速的記住自己公司的網(wǎng)址 而用戶也希望自己

    2024年02月11日
    瀏覽(17)
  • MobaXterm監(jiān)控服務(wù)器的資源(CPU、RAM、Network、disk...) 使用情況

    MobaXterm監(jiān)控服務(wù)器的資源(CPU、RAM、Network、disk...) 使用情況

    使用服務(wù)器的時候比較喜歡隨時查看的服務(wù)器資源使用情況,比如內(nèi)存,CPU,網(wǎng)速,磁盤使用等情況,一次偶然的機(jī)會發(fā)現(xiàn)了MobaXterm提供有這項(xiàng)功能,在會話窗口底部: 完整窗口示意圖 如果你發(fā)現(xiàn)你的會話窗口底部沒有,可以這樣開啟: Settings→SSH→勾選Remote-monitoring 參考

    2024年02月14日
    瀏覽(123)
  • mobaxterm無法連接vmware虛擬機(jī)服務(wù)器,network error:connection refused

    場景描述: 電腦硬盤換了,重新安裝vmware,ubuntu,mobaxterm..... 安裝完ubuntu后,因?yàn)榱?xí)慣了無UI的界面,所以關(guān)閉了ubuntu的桌面服務(wù) (有需要的同學(xué)可以通過sudo systemctl set-default multi-user.target,然后sudo reboot就可以關(guān)閉桌面服務(wù)了,打開命令是sudo 6systemctl set-default graphical.targe

    2024年02月14日
    瀏覽(22)
  • /etc/netplan/network-manager-all.yaml 配置服務(wù)器ip

    本文為博主原創(chuàng),轉(zhuǎn)載請注明出處: /etc/netplan 是用于配置 Ubuntu 系統(tǒng)網(wǎng)絡(luò)接口的目錄。在 Ubuntu 中,網(wǎng)絡(luò)配置的默認(rèn)工具為?? Netplan ,而 /etc/netplan 則是 Netplan 配置文件的存儲位置。 在 /etc/netplan 目錄中,通常會有一個或多個 YAML 格式的文件,用來定義系統(tǒng)中的網(wǎng)絡(luò)接口、

    2024年02月07日
    瀏覽(12)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包