ip address to hexadecimal converter

Derek Martin ddm at pizzashack.org
Sat Apr 28 21:52:52 EDT 2001


On Fri, Apr 27, 2001 at 09:59:21AM -0400, Robert Sarao wrote:
> Good morning,
> 
>        Does anyone have a software package that they love that converts the 
> ip octet address to hexadecimal. Something simple, we just have to do some 
> conversion and it would be a nice tool...


/* This simple program has little error checking but does the job. */
/* Obviously you should modify it as necessary.                    */ 


#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main( int argc, char **argv ){

    struct in_addr address;

    if ( argc != 2 ){
	fprintf( stderr, "Please supply exactly one argument\n\n" );
	exit( 1 );
    }

    inet_aton( argv[1], &address );

    printf( "0x%0.8x\n", ntohl( address.s_addr ) );

    exit( 0 );

}



--
---------------------------------------------------
Derek Martin          |   Unix/Linux geek
ddm at pizzashack.org    |   GnuPG Key ID: 0x81CFE75D
Retrieve my public key at http://pgp.mit.edu

-
Subcription/unsubscription/info requests: send e-mail with
"subscribe", "unsubscribe", or "info" on the first line of the
message body to discuss-request at blu.org (Subject line is ignored).



More information about the Discuss mailing list