2 * $Id: libnet_link_nit.c,v 1.1.1.1 2000/05/25 00:28:49 route Exp $
5 * libnet_nit.c - network interface tap routines
7 * Copyright (c) 1998 - 2001 Mike D. Schiffman <mike@infonexus.com>
10 * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996
11 * The Regents of the University of California. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that: (1) source code distributions
15 * retain the above copyright notice and this paragraph in its entirety, (2)
16 * distributions including binary code include the above copyright notice and
17 * this paragraph in its entirety in the documentation or other materials
18 * provided with the distribution, and (3) all advertising materials mentioning
19 * features or use of this software display the following acknowledgement:
20 * ``This product includes software developed by the University of California,
21 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
22 * the University nor the names of its contributors may be used to endorse
23 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
27 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
31 #include "../include/config.h"
33 #include "../include/libnet.h"
35 #include "../include/gnuc.h"
36 #ifdef HAVE_OS_PROTO_H
37 #include "../include/os-proto.h"
40 struct libnet_link_int *
41 libnet_open_link_interface(char *device, char *ebuf)
43 struct sockaddr_nit snit;
44 register struct libnet_link_int *l;
46 l = (struct libnet_link_int *)malloc(sizeof(*p));
49 strcpy(ebuf, ll_strerror(errno));
53 memset(l, 0, sizeof(*l));
55 l->fd = socket(AF_NIT, SOCK_RAW, NITPROTO_RAW);
58 sprintf(ebuf, "socket: %s", ll_strerror(errno));
61 snit.snit_family = AF_NIT;
62 strncpy(snit.snit_ifname, device, NITIFSIZ);
64 if (bind(l->fd, (struct sockaddr *)&snit, sizeof(snit)))
66 sprintf(ebuf, "bind: %s: %s", snit.snit_ifname, ll_strerror(errno));
71 * NIT supports only ethernets.
73 l->linktype = DLT_EN10MB;
88 libnet_close_link_interface(struct libnet_link_int *l)
90 if (close(l->fd) == 0)
102 write_link_layer(struct libnet_link_int *l, const char *device,
103 u_char *buf, int len)
108 memset(&sa, 0, sizeof(sa));
109 strncpy(sa.sa_data, device, sizeof(sa.sa_data));
111 c = sendto(l->fd, buf, len, 0, &sa, sizeof(sa));
115 libnet_error(LN_ERR_WARNING,
116 "write_link_layer: %d bytes written (%s)\n", c,