Annotation of embedaddon/libnet/sample/dot1x.c, revision 1.1
1.1 ! misho 1: /*
! 2: * $Id: dot1x.c,v 1.2 2004/01/03 20:31:01 mike Exp $
! 3: *
! 4: * libnet 1.1
! 5: * Build a dot1x packet
! 6: *
! 7: * Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
! 8: * All rights reserved.
! 9: *
! 10: * Redistribution and use in source and binary forms, with or without
! 11: * modification, are permitted provided that the following conditions
! 12: * are met:
! 13: * 1. Redistributions of source code must retain the above copyright
! 14: * notice, this list of conditions and the following disclaimer.
! 15: * 2. Redistributions in binary form must reproduce the above copyright
! 16: * notice, this list of conditions and the following disclaimer in the
! 17: * documentation and/or other materials provided with the distribution.
! 18: *
! 19: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
! 20: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 21: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 22: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
! 23: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 24: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 25: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 26: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 27: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 28: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 29: * SUCH DAMAGE.
! 30: *
! 31: */
! 32:
! 33: #if (HAVE_CONFIG_H)
! 34: #include "../include/config.h"
! 35: #endif
! 36: #include "./libnet_test.h"
! 37:
! 38: int
! 39: main(int argc, char *argv[])
! 40: {
! 41: int c;
! 42: libnet_t *l;
! 43: libnet_ptag_t t;
! 44: u_char eap_dst[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x03};
! 45: char *device = NULL;
! 46: char errbuf[LIBNET_ERRBUF_SIZE];
! 47: /* Code Id Length(2) Type DesiredType */
! 48: char payload[] = {0x01, 0x0a, 0x00, 0x7f, 0x03, 0x05};
! 49:
! 50: printf("libnet 1.1 packet shaping: dot1x\n");
! 51:
! 52: if (argc > 1)
! 53: {
! 54: device = argv[1];
! 55: }
! 56: l = libnet_init(
! 57: LIBNET_LINK_ADV, /* injection type */
! 58: device, /* network interface */
! 59: errbuf); /* errbuf */
! 60:
! 61: if (l == NULL)
! 62: {
! 63: fprintf(stderr, "libnet_init() failed: %s", errbuf);
! 64: exit(EXIT_FAILURE);
! 65: }
! 66:
! 67: t = libnet_build_802_1x(
! 68: 0,
! 69: LIBNET_802_1X_PACKET,
! 70: sizeof(payload),
! 71: payload,
! 72: sizeof(payload),
! 73: l,
! 74: 0);
! 75: if (t == -1)
! 76: {
! 77: fprintf(stderr, "Can't build dot1x header: %s\n", libnet_geterror(l));
! 78: goto bad;
! 79: }
! 80:
! 81: t = libnet_autobuild_ethernet(
! 82: eap_dst, /* ethernet destination */
! 83: ETHERTYPE_EAP, /* protocol type */
! 84: l); /* libnet handle */
! 85: if (t == -1)
! 86: {
! 87: fprintf(stderr, "Can't build ethernet header: %s\n", libnet_geterror(l));
! 88: goto bad;
! 89: }
! 90:
! 91: /*
! 92: * Write it to the wire.
! 93: */
! 94: c = libnet_write(l);
! 95:
! 96: if (c == -1)
! 97: {
! 98: fprintf(stderr, "Write error: %s\n", libnet_geterror(l));
! 99: goto bad;
! 100: }
! 101: else
! 102: {
! 103: fprintf(stderr, "Wrote %d byte dot1x packet from context \"%s\"; "
! 104: "check the wire.\n", c, libnet_cq_getlabel(l));
! 105: }
! 106: libnet_destroy(l);
! 107: return (EXIT_SUCCESS);
! 108: bad:
! 109: libnet_destroy(l);
! 110: return (EXIT_FAILURE);
! 111: }
! 112:
! 113: /* EOF */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>