Is there a standard function for converting IP address to number?

2006-12-04 Thread a
Is there a standard function converting four numbers to one 32-bit 
IP address?

I mean a function like

f(i, j, k, l) {
return (i  8) | j)  8) | k)  8) | l;
}

Elisej Babenko
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Is there a standard function for converting IP address to number?

2006-12-04 Thread Giorgos Keramidas
On 2006-12-04 14:45, [EMAIL PROTECTED] wrote:
 Is there a standard function converting four numbers to one 32-bit 
 IP address?
 
 I mean a function like
 
 f(i, j, k, l) {
   return (i  8) | j)  8) | k)  8) | l;
   }

That's not even a complete, usable function, but if you are looking for
a 'standard' function as in part of libc already, the answer is no.

Try something like the

in_addr_t makeaddr(uint8_t, uint8_t, uint8_t, uint8_t);

function from this sample program:

http://people.freebsd.org/~keramida/files/addr.tar.gz

which looks like this:

#include sys/types.h

#include netinet/in.h

#include addr.h

in_addr_t
makeaddr(uint8_t a, uint8_t b, uint8_t c, uint8_t d)
{

return (htonl(((in_addr_t)a  24) + ((in_addr_t)b  16) +
((in_addr_t)c  8) + (in_addr_t)d));
}

___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: Is there a standard function for converting IP address to number?

2006-12-04 Thread Matthew Seaman
[EMAIL PROTECTED] wrote:
 Is there a standard function converting four numbers to one 32-bit 
 IP address?
 
 I mean a function like
 
 f(i, j, k, l) {
   return (i  8) | j)  8) | k)  8) | l;
   }

Not exactly.  inet_ntoa() and inet_aton() are about the closest I can
think of.  There's a range of similar functions described in the
inet(3) man page for converting from struct in_addr (essentially
an IPv4 address expressed as a 32bit int) to a textual representation
of an IPv4 number, and vice versa. 

Cheers,

Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.   7 Priory Courtyard
  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey Ramsgate
  Kent, CT11 9PW



signature.asc
Description: OpenPGP digital signature