Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS // Perdonami, Windows :C
- #include <stdio.h>
- #include <string.h>
- typedef unsigned char byte;
- typedef union
- {
- struct
- {
- byte b1, b2, b3, b4;
- } bytes;
- unsigned int asUInt;
- } IPv4Address;
- int main(int argc, char* argv[])
- {
- IPv4Address IP, SubnetMask, BroadcastAddress;
- // Un po' di pulizia...
- IP.asUInt = SubnetMask.asUInt = BroadcastAddress.asUInt = 0;
- // Il formato di scanf sa tanto di ridicolo XD
- // Giusto per renderlo piΓΉ leggibile:
- // hh = char, u = unsigned.
- printf("Inserisci un indirizzo IP nel formato a.b.c.d: ");
- scanf("%hhu.%hhu.%hhu.%hhu", &(IP.bytes.b1),
- &(IP.bytes.b2),
- &(IP.bytes.b3),
- &(IP.bytes.b4)
- );
- printf("Inserisci la maschera di sottorete nel formato a.b.c.d: ");
- scanf("%hhu.%hhu.%hhu.%hhu", &(SubnetMask.bytes.b1),
- &(SubnetMask.bytes.b2),
- &(SubnetMask.bytes.b3),
- &(SubnetMask.bytes.b4)
- );
- // E ora, la sacra danza dei bit :O
- BroadcastAddress.asUInt = IP.asUInt | ~SubnetMask.asUInt;
- // Output
- printf("\nIndirizzo di broadcast: %hhu.%hhu.%hhu.%hhu\n", BroadcastAddress.bytes.b1,
- BroadcastAddress.bytes.b2,
- BroadcastAddress.bytes.b3,
- BroadcastAddress.bytes.b4
- );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement