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

send.c

Go to the documentation of this file.
00001 /*
00002  * send.c
00003  *
00004  * Copyright (c) 2002 Dug Song <dugsong@monkey.org>
00005  *
00006  * $Id: send.c,v 1.3 2002/02/08 07:43:53 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 <string.h>
00017 #include <time.h>
00018 #include <unistd.h>
00019 
00020 #include "dnet.h"
00021 #include "aton.h"
00022 #include "mod.h"
00023 
00024 void
00025 send_usage(void)
00026 {
00027         fprintf(stderr, "Usage: dnet send [<device>]\n");
00028         exit(1);
00029 }
00030 
00031 int
00032 send_main(int argc, char *argv[])
00033 {
00034         eth_t *eth;
00035         ip_t *ip;
00036         u_char *p, buf[IP_LEN_MAX];     /* XXX */
00037         int c, len;
00038 
00039         if (argc == 2 && *(argv[1]) == '-')
00040                 send_usage();
00041         
00042         if (isatty(STDIN_FILENO))
00043                 errx(1, "can't read packet to send from tty");
00044 
00045         p = buf;
00046         len = sizeof(buf) - (p - buf);
00047         
00048         while ((c = read(STDIN_FILENO, p, len)) > 0) {
00049                 p += c;
00050                 len -= c;
00051         }
00052         len = p - buf;
00053         
00054         if (argc == 1) {
00055                 if ((ip = ip_open()) == NULL)
00056                         err(1, "ip_open");
00057                 if (ip_send(ip, buf, len) != len)
00058                         err(1, "ip_send");
00059                 ip_close(ip);
00060         } else if (argc == 2) {
00061                 if ((eth = eth_open(argv[1])) == NULL)
00062                         err(1, "eth_open");
00063                 if (eth_send(eth, buf, len) != len)
00064                         err(1, "eth_send");
00065                 eth_close(eth);
00066         } else
00067                 send_usage();
00068         
00069         exit(0);
00070 }
00071 
00072 struct mod mod_send = {
00073         "send",
00074         MOD_TYPE_XMIT,
00075         send_main
00076 };

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