网络掩码转换为C ++中的CIDR格式 [英] netmask conversion to CIDR format in C++

查看:642
本文介绍了网络掩码转换为C ++中的CIDR格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将2个DWORD,IP地址和网络掩码转换为CDIR格式...
所以我有2个DWORD对应于1.1.1.1和255.255.255.255,我想提出字符串
1.1.1.1/32

I have to convert 2 DWORDs, IP address and a network mask to CDIR format... So I have 2 DWORDs corresponding 1.1.1.1 and 255.255.255.255 and I want to come up with string 1.1.1.1/32

有任何想法吗?

感谢

推荐答案

由于有一个小的和固定数量的有效网络掩码(32,要精确),最快的方法可能是只是构建一个掩码地图前缀长度在初始时间一次,转换只是在地图中查找。

Since there are a small and fixed number of valid netmasks (32, to be exact), the fastest way is probably to just build a map of masks to prefix length once at init time, and the conversion is just a lookup in the map.

这篇关于网络掩码转换为C ++中的CIDR格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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