enable -fno-strict-aliasing until the code base gets a hefty clean up to fix all...
[platform/upstream/net-tools.git] / lib / slip_ac.c
1 /*
2  * lib/slip_ac.c      This file contains the activation for the
3  *                      SLIP line disciplines, called from activate_ld().
4  *
5  * Version:     $Id: slip_ac.c,v 1.3 1998/11/15 20:12:20 freitag Exp $
6  *
7  * Author:      Bernd 'eckes' Eckenfels
8  *              Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
9  *              Copyright 1993 MicroWalt Corporation
10  *
11  *              Modified by Alan Cox, May 94 to cover NET-3
12  *
13  *              This program is free software; you can redistribute it
14  *              and/or  modify it under  the terms of  the GNU General
15  *              Public  License as  published  by  the  Free  Software
16  *              Foundation;  either  version 2 of the License, or  (at
17  *              your option) any later version.
18  */
19 #include "config.h"
20
21 #if HAVE_HWSLIP
22
23 #include <sys/types.h>
24 #include <sys/ioctl.h>
25 #include <sys/socket.h>
26 #include <net/if_arp.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <ctype.h>
30 #include <errno.h>
31 #include <fcntl.h>
32 #include <string.h>
33 #include <termios.h>
34 #include <unistd.h>
35 #include "net-support.h"
36 #include "pathnames.h"
37
38
39 /* Set the line discipline of a terminal line. */
40 static int SLIP_set_disc(int fd, int disc)
41 {
42     if (ioctl(fd, TIOCSETD, &disc) < 0) {
43         fprintf(stderr, "SLIP_set_disc(%d): %s\n", disc, strerror(errno));
44         return (-errno);
45     }
46     return (0);
47 }
48
49
50 /* Set the encapsulation type of a terminal line. */
51 static int SLIP_set_encap(int fd, int encap)
52 {
53     if (ioctl(fd, SIOCSIFENCAP, &encap) < 0) {
54         fprintf(stderr, "SLIP_set_encap(%d): %s\n", encap, strerror(errno));
55         return (-errno);
56     }
57     return (0);
58 }
59
60
61 /* Start the SLIP encapsulation on the file descriptor. */
62 int SLIP_activate(int fd)
63 {
64     if (SLIP_set_disc(fd, N_SLIP) < 0)
65         return (-1);
66     if (SLIP_set_encap(fd, 0) < 0)
67         return (-1);
68     return (0);
69 }
70
71
72 /* Start the VJ-SLIP encapsulation on the file descriptor. */
73 int CSLIP_activate(int fd)
74 {
75     if (SLIP_set_disc(fd, N_SLIP) < 0)
76         return (-1);
77     if (SLIP_set_encap(fd, 1) < 0)
78         return (-1);
79     return (0);
80 }
81
82
83 /* Start the SLIP-6 encapsulation on the file descriptor. */
84 int SLIP6_activate(int fd)
85 {
86     if (SLIP_set_disc(fd, N_SLIP) < 0)
87         return (-1);
88     if (SLIP_set_encap(fd, 2) < 0)
89         return (-1);
90     return (0);
91 }
92
93
94 /* Start the VJ-SLIP-6 encapsulation on the file descriptor. */
95 int CSLIP6_activate(int fd)
96 {
97     if (SLIP_set_disc(fd, N_SLIP) < 0)
98         return (-1);
99     if (SLIP_set_encap(fd, 3) < 0)
100         return (-1);
101     return (0);
102 }
103
104
105 /* Start adaptive encapsulation on the file descriptor. */
106 int ADAPTIVE_activate(int fd)
107 {
108     if (SLIP_set_disc(fd, N_SLIP) < 0)
109         return (-1);
110     if (SLIP_set_encap(fd, 8) < 0)
111         return (-1);
112     return (0);
113 }
114 #endif                          /* HAVE_HWSLIP */