1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
/*
* send.c
*
* Copyright (c) 2002 Dug Song <dugsong@monkey.org>
*
* $Id$
*/
#include "config.h"
#include <sys/types.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "dumbnet.h"
#include "aton.h"
#include "mod.h"
void
send_usage(void)
{
fprintf(stderr, "Usage: dnet send [<device>]\n");
exit(1);
}
int
send_main(int argc, char *argv[])
{
eth_t *eth;
ip_t *ip;
u_char *p, buf[IP_LEN_MAX]; /* XXX */
int c, len;
if (argc == 2 && *(argv[1]) == '-')
send_usage();
if (isatty(STDIN_FILENO))
errx(1, "can't read packet to send from tty");
p = buf;
len = sizeof(buf) - (p - buf);
while ((c = read(STDIN_FILENO, p, len)) > 0) {
p += c;
len -= c;
}
len = p - buf;
if (argc == 1) {
if ((ip = ip_open()) == NULL)
err(1, "ip_open");
if (ip_send(ip, buf, len) != len)
err(1, "ip_send");
ip_close(ip);
} else if (argc == 2) {
if ((eth = eth_open(argv[1])) == NULL)
err(1, "eth_open");
if (eth_send(eth, buf, len) != len)
err(1, "eth_send");
eth_close(eth);
} else
send_usage();
exit(0);
}
struct mod mod_send = {
"send",
MOD_TYPE_XMIT,
send_main
};
|