日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

inet_ntop函数和inet_pton函数

發(fā)布時(shí)間:2025/3/15 编程问答 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 inet_ntop函数和inet_pton函数 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
#include<arpa/inet.h> int inet_pton(int family, const char *strptr, void *addrptr);返回:若成功則為1,若輸入不是有效的表達(dá)格式則為0,若出錯(cuò)則為-1 const char *inet_ntop(int family, const void *addrptr, char *strptr, size_t len);返回:若成功則為指向結(jié)果的指針, 若出錯(cuò)則為NULL

這兩個(gè)函數(shù)的family參數(shù)既可以是AF_INET,也可以是AF_INET6。如果以不被支持的地址族作為family的參數(shù),這兩個(gè)函數(shù)就都返回一個(gè)錯(cuò)誤,并將errno置為EAFNOSUPPORT。

第一個(gè)函數(shù)嘗試轉(zhuǎn)換由strptr指針?biāo)傅淖址?#xff0c;并通過addrptr指針存放二進(jìn)制結(jié)果。若成功則返回1,否則如果對(duì)所指定的family而言輸入的字符串不是有效的表達(dá)式,那么值為0。

inet_ntop進(jìn)行相反的轉(zhuǎn)換,從數(shù)值格式(addrptr)轉(zhuǎn)換到表達(dá)格式(strptr)。len參數(shù)是目標(biāo)存儲(chǔ)單元的大小,以免該函數(shù)溢出其調(diào)用者的緩沖區(qū)。為有助于指定這個(gè)大小,在

