inet_pton()函数仅给出ip或ip和端口号? [英] inet_pton() function gives only ip or ip and port number?

查看:385
本文介绍了inet_pton()函数仅给出ip或ip和端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C中,函数inet_pton()只能将IP地址从printble转换为字符串格式,还是也可以转换IP地址和端口号?我的意思是,如果我有一个格式为A.B.C.D:E的字符串,其中A.B.C.D是ip,E是端口号,是否可以将inet_pton用作相同的字符串?

In C does the function inet_pton() convert only the ip address from printble to string format or it also converts ip address and port number too? I mean, if I have a string of format A.B.C.D:E where A.B.C.D is the ip and E is the port number, would I be able to use inet_pton for the same?

推荐答案

否,它不处理端口号. 手册页准确地指定了它的内容期望使用IPv4地址:

No, it does not handle port numbers. The man page specifies exactly what it expects for IPv4 addresses:

src指向包含IPv4网络地址的字符串 点分十进制格式"ddd.ddd.ddd.ddd",其中ddd是十进制数字 最多三位数字,范围为0到255.地址被转换 到struct in_addr并复制到dst,该长度必须为sizeof(struct in_addr)(4)字节(32位)长.

src points to a character string containing an IPv4 network address in dotted-decimal format, "ddd.ddd.ddd.ddd", where ddd is 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.

这篇关于inet_pton()函数仅给出ip或ip和端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