/***************************************************
 * IPConvert.c -- Main file for IPConvert          *
 * Author: stderr (stderr.dev@gmail.com)           *
 *                                                 *
 * Usage: Run program with ip as argument          *
 * Purpose: Convert IP address to a decimal number *
 *                                                 *
 * Note: In order to run this, you must have the   *
 * bc program on your linux computer. It is needed *
 * because this program requires the use of very   *
 * large numbers.                                  *
 ***************************************************/

#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
  char line[256];
  long dot1, dot2, dot3, dot4;
  
  if (argc < 2) {
    printf("Usage: %s <ip address>\n",argv[0]);
    exit(1);
  } 
  strncpy(line,argv[1],sizeof(line));
  
  sscanf(line,"%d.%d.%d.%d",&dot1,&dot2,&dot3,&dot4);
  sprintf(line,"echo \"(%d * 16777216) + (%d * 65536) + (%d * 256) + (%d * 1)\nquit\n\" | bc -q ",dot1,dot2,dot3,dot4);
  system(line);

  return 0;
}
