Ejemplo n.º 1
0
Archivo: inp.c Proyecto: 174high/ldd3
int main(int argc, char **argv)
{
    unsigned int i, n, port, size, error = 0;
    
    prgname = argv[0];
    /* find the data size */
    switch (prgname[strlen(prgname)-1]) {
        case 'w': size = 2; break;
        case 'l': size = 4; break;
        case 'b': case 'p': default:
	    size = 1;
    }

    setuid(0); /* if we're setuid, force it on */
    for (i = 1; i < argc; i++) {
        if ( sscanf(argv[i], "%x%n", &port, &n) < 1
	      || n != strlen(argv[i]) ) {
	    fprintf(stderr, "%s: argument \"%s\" is not a hex number\n",
		    argv[0], argv[i]);
	    error++; continue;
	}
	if (port & (size-1)) {
	    fprintf(stderr, "%s: argument \"%s\" is not properly aligned\n",
		    argv[0], argv[i]);
	    error++; continue;
	}
	error += read_and_print_one(port, size);
    }
    exit (error ? 1 : 0);
}
Ejemplo n.º 2
0
int main(int argc, char** argv) {
  unsigned int i, n, port, size, error = 0;

  progname = argv[0];
  switch (progname[strlen(progname)-1]) {
  case 'w':
    size = 2; break;
  case 'l':
    size = 4; break;
  case 'b':
  case 'p':
  default:
    size = 1;
  }

  setuid(0);
  for (i = 1; i < argc; ++i) {
    if (sscanf(argv[i], "%x%n", &port, &n) < 1 || n != strlen(argv[i])) {
      fprintf(stderr, "%s: argument '%s' is not a hex number\n", argv[0], argv[i]);
      ++error;
      continue;
    }
    if (port & (size-1)) {
      fprintf(stderr, "%s: argument '%s' is not properly aligned\n", argv[0], argv[i]);
      ++error;
      continue;
    }
    error += read_and_print_one(port, size);
  }

  exit(error ? 1 : 0);
}