INET_NTOP(3) Linux Programmer's Manual INET_NTOP(3)NAMEinet_ntop - convert IPv4 and IPv6 addresses from binary to text formSYNOPSIS#include <arpa/inet.h>const char *inet_ntop(int af, const void *src,char *dst, socklen_t size);DESCRIPTIONThis function converts the network address structure src in the afaddress family into a character string. The resulting string is copiedto the buffer pointed to by dst, which must be a non-null pointer. Thecaller specifies the number of bytes available in this buffer in theargument size.inet_ntop() extends the inet_ntoa(3) function to support multipleaddress families, inet_ntoa(3) is now considered to be deprecated infavor of inet_ntop(). The following address families are currentlysupported:AF_INETsrc points to a struct in_addr (in network byte order) which isconverted to an IPv4 network address in the dotted-decimal for‐mat, "ddd.ddd.ddd.ddd". The buffer dst must be at leastINET_ADDRSTRLEN bytes long.AF_INET6src points to a struct in6_addr (in network byte order) which isconverted to a representation of this address in the most appro‐priate IPv6 network address format for this address. The bufferdst must be at least INET6_ADDRSTRLEN bytes long.RETURN VALUEOn success, inet_ntop() returns a non-null pointer to dst. NULL isreturned if there was an error, with errno set to indicate the error.ERRORSEAFNOSUPPORTaf was not a valid address family.ENOSPC The converted address string would exceed the size given bysize.ATTRIBUTESFor an explanation of the terms used in this section, seeattributes(7).┌────────────┬───────────────┬────────────────┐│Interface │ Attribute │ Value │├────────────┼───────────────┼────────────────┤│inet_ntop() │ Thread safety │ MT-Safe locale │└────────────┴───────────────┴────────────────┘CONFORMING TOPOSIX.1-2001, POSIX.1-2008. Note that RFC 2553 defines a prototypewhere the last argument size is of type size_t. Many systems followRFC 2553. Glibc 2.0 and 2.1 have size_t, but 2.2 and later havesocklen_t.BUGSAF_INET6 converts IPv4-mapped IPv6 addresses into an IPv6 format.EXAMPLESee inet_pton(3).SEE ALSOgetnameinfo(3), inet(3), inet_pton(3)COLOPHONThis page is part of release 4.04 of the Linux man-pages project. Adescription of the project, information about reporting bugs, and thelatest version of this page, can be found athttp://www.kernel.org/doc/man-pages/.Linux 2015-08-08 INET_NTOP(3)INET_PTON(3) Linux Programmer's Manual INET_PTON(3)NAMEinet_pton - convert IPv4 and IPv6 addresses from text to binary formSYNOPSIS#include <arpa/inet.h>int inet_pton(int af, const char *src, void *dst);DESCRIPTIONThis function converts the character string src into a network addressstructure in the af address family, then copies the network addressstructure to dst. The af argument must be either AF_INET or AF_INET6.The following address families are currently supported:AF_INETsrc points to a character string containing an IPv4 networkaddress in dotted-decimal format, "ddd.ddd.ddd.ddd", where dddis a decimal number of up to three digits in the range 0 to 255.The address is converted to a struct in_addr and copied to dst,which must be sizeof(struct in_addr) (4) bytes (32 bits) long.AF_INET6src points to a character string containing an IPv6 networkaddress. The address is converted to a struct in6_addr andcopied to dst, which must be sizeof(struct in6_addr) (16) bytes(128 bits) long. The allowed formats for IPv6 addresses followthese rules:1. The preferred format is x:x:x:x:x:x:x:x. This form consistsof eight hexadecimal numbers, each of which expresses a16-bit value (i.e., each x can be up to 4 hex digits).2. A series of contiguous zero values in the preferred formatcan be abbreviated to ::. Only one instance of :: can occurin an address. For example, the loopback address0:0:0:0:0:0:0:1 can be abbreviated as ::1. The wildcardaddress, consisting of all zeros, can be written as ::.3. An alternate format is useful for expressing IPv4-mapped IPv6addresses. This form is written as x:x:x:x:x:x:d.d.d.d,where the six leading xs are hexadecimal values that definethe six most-significant 16-bit pieces of the address (i.e.,96 bits), and the ds express a value in dotted-decimal nota‐tion that defines the least significant 32 bits of theaddress. An example of such an address is::FFFF:204.152.189.116.See RFC 2373 for further details on the representation of IPv6addresses.RETURN VALUEinet_pton() returns 1 on success (network address was successfully con‐verted). 0 is returned if src does not contain a character string rep‐resenting a valid network address in the specified address family. Ifaf does not contain a valid address family, -1 is returned and errno isset to EAFNOSUPPORT.ATTRIBUTESFor an explanation of the terms used in this section, seeattributes(7).┌────────────┬───────────────┬────────────────┐│Interface │ Attribute │ Value │├────────────┼───────────────┼────────────────┤│inet_pton() │ Thread safety │ MT-Safe locale │└────────────┴───────────────┴────────────────┘ CONFORMING TOPOSIX.1-2001, POSIX.1-2008.NOTESUnlike inet_aton(3) and inet_addr(3), inet_pton() supports IPv6addresses. On the other hand, inet_pton() accepts only IPv4 addressesin dotted-decimal notation, whereas inet_aton(3) and inet_addr(3) allowthe more general numbers-and-dots notation (hexadecimal and octal num‐ber formats, and formats that don't require all four bytes to beexplicitly written). For an interface that handles both IPv6addresses, and IPv4 addresses in numbers-and-dots notation, see getad‐drinfo(3).BUGSAF_INET6 does not recognize IPv4 addresses. An explicit IPv4-mappedIPv6 address must be supplied in src instead.EXAMPLEThe program below demonstrates the use of inet_pton() and inet_ntop(3).Here are some example runs:$ ./a.out i6 0:0:0:0:0:0:0:0::$ ./a.out i6 1:0:0:0:0:0:0:81::8$ ./a.out i6 0:0:0:0:0:FFFF:204.152.189.116::ffff:204.152.189.116Program source#include <arpa/inet.h>#include <stdio.h>#include <stdlib.h>#include <string.h>intmain(int argc, char *argv[]){unsigned char buf[sizeof(struct in6_addr)];int domain, s;char str[INET6_ADDRSTRLEN];if (argc != 3) {fprintf(stderr, "Usage: %s {i4|i6|<num>} string\n", argv[0]);exit(EXIT_FAILURE);}domain = (strcmp(argv[1], "i4") == 0) ? AF_INET :(strcmp(argv[1], "i6") == 0) ? AF_INET6 : atoi(argv[1]);s = inet_pton(domain, argv[2], buf);if (s <= 0) {if (s == 0)fprintf(stderr, "Not in presentation format");elseperror("inet_pton");exit(EXIT_FAILURE);}if (inet_ntop(domain, buf, str, INET6_ADDRSTRLEN) == NULL) {perror("inet_ntop");exit(EXIT_FAILURE);}printf("%s\n", str);exit(EXIT_SUCCESS);}SEE ALSOgetaddrinfo(3), inet(3), inet_ntop(3)COLOPHONThis page is part of release 4.04 of the Linux man-pages project. Adescription of the project, information about reporting bugs, and thelatest version of this page, can be found athttp://www.kernel.org/doc/man-pages/.Linux 2015-08-08 INET_PTON(3)

