inet_ntoa function ??

inet_ntoa function ??

Post by Sasha Kacansk » Thu, 02 Jul 1998 04:00:00



Hello,

having a problem with function char *inet_ntoa(struct in_addr in);

What ever I do to convert IP network ordering to printable string, program crashes on

this function.

example:

printf( "%s\n", inet_ntoa(*(struct in_addr *)haddr->s_addr );

where is  struct in_addr *haddr;

what I am doing wrong here.

Maybe someone could show me how to determine which host has a given IP address, which I

am trying to do, btw.

thanks

/s

--------------------------------
Sasha Kacanski
240 Murray Avenue
Ann Arbor, MI 48103
http://ic.net/~sasha

--------------------------
farcical - laughably inept

 
 
 

inet_ntoa function ??

Post by Steve Pel » Thu, 02 Jul 1998 04:00:00



Quote:>printf( "%s\n", inet_ntoa(*(struct in_addr *)haddr->s_addr );

>where is  struct in_addr *haddr;

This is the wrong newsgroup, but that should be:

        inet_ntoa(haddr->s_addr)

You're confusing haddr (which appears to be a pointer to a struct
sockaddr_in) with what you pass to inet_ntoa. Your program is dying
because the field s_addr is not a pointer, it's the struct itself.

 
 
 

inet_ntoa function ??

Post by Jeffrey Moye » Thu, 02 Jul 1998 04:00:00



> Hello,

> having a problem with function char *inet_ntoa(struct in_addr in);
> What ever I do to convert IP network ordering to printable string, program crashes on
> this function.

> example:

> printf( "%s\n", inet_ntoa(*(struct in_addr *)haddr->s_addr );

        well, read the man page.  you will see that inet_ntoa takes a
struct in_add as an arguement.  not a pointer to one, not a pointer to the
data element inside of it.  ;)  so the following will work for you:

  struct in_addr haddr;
  inet_aton("192.168.1.2", &haddr);
  printf( "%s\n", inet_ntoa(haddr));

yes, it's that simple.  :)  

        Regards,

           Phro

 
 
 

inet_ntoa function ??

Post by Sasha Kacansk » Fri, 03 Jul 1998 04:00:00


Thanks both of you for quick answers.
I went to * this one. It was very easy and both of you proved that to me.
sorry for bugging...



> > Hello,

> > having a problem with function char *inet_ntoa(struct in_addr in);
> > What ever I do to convert IP network ordering to printable string, program crashes on
> > this function.

> > example:

> > printf( "%s\n", inet_ntoa(*(struct in_addr *)haddr->s_addr );

>         well, read the man page.  you will see that inet_ntoa takes a
> struct in_add as an arguement.  not a pointer to one, not a pointer to the
> data element inside of it.  ;)  so the following will work for you:

>   struct in_addr haddr;
>   inet_aton("192.168.1.2", &haddr);
>   printf( "%s\n", inet_ntoa(haddr));

> yes, it's that simple.  :)

>         Regards,

>            Phro

--
--------------------------------
Sasha Kacanski
240 Murray Avenue
Ann Arbor, MI 48103
http://www.veryComputer.com/~sasha

--------------------------
farcical - laughably inept
 
 
 

1. implicit declaration of function 'inet_ntoa'

when I compile a program of mine, it gives the warning:

implicit declaration of function 'inet_ntoa'
the line this warning is on is:

char *ip;
struct hostent *h;

ip = inet_ntoa(*((struct in_addr*)h->h_addr));

what does this mean?
It's only a warning and everything else compiles fine, but I'd still
like to know.

thanks,

--
Aaron Walker

http://iconmedia.com/aaron

2. Problems with monitor

3. function, function...who's got the function?

4. Help with NIS+ and domainname

5. inet_ntoa problem

6. Kernel for ATI

7. what's going on with inet_ntoa() ?

8. font Efont for root in suse 7.2 kde upgraded to 2.2.1 - why? how to fix? regular users are fine, some computers are fine also...

9. inet_ntoa

10. Is inet_ntoa thread-safe on AIX 4.3?

11. problem with inet_ntoa/inet_ntop

12. inet_aton and inet_ntoa under Solaris7/8

13. What library is 'inet_ntoa' in ?