C++ how to convert ip address to bytes?

后端 未结 4 1759
借酒劲吻你
借酒劲吻你 2021-01-07 08:54

How would I convert an ip address into bytes in C++? Basically how do I parse the IP address? For example, if I have a string equal to 121.122.123.124. I need

4条回答
  •  醉话见心
    2021-01-07 09:51

    Using sscanf() function:

    #include 
    
    char arr[] = "192.168.1.102"; 
    unsigned short a, b, c, d;
    sscanf(arr, "%hu.%hu.%hu.%hu", &a, &b, &c, &d);
    

提交回复
热议问题