Search code examples
cnetworkingip-addressgethostbyaddr

How to store human readable IP in struct in_addr?


Say if you have the following IP address:

192.168.0.255

How can I store that human readable IP address into a struct in_addr? I'm brand new to network programming in C at this low level, so any help would be greatly appreciated.


Solution

  • You can do

    struct in_addr p;
    inet_aton("192.168.0.255", &p.s_addr);