On Wed, Apr 22, 2009 at 10:15 PM, Lettow, Kenneth <[email protected]> wrote:
> How do you convert a IP address from dotted quad representation to
> integer and back in J?
You may also use the proper library function for reading a dotted quad
address. Here's an example. This only does conversion in one way and
doesn't check the error code, but you can easily extend it to do those
too. (Note that I need a wrapper because the library function is in
libc and may be a macro or can use other libc magic so we can't
directly load it from J.)
[am]king ~/a/tmp$ cat wrap_in.c
#include <arpa/inet.h>
int
wrap_inet_aton(const char *s, int *p) {
struct in_addr b;
int r = inet_aton(s, &b);
*p = b.s_addr;
return r;
}
[am]king ~/a/tmp$ gcc -Wall -O -fPIC -shared -o wrap_in.so wrap_in.c
[am]king ~/a/tmp$ jconsole
(<.2^32)|_1{::'./wrap_in.so wrap_inet_aton i *c *i' 15!:0 '69 255
248 210';,0
1157627904
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm