Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

hex.c

Go to the documentation of this file.
00001 /*
00002  * hex.c
00003  *
00004  * Copyright (c) 2001 Dug Song <dugsong@monkey.org>
00005  *
00006  * $Id: hex.c,v 1.6 2004/03/28 17:38:18 dugsong Exp $
00007  */
00008 
00009 #include "config.h"
00010 
00011 #include <sys/types.h>
00012 
00013 #include <err.h>
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 #include <unistd.h>
00017 
00018 #include "dnet.h"
00019 #include "aton.h"
00020 #include "mod.h"
00021 
00022 void
00023 hex_usage(void)
00024 {
00025         fprintf(stderr, "Usage: dnet hex <string> ...\n");
00026         exit(1);
00027 }
00028 
00029 int
00030 hex_main(int argc, char *argv[])
00031 {
00032         char buf[IP_LEN_MAX], *p = buf;
00033         int c, len;
00034         
00035         if (argc == 1 || *(argv[1]) == '-')
00036                 hex_usage();
00037         
00038         for (c = 1; c < argc; c++) {
00039                 if ((len = fmt_aton(argv[c], (u_char *)argv[c])) < 0)
00040                         hex_usage();
00041                 
00042                 if (write(STDOUT_FILENO, argv[c], len) != len)
00043                         err(1, "write");
00044         }
00045         if (!isatty(STDIN_FILENO)) {
00046                 len = sizeof(buf);
00047                 while ((c = read(STDIN_FILENO, p, len)) > 0) {
00048                         p += c;
00049                         len -= c;
00050                 }
00051                 len = p - buf;
00052                 if (write(STDOUT_FILENO, buf, len) != len)
00053                         err(1, "write");
00054         }                                  
00055         return (0);
00056 }
00057 
00058 struct mod mod_hex = {
00059         "hex",
00060         MOD_TYPE_DATA,
00061         hex_main
00062 };

Generated on Sun May 14 14:51:12 2006 by  doxygen 1.4.2