總結(jié)

以上是生活随笔為你收集整理的inet_ntop函数和inet_pton函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 欧美日韩在线播放 | 欧美黄色性视频 | 中文字幕乱码中文乱码777 | 精品国产精品 | 三年在线观看视频 | 欧美性受xxxx黑人xyx性爽 | 男女互操视频 | 美女张开腿让男人操 | 熟妇大屁股一区二区三区视频 | 一起操网站 | 日韩视频免费播放 | 岛国精品资源网站 | 午夜寂寞影院在线观看 | 久久色av| 麻豆传媒一区 | jizz在线观看视频 | 四虎黄色影院 | 一级特黄毛片 | 国产美女操 | 在线观看免费视频一区二区 | 91亚洲精品视频 | 新版天堂资源中文8在线 | www九色 | 久久99久久精品 | 女同vk | 久草手机在线 | 日本免费不卡 | 国产高清视频免费 | 国产99久久久国产精品成人免费 | 91大神小宝寻花在线观看 | 麻豆网站在线播放 | 高跟鞋和丝袜猛烈xxxxxx | 亚洲天堂毛片 | 乱淫67194| 亚洲欧洲久久久 | 91精品国产免费 | 99精品久久久久 | 91色精品 | xxxⅹ少妇少妇xxxx | 狠狠躁夜夜躁xxxxaaaa | 日本中文在线播放 | 精品国产一区二区三区av性色 | 操操日 | 国产羞羞 | 青草一区| 野外做受又硬又粗又大视频√ | 亚洲天堂视频一区 | 福利视频黄色 | 懂色av一区二区三区免费观看 | 欧美一级片在线看 | 成人亚洲玉足脚交系列 | 无码人妻精品一区二区三区不卡 | 经典av在线| 国产美女91呻吟求 | 国产精品美女www爽爽爽 | 午夜男人的天堂 | 蜜臀尤物一区二区三区直播 | 亚洲日本欧美在线 | 99热这里只有精品4 精品国产黄色 | sm在线看 | 国产欧美日韩在线播放 | 国产毛毛片 | 久久精品无码一区二区三区免费 | 国产精品热久久 | 国产酒店自拍 | 国产农村妇女精品一区 | 高清一区二区视频 | 日本女人黄色 | 亚洲性图一区二区 | 久久久久久久久久久久久女过产乱 | 丰满岳乱妇在线观看中字无码 | 久久伊人网站 | 在线观看无码精品 | 伊人久久大香线蕉成人综合网 | 亚洲国产精品自拍 | 男女野外做受全过程 | 精产国产伦理一二三区 | 一级毛片aa | av这里只有精品 | 91免费大片| 黄色免费在线观看视频 | 草久久久久 | 欧美成人毛片 | 久久国产成人精品国产成人亚洲 | 爱逼综合 | 黄网站在线观看视频 | 狠狠干狠狠操视频 | 欧美日韩视频免费观看 | 91丨九色丨黑人外教 | 九一成人网 | 丁香美女社区 | 法国空姐在线观看视频 | 性欧美大战久久久久久久久 | 少妇精品偷拍高潮白浆 | av电影免费在线播放 | 精品久久久久久久久久久久久久久久 | 午夜精品一区二区三区在线 | 长篇高h乱肉辣文 | 91在线免费视频观看 |