inet_aton() function problems Any help appreciated!

inet_aton() function problems Any help appreciated!

Post by Chris Wrigh » Tue, 10 Jul 2001 07:57:02



Hello everyone,

I made a decision to try some linux programming this weekend.  I wanted to
try out the inet_aton function which is supposed to convert a normal ip to
its decimal value right?

here is the problem.  When i run the program and pass it 192.168.0.1 it
returns 16820416.
unfortunately that integer is the decimal value of 1.0.168.192
1.0.0.0 returns 1
0.0.0.1 returns 16777216

everything is backwards!

=(
needlesss to say i am a little confused.  Any help would be greatly
appreciated!

Here is the code i used:

#include <stdio.h>
#include <arpa/inet.h>

int main (int argc, char **argv)
{
    struct in_addr FullAddress;
    char *ipaddr;
    printf("%d\n",argc);
    if(argc<2){
        printf("You did not provide a parameter!\n");
        exit(1);
    }
    else{
        ipaddr = argv[1];
        inet_aton(argv[1], &FullAddress);
        printf("The Decimal value of your ip is: %lu\n", FullAddress);
    }
    return 0;

Quote:}

-Chris Wright

 
 
 

inet_aton() function problems Any help appreciated!

Post by Casper H.S. Dik - Network Security Engine » Tue, 10 Jul 2001 08:29:06


[[ PLEASE DON'T SEND ME EMAIL COPIES OF POSTINGS ]]


>I made a decision to try some linux programming this weekend.  I wanted to
>try out the inet_aton function which is supposed to convert a normal ip to
>its decimal value right?

Not quite; it converts a "dotted quad" representation of an IP address
into a binary representation of the IP address.

IP addresses are represented in network byte order; that is, MSB first.
Presumably you're using a little endian system (Intel) which has
the bytes in a number reversed when compared to network byte order.

Casper
--
Expressed in this posting are my opinions.  They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.

 
 
 

inet_aton() function problems Any help appreciated!

Post by Scott Neugrosch » Tue, 10 Jul 2001 14:57:17


man ntohl


> Hello everyone,

> I made a decision to try some linux programming this weekend.  I wanted to
> try out the inet_aton function which is supposed to convert a normal ip to
> its decimal value right?

> here is the problem.  When i run the program and pass it 192.168.0.1 it
> returns 16820416.
> unfortunately that integer is the decimal value of 1.0.168.192
> 1.0.0.0 returns 1
> 0.0.0.1 returns 16777216

> everything is backwards!

> =(
> needlesss to say i am a little confused.  Any help would be greatly
> appreciated!

> Here is the code i used:

> #include <stdio.h>
> #include <arpa/inet.h>

> int main (int argc, char **argv)
> {
>     struct in_addr FullAddress;
>     char *ipaddr;
>     printf("%d\n",argc);
>     if(argc<2){
>         printf("You did not provide a parameter!\n");
>         exit(1);
>     }
>     else{
>         ipaddr = argv[1];
>         inet_aton(argv[1], &FullAddress);
>         printf("The Decimal value of your ip is: %lu\n", FullAddress);
>     }
>     return 0;
> }

> -Chris Wright


 
 
 

inet_aton() function problems Any help appreciated!

Post by Donald McLachl » Tue, 10 Jul 2001 21:09:35


man htonl

--

Communications Research Centre / RNS    Tel     (613) 998-2845
3701 Carling Ave.,                      Fax     (613) 998-9648
Ottawa, Ontario
K2H 8S2
Canada

 
 
 

1. Use of inet_aton() function

Could someone give me a 4 or 5 line example of code showing the correct
syntax for
using the inet_aton() function.  I have tried nearly every possible
combination in my code
and can't seem to get it to compile.

for example:

struct sockaddr_in temp;
if (inet_aton("147.226.53.6", &(WHAT GOES HERE))
  printf ("works\n");

Thanks for any help you can give me.

Jeff Hanks


2. Solaris 2.3/PPP Woes

3. Help please - strange FTP problem - any help much appreciated :)

4. Module rewrite 16/20: module_put_return for x86

5. Samba - XP problem - appreciate the help!

6. Contest v0.51 benchmark

7. Odd problem with vi, would appreciate help

8. Virtual Host Help needed !

9. 3 small problems. Help appreciated

10. .cw/.cf config problem with local & internet hostname - help appreciated

11. small PPP problem.. help appreciated!

12. help with inet_aton IP conversion...

13. Linux Crash & Partition Problem: Help Appreciated