1. convert char IP address to four int
2. convert four int var to one int
3. convert four int var to one char
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Or, these is a api to do it
| 1 2 3 4 5 6 7 8 9 10 11 | |
===========================================
reference from:
http://www.cplusplus.com/forum/general/9403/
http://stackoverflow.com/questions/1505676/how-to-convert-ip-address-from-char-to-int
http://beej.us/guide/bgnet/output/html/multipage/inet_ntopman.html (good)
http://beej.us/guide/bgnet/output/html/multipage/inet_ntoaman.html
http://www.aboutmyip.com/AboutMyXApp/IP2Integer.jsp
===========================================
後記:
後來發現一篇文章最有用
從 inet_ntoa 看 thread safe 的 API
inet_ntoa會有thread safe的問題,最好直接改用inet_ntop