home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / N / TCPIP / NET-TOOL.1 / NET-TOOL / net-tools / lib / slip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-19  |  3.0 KB  |  134 lines

  1. /*
  2.  * NET-2    This file contains the SLIP support for the NET-2 base
  3.  *        distribution.
  4.  *
  5.  * Version:    @(#)slip.c    1.10    10/07/93
  6.  *
  7.  * Author:    Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  8.  *        Copyright 1993 MicroWalt Corporation
  9.  *
  10.  *        Modified by Alan Cox, May 94 to cover NET-3
  11.  *
  12.  *        This program is free software; you can redistribute it
  13.  *        and/or  modify it under  the terms of  the GNU General
  14.  *        Public  License as  published  by  the  Free  Software
  15.  *        Foundation;  either  version 2 of the License, or  (at
  16.  *        your option) any later version.
  17.  */
  18. #include "config.h"
  19.  
  20. #if HAVE_HWSLIP
  21.  
  22. #include <sys/types.h>
  23. #include <sys/ioctl.h>
  24. #include <sys/socket.h>
  25. #include <linux/if.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <ctype.h>
  29. #include <errno.h>
  30. #include <fcntl.h>
  31. #include <string.h>
  32. #include <termios.h>
  33. #include <unistd.h>
  34. #include "support.h"
  35. #include "pathnames.h"
  36.  
  37.  
  38. /* Set the line discipline of a terminal line. */
  39. static int
  40. 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
  52. SLIP_set_encap(int fd, int encap)
  53. {
  54.   if (ioctl(fd, SIOCSIFENCAP, &encap) < 0) {
  55.     fprintf(stderr, "SLIP_set_encap(%d): %s\n", encap, strerror(errno));
  56.     return(-errno);
  57.   }
  58.   return(0);
  59. }
  60.  
  61.  
  62. /* Start the SLIP encapsulation on the file descriptor. */
  63. static int
  64. do_slip(int fd)
  65. {
  66.   if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
  67.   if (SLIP_set_encap(fd, 0) < 0) return(-1);
  68.   return(0);
  69. }
  70.  
  71.  
  72. /* Start the VJ-SLIP encapsulation on the file descriptor. */
  73. static int
  74. do_cslip(int fd)
  75. {
  76.   if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
  77.   if (SLIP_set_encap(fd, 1) < 0) return(-1);
  78.   return(0);
  79. }
  80.  
  81.  
  82. /* Start the SLIP-6 encapsulation on the file descriptor. */
  83. static int
  84. do_slip6(int fd)
  85. {
  86.   if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
  87.   if (SLIP_set_encap(fd, 2) < 0) return(-1);
  88.   return(0);
  89. }
  90.  
  91.  
  92. /* Start the VJ-SLIP-6 encapsulation on the file descriptor. */
  93. static int
  94. do_cslip6(int fd)
  95. {
  96.   if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
  97.   if (SLIP_set_encap(fd, 3) < 0) return(-1);
  98.   return(0);
  99. }
  100.  
  101. /* Start adaptive encapsulation on the file descriptor. */
  102. static int
  103. do_adaptive(int fd)
  104. {
  105.   if (SLIP_set_disc(fd, N_SLIP) < 0) return(-1);
  106.   if (SLIP_set_encap(fd, 8) < 0) return(-1);
  107.   return(0);
  108. }
  109.  
  110.  
  111. struct hwtype slip_hwtype = {
  112.   "slip",    "Serial Line IP",        ARPHRD_SLIP,    0,
  113.   NULL,        NULL,        NULL,        do_slip
  114. };
  115. struct hwtype cslip_hwtype = {
  116.   "cslip",    "VJ Serial Line IP",        ARPHRD_CSLIP,    0,
  117.   NULL,        NULL,        NULL,        do_cslip
  118. };
  119. struct hwtype slip6_hwtype = {
  120.   "slip6",    "6-bit Serial Line IP",        ARPHRD_SLIP6,    0,
  121.   NULL,        NULL,        NULL,        do_slip6
  122. };
  123. struct hwtype cslip6_hwtype = {
  124.   "cslip6",    "VJ 6-bit Serial Line IP",    ARPHRD_CSLIP6,    0,
  125.   NULL,        NULL,        NULL,        do_cslip6
  126. };
  127. struct hwtype adaptive_hwtype = {
  128.   "adaptive",    "Adaptive Serial Line IP",    ARPHRD_ADAPT,0,
  129.   NULL,        NULL,        NULL,        do_adaptive
  130. };
  131.  
  132.  
  133. #endif    /* HAVE_HWSLIP */
  134.