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 282 views
282 views asked May 15, 2024 by avibootz
1 answer 244 views
1 answer 262 views
2 answers 262 views
262 views asked May 22, 2015 by avibootz
1 answer 115 views
1 answer 204 views
1 answer 112 views
...