Re: alternative way of addressing

From: Chris Hall (bnyec@yahoo.com)
Date: 01/28/02


Date: Sun, 27 Jan 2002 18:45:15 -0800 (PST)
From: Chris Hall <bnyec@yahoo.com>
To: "J. Reilink" <digiover@dsinet.org>


John Doe wrote:
>
> Hi.
>
> I remember a while back on this list, there was a
discussion of alternative
> ways of addressing URLs (using hex code and binary,
I think). Can anyone
> give me a refresher course?
>
>Check here:
>http://www.pc-help.org/obscure.htm
>"How to Obscure Any URL"

   Using above info, i have written a small program
 that will do conversion from decmial to IP and back
;-)

---------------
/*
         IP 2 Decimal and Back agian
        ------------------------------
  
 Ever see a URL in the form of
 http://3232235521/
  Basicly all that is the actual decimal value of
  192.168.0.1
  This Program converts an IP ( dotted notation ) to
 the Decimal ( dotless notation) and Back agian.

    Compile:
       gcc -lm -o ip2d ip2d.c

 For more Conversion info:
   http://www.pc-help.org/obscure.htm

bnyec@yahoo.com

*/

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int a,b,c,d;
char ip_address[20];
double num,num2,num3,num4;
int x,x2,x3,x4;
unsigned int numa;

int main(int argc, char *argv[])
{
       if(argc!=2) {
        printf("\nUsage: %s [-c] [-d]\n",argv[0]);
        printf("\t\t-c --- IP to Decimal\n");
        printf("\t\t-d --- Decimal to IP\n\n");
         exit(1);
      }
        if(argv[1][0]=='-' && argv[1][1] =='c') {
           printf("Enter IP to Convert: ");
              fgets(ip_address, sizeof(ip_address),
stdin);
              
sscanf(ip_address,"%d.%d.%d.%d",&a,&b,&c,&d);

  /* Convert Dotted notation to dotless Notation */
         num=(pow(256,3))*a;
         num2=(pow(256,2))*b;
         num3=256*c;
         num4=num+num2+num3+d;
           
            printf("%0.f\n",num4);
          }
            
          if(argv[1][0]=='-' && argv[1][1] =='d') {
             printf("Enter Number to Convert: ");
              fgets(ip_address, sizeof(ip_address),
stdin);
               sscanf(ip_address,"%u",&numa);

  /* Covert Dotless notation to dotted Notation */
       
         x=numa/pow(256,3);
         x2=(numa-(x*pow(256,3)))/pow(256,2);
        
x3=((numa-(x*pow(256,3)))-(x2*pow(256,2)))/256;
        
x4=(((numa-(x*(pow(256,3))))-(x2*(pow(256,2))))-(x3*256));

         printf("%d.%d.%d.%d\n",x,x2,x3,x4);
        }
 
 return(0);
}

__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions!
http://auctions.yahoo.com



Relevant Pages

  • Re: Using epoll with real files
    ... I did not want to use a blocking write from the logging thread which lead me down this lane and I started playing with O_NONBLOCK and epoll. ... int main(int argc, char *argv) { ... Interestingly it does work reading from tty stdin, it also works when piping to stdin, but not when redirecting a file to stdin. ...
    (comp.os.linux.development.system)
  • Re: stdin problem.
    ... I'm betting that you declared your variable as a char rather than an int, ... You should store it in an int. ... but if not stdin will be the terminal IE. keyboard. ... // Don't read stdin from the terminal just from a redirected file. ...
    (comp.unix.programmer)
  • Re: help with select()
    ... > to monitor a socket and stdin. ... > int main{ ... > char buf; ... > addr_len = sizeof(struct sockaddr); ...
    (comp.unix.programmer)
  • Re: Programmer wannabee question about sscanf
    ... int start, finish, values; ... char line; ... good habit to get into. ... fgets, stdin); ...
    (comp.lang.c)
  • Compile error
    ... int main ... char h; ... struct hostent *x; ... Do you Yahoo!? ...
    (freebsd-questions)