aboutsummaryrefslogtreecommitdiff
blob: c48937b98b4171e1b2967588fd8256e99d269e5b (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * lib/slip_ac.c      This file contains the activation for the
 *                      SLIP line disciplines, called from activate_ld().
 *
 * Version:     $Id: slip_ac.c,v 1.3 1998/11/15 20:12:20 freitag Exp $
 *
 * Author:      Bernd 'eckes' Eckenfels
 *              Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
 *              Copyright 1993 MicroWalt Corporation
 *
 *              Modified by Alan Cox, May 94 to cover NET-3
 *
 *              This program is free software; you can redistribute it
 *              and/or  modify it under  the terms of  the GNU General
 *              Public  License as  published  by  the  Free  Software
 *              Foundation;  either  version 2 of the License, or  (at
 *              your option) any later version.
 */
#include "config.h"

#if HAVE_HWSLIP

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if_arp.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include "net-support.h"
#include "pathnames.h"


/* Set the line discipline of a terminal line. */
static int SLIP_set_disc(int fd, int disc)
{
    if (ioctl(fd, TIOCSETD, &disc) < 0) {
	fprintf(stderr, "SLIP_set_disc(%d): %s\n", disc, strerror(errno));
	return (-errno);
    }
    return (0);
}


/* Set the encapsulation type of a terminal line. */
static int SLIP_set_encap(int fd, int encap)
{
    if (ioctl(fd, SIOCSIFENCAP, &encap) < 0) {
	fprintf(stderr, "SLIP_set_encap(%d): %s\n", encap, strerror(errno));
	return (-errno);
    }
    return (0);
}


/* Start the SLIP encapsulation on the file descriptor. */
int SLIP_activate(int fd)
{
    if (SLIP_set_disc(fd, N_SLIP) < 0)
	return (-1);
    if (SLIP_set_encap(fd, 0) < 0)
	return (-1);
    return (0);
}


/* Start the VJ-SLIP encapsulation on the file descriptor. */
int CSLIP_activate(int fd)
{
    if (SLIP_set_disc(fd, N_SLIP) < 0)
	return (-1);
    if (SLIP_set_encap(fd, 1) < 0)
	return (-1);
    return (0);
}


/* Start the SLIP-6 encapsulation on the file descriptor. */
int SLIP6_activate(int fd)
{
    if (SLIP_set_disc(fd, N_SLIP) < 0)
	return (-1);
    if (SLIP_set_encap(fd, 2) < 0)
	return (-1);
    return (0);
}


/* Start the VJ-SLIP-6 encapsulation on the file descriptor. */
int CSLIP6_activate(int fd)
{
    if (SLIP_set_disc(fd, N_SLIP) < 0)
	return (-1);
    if (SLIP_set_encap(fd, 3) < 0)
	return (-1);
    return (0);
}


/* Start adaptive encapsulation on the file descriptor. */
int ADAPTIVE_activate(int fd)
{
    if (SLIP_set_disc(fd, N_SLIP) < 0)
	return (-1);
    if (SLIP_set_encap(fd, 8) < 0)
	return (-1);
    return (0);
}
#endif				/* HAVE_HWSLIP */