How to store IP address in C

1 Answer

0 votes
#include <stdio.h>
#include <stdint.h>

union {
    struct {
        uint8_t first:8;
        uint8_t second:8;
        uint8_t third:8;
        uint8_t fourth:8;
    };
    uint32_t ip;
} typedef IPAddress;

int main() {

    IPAddress ip = {{127,55,7,3}};

    printf("%d.%d.%d.%d\n", ip.first, ip.second, ip.third, ip.fourth);


    return 0;
}




/*
run:

127.55.7.3

*/

 



answered May 6, 2021 by avibootz

Related questions

4 answers 247 views
247 views asked May 15, 2024 by avibootz
1 answer 234 views
1 answer 257 views
2 answers 254 views
254 views asked May 22, 2015 by avibootz
1 answer 106 views
1 answer 201 views
1 answer 105 views
...