I previously posted how to implement a function that will convert an integer to an IP address string. So how would we go vice-versa, that is, given a string (154.111.23.23) that is an address, how can we get that integer back, using no inet functions.
相关问题
- Multiple sockets for clients to connect to
- how to split a list into a given number of sub-lis
- What is the best way to do a search in a large fil
- glDrawElements only draws half a quad
- Generate string from integer with arbitrary base i
scanf the string into four bytes and add/shift them into a 32 bit integer.
EDIT: For those how are interested on the code produced, GCC is smart enough to replace my multiplication of 256 with shifts left. (In my program I've also called exit):
Posix.1-2001 provides
inet_pton()
for this task. There's a couple of ms-windows versions of this too.