Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
IP アドレスとサブネットマスクの 2 つのパラメーターを受け取る関数を C/C++ で作成する際に助けが必要です。
関数は、関連付けられたネットワーク内にあるすべての IP アドレスのリストを返す必要があります。
例: IP アドレス= 192.168.33.72 と マスク= 255.255.255.192 という 2 つのパラメーターを指定すると、関数は IP の 192.168.33.65 から 192.168.33.126 を含むリストを返します。
1) まず、 と を文字列形式からバイナリ形式に で変換ipaddressできsubnetmaskますinet_pton()。
ipaddress
subnetmask
inet_pton()
subnetmask2)有効なサブネット マスクである必要があるマスクをチェックします。
3)subnetmask逆数を取得する ( ~subnetmask)
~subnetmask
4)
for (i=1; i<(~subnetmask); i++) { ip = ipaddress & (subnetmask + i); //append ip to your ip list }