home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / sysVr4386slip / part03 < prev    next >
Text File  |  1991-03-21  |  55KB  |  1,925 lines

  1. Subject:  v24i080:  SystemVr4/386 SLIP driver and utilities, Part03/04
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: b6968f4d c4954b41 b3910112 a385008b
  5.  
  6. Submitted-by: sudji@indo.intel.com (Sudji Husodo)
  7. Posting-number: Volume 24, Issue 80
  8. Archive-name: sysVr4386slip/part03
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then feed it
  12. # into a shell via "sh file" or similar.  To overwrite existing files,
  13. # type "sh file -c".
  14. # The tool that generated this appeared in the comp.sources.unix newsgroup;
  15. # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
  16. # Contents:  dialslip/mkslipuser.c dialslip/slip.c dialslip/slip.h
  17. #   man/man1/dslipuser.1 man/man1/mkslipuser.1 man/man1/slattach.1
  18. #   man/man1/sldetach.1 man/man1/slip.1 man/man7/slip.7
  19. #   utils/slattach.c utils/slhangupd.c
  20. # Wrapped by rsalz@litchi.bbn.com on Fri Mar 22 11:57:12 1991
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. echo If this archive is complete, you will see the following message:
  23. echo '          "shar: End of archive 3 (of 4)."'
  24. if test -f 'dialslip/mkslipuser.c' -a "${1}" != "-c" ; then 
  25.   echo shar: Will not clobber existing file \"'dialslip/mkslipuser.c'\"
  26. else
  27.   echo shar: Extracting \"'dialslip/mkslipuser.c'\" \(3115 characters\)
  28.   sed "s/^X//" >'dialslip/mkslipuser.c' <<'END_OF_FILE'
  29. X
  30. X/*
  31. X * mkslipuser.c
  32. X *
  33. X * Creates a blank user file based on a description of the network
  34. X * configuration.  Initializes the dialup slip system.
  35. X *
  36. X * Copyright 1987 by University of California, Davis
  37. X *
  38. X * Greg Whitehead 10-1-87
  39. X * Computing Services
  40. X * University of California, Davis
  41. X */
  42. X
  43. X/*
  44. X * This program creates the dialup slip USER_FL based on information supplied
  45. X * either on the command line or in a configuration file. The configuration
  46. X * file consists of a number of one-line entries; one for each simultaneous
  47. X * login that is allowed. The number of simultaneous logins must, of course,
  48. X * be less than or equal to the number of interfaces available. Each one-line
  49. X * entry contains an internet address (a.b.c.d or hostname format) for the
  50. X * server side of the slip line. They may all be the same, or they may be
  51. X * different, depending on how you prefer to administer your network. The
  52. X * configuration file may also contain comments (lines starting with a #). In
  53. X * the case where all of the server side addresses are the same, command line
  54. X * arguments may be used instead of the configuration file. The first argument
  55. X * is the number of simultaneous logins to allow, and the second argument is
  56. X * the address of the server side of the point-point link.
  57. X *
  58. X * Modified by Geoff Arnold, Sun Microsystems 10-21-87:
  59. X *
  60. X * Allow a hostname instead of a dotted internet address.
  61. X *
  62. X */
  63. X
  64. X#include <stdio.h>
  65. X#include <ctype.h>
  66. X#include <sys/types.h>
  67. X#include <sys/file.h>
  68. X#include <string.h>
  69. X#include <netinet/in.h>
  70. X#include <netdb.h>
  71. X#include <arpa/inet.h>
  72. X#include "slip.h"
  73. X
  74. X#ifdef USG
  75. X#  include <sys/fcntl.h>
  76. X#endif
  77. X
  78. Xmain(argc,argv)
  79. Xint argc;
  80. Xchar **argv;
  81. X{
  82. X    FILE *cfd;
  83. X    char cline[80];
  84. X    int ufd;
  85. X    struct sl_urec urec;
  86. X    int x;
  87. X
  88. X
  89. X    /*
  90. X     * Open CONFIG_FL if the neccessary arguments aren't available on the
  91. X     * command line. If the file isn't there either then give usage.
  92. X     *
  93. X     */
  94. X    if (argc<3 && (cfd=fopen(CONFIG_FL,"r"))==NULL) {
  95. X        fprintf(stderr,"usage: %s [count address]  (reads \"%s\" on default)",argv[0],CONFIG_FL);
  96. X        exit(1);
  97. X    }
  98. X
  99. X
  100. X    /*
  101. X     * Open USER_FL.
  102. X     *
  103. X     */
  104. X    if ((ufd=open(USER_FL,O_WRONLY|O_CREAT|O_TRUNC,0644))<0) {
  105. X    perror(USER_FL);
  106. X    exit(1);
  107. X    }
  108. X
  109. X
  110. X    /*
  111. X     * create USER_FL.
  112. X     *
  113. X     */
  114. X    urec.sl_uid = -1;
  115. X
  116. X    if (argc<3) {
  117. X    while (fgets(cline,80,cfd)!=NULL)
  118. X        if (*cline!='#')
  119. X        if (write_urec(ufd,urec,cline)<0) {
  120. X            fclose(cfd);
  121. X            exit(1);
  122. X        }
  123. X        fclose(cfd);
  124. X    }
  125. X
  126. X    else {
  127. X    for (x=0;x<atoi(argv[1]);x++) 
  128. X        if (write_urec(ufd,urec,argv[2])<0)
  129. X        exit(1);
  130. X    }
  131. X
  132. X    close(ufd);
  133. X}
  134. X
  135. X
  136. Xwrite_urec(ufd,urec,addr)
  137. Xint ufd;
  138. Xstruct sl_urec urec;
  139. Xchar *addr;
  140. X{
  141. X    struct hostent *h;
  142. X    char *c;
  143. X
  144. X    if (c = strchr(addr, '\n'))            /* zap the newline */
  145. X    *c = '\0';
  146. X
  147. X    if ((h = gethostbyname(addr)) == NULL)
  148. X    urec.sl_saddr.s_addr=inet_addr(addr);
  149. X    else
  150. X    urec.sl_saddr.s_addr = *((int *) h->h_addr); /* internet only */
  151. X
  152. X    if (write(ufd,&urec,sizeof(urec))!=sizeof(urec)){
  153. X    fprintf(stderr,"%s: write failed\n",USER_FL);
  154. X    close(ufd);
  155. X    return(-1);
  156. X        /* NOTREACHED */
  157. X    }
  158. X
  159. X    return(0);
  160. X}
  161. END_OF_FILE
  162.   if test 3115 -ne `wc -c <'dialslip/mkslipuser.c'`; then
  163.     echo shar: \"'dialslip/mkslipuser.c'\" unpacked with wrong size!
  164.   fi
  165.   # end of 'dialslip/mkslipuser.c'
  166. fi
  167. if test -f 'dialslip/slip.c' -a "${1}" != "-c" ; then 
  168.   echo shar: Will not clobber existing file \"'dialslip/slip.c'\"
  169. else
  170.   echo shar: Extracting \"'dialslip/slip.c'\" \(11967 characters\)
  171.   sed "s/^X//" >'dialslip/slip.c' <<'END_OF_FILE'
  172. X
  173. X/*
  174. X * slip.c
  175. X *
  176. X * Dialup slip line allocator.
  177. X *
  178. X * Copyright 1987 by University of California, Davis
  179. X *
  180. X * Greg Whitehead 10-1-87
  181. X * Computing Services
  182. X * University of California, Davis
  183. X */
  184. X
  185. X/*
  186. X * This program provides a means to obtain a slip line on a dialup tty.
  187. X * It reads the file USER_FL to determine if an interface is available,
  188. X * and to make sure that no internet address logs in more than once.
  189. X * It updates the file with each login/disconnect in order to maintain
  190. X * a record of which addresses are attached to which interfaces.
  191. X *
  192. X * In order to "ifconfig" and "slattach", slip must run setuid to root.
  193. X *
  194. X * Extensively modified by
  195. X *
  196. X *    Geoff Arnold
  197. X *    Sun Microsystems Inc.
  198. X *    10-28-87
  199. X *
  200. X * Modifications include:
  201. X *
  202. X * - allowing hostnames instead of dotted addresses (see also "mkslipuser")
  203. X * - writing a line describing the configuration assigned by "sunslip"
  204. X *   to stdout; a corresponding PC program can parse this and use the
  205. X *   addressing information to check/update its local state
  206. X * - for Sun systems, replacing the calls to slattach/ifconfig with the
  207. X *   equivalent ioctls
  208. X *
  209. X * Lightly modified by:
  210. X *    Sudji Husodo      2-8-91
  211. X *
  212. X * Modifications:
  213. X *  - ported to Unix System V/386 Release 4.0. (actually done by Alan Batie).
  214. X *  - modified to log slip activities to /var/slip/slip.log if the file exists.
  215. X *  - changed the call to "system" to fork and exec, so we don't have to setuid
  216. X *    slattach and ifconfig to root.
  217. X */
  218. X
  219. X#ifdef sun
  220. X#define YELLOW_PAGES    1 /* assumes SLIP server is a YP server too */
  221. X#endif sun
  222. X
  223. X#include <stdio.h>
  224. X#include <signal.h>
  225. X#include <ctype.h>
  226. X#include <sgtty.h>
  227. X#include <time.h>
  228. X#include <sys/types.h>
  229. X#include <sys/file.h>
  230. X#include <sys/socket.h>
  231. X#include <net/if.h>
  232. X#include <netdb.h>
  233. X#include <sys/stat.h>
  234. X#include <netinet/in.h>
  235. X#include <arpa/inet.h>
  236. X#include "slip.h"
  237. X
  238. X#ifdef USG
  239. X#  include <unistd.h>
  240. X#  include <sys/fcntl.h>
  241. X#endif
  242. X
  243. Xchar *ttyname();
  244. Xchar *getlogin();
  245. X
  246. Xvoid bye();            /* SIGHUP handler to remove USER_FL entry */
  247. X
  248. X
  249. Xint ufd = -1;            /* global info on USER_FL entry */
  250. Xstruct sl_urec urec;
  251. Xint urec_i = -1;
  252. X
  253. Xchar *tty, *name;
  254. X
  255. X#ifdef sun
  256. Xstruct ifreq ifr;
  257. X#endif sun
  258. X
  259. Xchar string [128];
  260. Xchar if_str [8];
  261. Xchar source[32];
  262. Xchar remote[32];
  263. Xchar pidstr[16];
  264. Xint  log = 1;
  265. Xint  fd_log;
  266. Xtime_t    clock_val;
  267. X
  268. Xmain(argc,argv)
  269. Xint argc;
  270. Xchar **argv;
  271. X{
  272. X    int uid;
  273. X
  274. X    FILE *hfd;
  275. X    char host_line[80], host_name[80], host_addr[80];
  276. X    struct in_addr addr;
  277. X    struct hostent *h, *hh;
  278. X    struct sl_urec urec_tmp;
  279. X    char sys_str[160];
  280. X    struct sgttyb sgtty;
  281. X    int disc = DISC;
  282. X    int unit;
  283. X    int x;
  284. X#ifdef sun
  285. X    int sockfd;
  286. X#endif sun
  287. X
  288. X#ifdef sun
  289. Xfprintf(stderr,"SUNSLIP\n");
  290. X#endif sun
  291. X
  292. X    /*
  293. X     * if we can not open nor append the log file, turn log off
  294. X     */
  295. X    if ((fd_log = open (LOG_FL, O_RDWR | O_APPEND)) < 0)
  296. X    log = 0;
  297. X    else {
  298. X    clock_val = time(0);
  299. X        sprintf (string, "%s started by %s at %s", argv[0], getlogin(), ctime(&clock_val));
  300. X        write (fd_log, string, strlen(string));
  301. X    }
  302. X
  303. X    /*
  304. X     * Mask all signals except SIGSTOP, SIGKILL, and SIGHUP.
  305. X     *
  306. X     */
  307. X     sigsetmask(~sigmask(SIGHUP));
  308. X     signal(SIGHUP,SIG_DFL);
  309. X
  310. X
  311. X    /*
  312. X     * Must have a tty to attach to.
  313. X     *
  314. X     */
  315. X    if ((tty=ttyname(0))==NULL) {
  316. X    fail("Bad login port", NULL);
  317. X    /* NOTREACHED */
  318. X    }
  319. X
  320. X
  321. X    /*
  322. X     * Need uid to put in USER_FL.
  323. X     * (checking it is paranoid, but complete)
  324. X     *
  325. X     */
  326. X    if ((uid=getuid())<0) {
  327. X    fail("Bad uid", NULL);
  328. X    /* NOTREACHED */
  329. X    }
  330. X
  331. X
  332. X    /*
  333. X     * Must have a login name to look up.
  334. X     *
  335. X     */
  336. X    if ((name=getlogin())==NULL) {
  337. X    fail("Bad login name", NULL);
  338. X    /* NOTREACHED */
  339. X    }
  340. X
  341. X    /*
  342. X     * Open HOST_FL.
  343. X     *
  344. X     */
  345. X    if ((hfd=fopen(HOST_FL,"r"))==NULL) {
  346. X    fail("Can't open list of valid user-host mappings", NULL);
  347. X    /* NOTREACHED */
  348. X    }
  349. X
  350. X
  351. X    /*
  352. X     * look up login name in host file.
  353. X     *
  354. X     */
  355. X    for (;;) {    
  356. X    if (fgets(host_line,80,hfd)==NULL) {
  357. X        fail("User %s is not authorized to connect to SLIP", name);
  358. X        /* NOTREACHED */
  359. X    }
  360. X        if (*host_line!='#' &&
  361. X        sscanf(host_line,"%s %s",host_addr,host_name)==2) {
  362. X
  363. X        if (strncmp(name,host_name,8)==0) {
  364. X        break;
  365. X        }
  366. X    }
  367. X    }
  368. X    fclose(hfd);
  369. X
  370. X
  371. X    /*
  372. X     * Build internet addr from HOST_FL entry.
  373. X     *
  374. X     */
  375. X    if((h = gethostbyname(host_addr)) != NULL)
  376. X        addr.s_addr = *((int *)h->h_addr);
  377. X    else if ((addr.s_addr=inet_addr(host_addr))<0) {
  378. X    fail("Invalid address %s in hosts file", host_addr);
  379. X    /* NOTREACHED */
  380. X    }
  381. X
  382. X    /*
  383. X     * Open USER_FL and get an exclusive lock on it.
  384. X     *
  385. X     */
  386. X    if ((ufd=open(USER_FL,O_RDWR))<0) {
  387. X    fail("Can't open SLIP user file", NULL);
  388. X    /* NOTREACHED */
  389. X    }
  390. X#ifdef USG
  391. X    /*  This is a blocking lock; don't waste time...  */
  392. X    if (lockf(ufd,F_LOCK,0L)<0) {
  393. X    close(ufd);
  394. X    fail("Unable to lock SLIP user file", NULL);
  395. X    /* NOTREACHED */
  396. X    }
  397. X#else
  398. X    if (flock(ufd,LOCK_EX)<0) {
  399. X    close(ufd);
  400. X    fail("Unable to lock SLIP user file", NULL);
  401. X    /* NOTREACHED */
  402. X    }
  403. X#endif
  404. X
  405. X
  406. X    /*
  407. X     * Make sure that this internet address isn't already logged in,
  408. X     * and look for a free interface
  409. X     *
  410. X     */
  411. X    for (x=0;read(ufd,&urec_tmp,sizeof(urec_tmp))==sizeof(urec_tmp);x++)
  412. X    if (urec_tmp.sl_uid<0) {
  413. X        if (urec_i<0) {
  414. X        urec_i=x;
  415. X        bcopy(&urec_tmp,&urec,sizeof(urec));
  416. X        }
  417. X    }
  418. X    else if (urec_tmp.sl_haddr.s_addr==addr.s_addr) {
  419. X        unlock_fail("Host %s is already attached",inet_ntoa(addr));
  420. X    /* NOTREACHED */
  421. X    }
  422. X
  423. X
  424. X    /*
  425. X     * If there is a free interface then take it.
  426. X     *
  427. X     */
  428. X    if (urec_i<0) {
  429. X    unlock_fail("All lines are busy. Try again later.");
  430. X    /* NOTREACHED */
  431. X    }
  432. X
  433. X    h = gethostbyaddr(&addr, 4, AF_INET);
  434. X    printf("Attaching %s (%s)", h->h_name, inet_ntoa(addr));
  435. X    hh = gethostbyaddr(&urec.sl_saddr, 4, AF_INET);
  436. X#ifdef YELLOW_PAGES
  437. X    getdomainname(host_line, 79);
  438. X    printf(" to domain %s via %s (%s)\n",
  439. X        host_line, hh->h_name, inet_ntoa(urec.sl_saddr));
  440. X#else
  441. X    printf(" to network via %s (%s)\n",
  442. X        hh->h_name, inet_ntoa(urec.sl_saddr));
  443. X#endif
  444. X
  445. X    if (ioctl(0, TIOCGETP, &sgtty) < 0) {
  446. X    perror("ioctl TIOCGETP");
  447. X    unlock_close(1);
  448. X    }
  449. X    sgtty.sg_flags = RAW | ANYP;
  450. X    if (ioctl(0, TIOCSETP, &sgtty) < 0) {
  451. X    perror("ioctl TIOCSETP");
  452. X    unlock_close(1);
  453. X    }
  454. X#ifndef USG
  455. X    if (ioctl(0, TIOCSETD, &disc) < 0) {
  456. X    perror("ioctl TIOCSETD");
  457. X    unlock_close(1);
  458. X    }
  459. X#endif
  460. X
  461. X
  462. X    /*
  463. X     * Retreive the SL unit number.
  464. X     *
  465. X     */
  466. X#ifndef sun
  467. X#  ifdef USG
  468. X    unit = urec_i;
  469. X#  else
  470. X    if (ioctl(0,TIOCGETU,&unit)<0) {
  471. X    perror("ioctl TIOCGETU");
  472. X    unlock_close(1);
  473. X    }
  474. X#  endif
  475. X#else sun
  476. X    if (ioctl(0,TIOCGETD,&unit)<0) {
  477. X    perror("ioctl TIOCGETD");
  478. X    unlock_close(1);
  479. X    }
  480. X#endif sun
  481. X
  482. X    /*
  483. X     * Build and write USER_FL entry.
  484. X     *
  485. X     */
  486. X    urec.sl_unit = unit;
  487. X    urec.sl_haddr.s_addr = addr.s_addr;
  488. X    urec.sl_uid = uid;
  489. X    if (lseek(ufd,urec_i*sizeof(urec),L_SET)<0) {
  490. X    sprintf(string,"%s: can't seek\n",USER_FL);
  491. X    fprintf(stderr,string);
  492. X    if (log)
  493. X        write (fd_log, string, strlen(string));
  494. X    unlock_close(1);
  495. X    }
  496. X    signal(SIGHUP,bye);
  497. X    if (write(ufd,&urec,sizeof(urec))!=sizeof(urec)) {
  498. X    sprintf(string,"%s: can't write\n",USER_FL);
  499. X    fprintf(stderr,string);
  500. X    if (log)
  501. X        write (fd_log, string, strlen(string));
  502. X    clean_user(1);
  503. X    }
  504. X
  505. X    /*
  506. X     * Through with critical code. Unlock USER_FL.
  507. X     */
  508. X#ifdef USG
  509. X    lseek(ufd,0L,SEEK_SET);
  510. X    if (lockf(ufd,F_ULOCK,0L)<0) {
  511. X#else
  512. X    if (flock(ufd,LOCK_UN)<0) {
  513. X#endif
  514. X    sprintf(string,"%s: unlock failed\n", USER_FL);
  515. X    fprintf(stderr,string);
  516. X    if (log)
  517. X        write (fd_log, string, strlen(string));
  518. X    clean_user(1);
  519. X    }
  520. X
  521. X#ifndef sun
  522. X#  ifdef USG
  523. X    /*
  524. X     * slattach the line.
  525. X     */
  526. X    itoa (getpid(), pidstr);
  527. X    sprintf(sys_str,"%s - %s%u %s", SLATTACH, IF_NAME, urec.sl_unit, pidstr);
  528. X    sprintf(if_str,"%s%u", IF_NAME, urec.sl_unit);
  529. X
  530. X    if (log) {
  531. X        sprintf (string, "   %s: executing %s\n", name, sys_str);
  532. X        write (fd_log, string, strlen(string));
  533. X    }
  534. X
  535. X    if (fork ())
  536. X        /* wait for child to finish */
  537. X        wait (0);
  538. X    else {
  539. X        /* execl doesn't return unless there's an error */
  540. X        execl (SLATTACH, SLATTACH, "-", if_str, pidstr, 0);
  541. X        printf("execl (%s): failed\n", sys_str);
  542. X        clean_user(1);
  543. X    }
  544. X
  545. X#  endif
  546. X    /*
  547. X     * ifconfig the slip line up.
  548. X     */
  549. X    sprintf(sys_str,"%s %s%u inet %s ",
  550. X    IFCONFIG,IF_NAME,urec.sl_unit,inet_ntoa(urec.sl_saddr));
  551. X    strcat(sys_str,inet_ntoa(urec.sl_haddr));
  552. X    strcat(sys_str,IFARGS);
  553. X
  554. X    {
  555. X    FILE *xyzzy;
  556. X    xyzzy = fopen("/tmp/slip.log", "w");
  557. X    fputs(sys_str, xyzzy);
  558. X    fputc('\n', xyzzy);
  559. X    fclose(xyzzy);
  560. X    }
  561. X
  562. X    if (log) {
  563. X    sprintf (string, "   %s: executing %s\n", name, sys_str);
  564. X    write (fd_log, string, strlen(string));
  565. X    }
  566. X
  567. X    if (fork ())
  568. X        /* wait for child to finish */
  569. X        wait (0);
  570. X    else {
  571. X        /* execl doesn't return unless there's an error */
  572. X        strcpy(source,inet_ntoa(urec.sl_saddr));
  573. X        strcpy(remote,inet_ntoa(urec.sl_haddr));
  574. X        execl (IFCONFIG, IFCONFIG, if_str, "inet", source, remote, "up", 0);
  575. X        printf ("execl (%s): failed\n", sys_str);
  576. X        clean_user(1);
  577. X    }
  578. X#else sun
  579. X    /*
  580. X     * Now instead of calling ifconfig (which in the Sun 3
  581. X     * version doesn't grok all of the 4.3BSD weirdness) we
  582. X     * revert to the old SIOCIFDSTADDR/SIOCSIFADDR stuff
  583. X     */
  584. X    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  585. X    if(sockfd < 0) {
  586. X        perror("sunslip: socket");
  587. X        clean_user(1);
  588. X    }
  589. X    sprintf(ifr.ifr_name, "sl%d", unit);
  590. X    fprintf(stderr, "sl%d\n", unit);
  591. X    getaddr(&urec.sl_haddr, (struct sockaddr_in *)&ifr.ifr_dstaddr);
  592. X    if(ioctl(sockfd, SIOCSIFDSTADDR, (caddr_t)&ifr) < 0) {
  593. X        perror("ioctl SIOCSIFDSTADDR");
  594. X        clean_user(1);
  595. X    }
  596. X    getaddr(&urec.sl_saddr, (struct sockaddr_in *)&ifr.ifr_addr);
  597. X    if(ioctl(sockfd, SIOCSIFADDR, (caddr_t)&ifr) < 0) {
  598. X        perror("ioctl SIOCSIFADDR");
  599. X        clean_user(1);
  600. X    }
  601. X#endif sun
  602. X
  603. X    if (log) {
  604. X    sprintf (string, "   %s: waiting for hangup\n",name);
  605. X    write (fd_log, string, strlen(string));
  606. X    }
  607. X
  608. X    /*
  609. X     * Wait until carrier drops.
  610. X     * clean_usr() will be called.
  611. X     *
  612. X     */
  613. X
  614. X    for(;;) {
  615. X        printf("pause returns %d\n", pause());
  616. X    }
  617. X}
  618. X
  619. X
  620. Xunlock_close(status)
  621. Xint status;
  622. X{
  623. X    /*
  624. X     * Unlock and close USER_FL, and exit with "status".
  625. X     *
  626. X     */ 
  627. X
  628. X#ifdef USG
  629. X    lseek(ufd,0L,SEEK_SET);
  630. X    lockf(ufd,F_ULOCK,0L);
  631. X#else
  632. X    flock(ufd,LOCK_UN);
  633. X#endif
  634. X    close(ufd);
  635. X    exit(status);
  636. X}
  637. X
  638. X
  639. Xunlock_fail(s1, s2)
  640. Xchar *s1;
  641. Xchar *s2;
  642. X{
  643. X    /*
  644. X     * Unlock and close USER_FL, and fail
  645. X     *
  646. X     */ 
  647. X
  648. X#ifdef USG
  649. X    lseek(ufd,0L,SEEK_SET);
  650. X    lockf(ufd,F_ULOCK,0L);
  651. X#else
  652. X    flock(ufd,LOCK_UN);
  653. X#endif
  654. X    close(ufd);
  655. X    fail(s1, s2);
  656. X}
  657. X
  658. X
  659. Xfail(s1, s2)
  660. Xchar *s1;
  661. Xchar *s2;
  662. X{
  663. X    fputs("\nConnection failure: ", stderr);
  664. X    fprintf(stderr, s1, s2);
  665. X    fputs("\n\n", stderr);
  666. X
  667. X    if (log) {
  668. X        sprintf (string,"Connection failure: %s %s\n", s1, s2);
  669. X        write (fd_log, string, strlen(string));
  670. X    }
  671. X
  672. X    exit(1);
  673. X}
  674. X
  675. X
  676. Xclean_user(status)
  677. Xint status;
  678. X{
  679. X    /*
  680. X     * mark line free in USER_FL, unlock and close USER_FL, and
  681. X     * exit with "status".
  682. X     *
  683. X     */ 
  684. X
  685. X    urec.sl_uid = -1;
  686. X    if (lseek(ufd,urec_i*sizeof(urec),L_SET)<0 || write(ufd,&urec,sizeof(urec))!=sizeof(urec))
  687. X    status = -1;
  688. X    unlock_close(status);
  689. X}
  690. X
  691. X
  692. Xvoid bye(int sig)
  693. X{
  694. X    /*
  695. X     * Handle SIGHUP.
  696. X     * Mark line free in USER_FL and exit with status 0.
  697. X     *
  698. X     */
  699. X
  700. Xprintf("signal %d\n", sig);
  701. X
  702. X    if (log) {
  703. X        clock_val = time(0);
  704. X        sprintf (string, "   %s: caught signal %d, exiting ... %s", name, sig, ctime (&clock_val));
  705. X    write (fd_log, string, strlen(string));
  706. X    }
  707. X    clean_user(0);
  708. X}
  709. X
  710. X
  711. X#ifdef sun
  712. Xgetaddr(s, sin)
  713. Xstruct in_addr *s;
  714. Xstruct sockaddr_in *sin;
  715. X{
  716. X    sin->sin_family = AF_INET;
  717. X    sin->sin_addr = *s;
  718. X}
  719. X#endif sun
  720. X
  721. X
  722. X
  723. Xitoa (int n, char s[])
  724. X{
  725. X    int i, j;
  726. X    int c = 0;
  727. X
  728. X    do {
  729. X        s[c++] = n % 10 + '0';
  730. X    } while ((n/=10) > 0);
  731. X    s[c] = '\0';
  732. X
  733. X    for (i=0, j=c-1; i<j; i++, j--) {
  734. X        c = s[i];
  735. X        s[i] = s[j];
  736. X        s[j] = c;
  737. X    }
  738. X}
  739. END_OF_FILE
  740.   if test 11967 -ne `wc -c <'dialslip/slip.c'`; then
  741.     echo shar: \"'dialslip/slip.c'\" unpacked with wrong size!
  742.   fi
  743.   # end of 'dialslip/slip.c'
  744. fi
  745. if test -f 'dialslip/slip.h' -a "${1}" != "-c" ; then 
  746.   echo shar: Will not clobber existing file \"'dialslip/slip.h'\"
  747. else
  748.   echo shar: Extracting \"'dialslip/slip.h'\" \(763 characters\)
  749.   sed "s/^X//" >'dialslip/slip.h' <<'END_OF_FILE'
  750. X/*
  751. X * slip.h
  752. X *
  753. X * Definitions for the dialup slip system.
  754. X *
  755. X * Copyright 1987 by University of California, Davis
  756. X *
  757. X * Greg Whitehead 10-1-87
  758. X * Computing Services
  759. X * University of California, Davis
  760. X */
  761. X
  762. X#define USER_FL        "/etc/slip.user"
  763. X#define HOST_FL        "/etc/slip.hosts"
  764. X#define CONFIG_FL    "/etc/slip.config"
  765. X#define LOG_FL        "/var/slip/slip.log"
  766. X
  767. X#define SLATTACH    "/usr/sbin/slattach"
  768. X#define IFCONFIG    "/usr/sbin/ifconfig"
  769. X#define IFARGS        " up"
  770. X
  771. X#define DISC        SLIPDISC
  772. X#define IF_NAME        "sl"
  773. X
  774. X
  775. Xstruct sl_urec {
  776. X    int sl_uid;            /* uid of logged in host (-1 if free) */
  777. X    int sl_unit;        /* unit number for this login */
  778. X    struct in_addr sl_haddr;    /* internet address of logged in host */
  779. X    struct in_addr sl_saddr;    /* internet address of server side */
  780. X};
  781. END_OF_FILE
  782.   if test 763 -ne `wc -c <'dialslip/slip.h'`; then
  783.     echo shar: \"'dialslip/slip.h'\" unpacked with wrong size!
  784.   fi
  785.   # end of 'dialslip/slip.h'
  786. fi
  787. if test -f 'man/man1/dslipuser.1' -a "${1}" != "-c" ; then 
  788.   echo shar: Will not clobber existing file \"'man/man1/dslipuser.1'\"
  789. else
  790.   echo shar: Extracting \"'man/man1/dslipuser.1'\" \(3069 characters\)
  791.   sed "s/^X//" >'man/man1/dslipuser.1' <<'END_OF_FILE'
  792. X.TH slip 1 "TCP/IP"
  793. X.SH NAME
  794. Xslip, mkslipuser, dslipuser \- dialup SLIP utilities
  795. X.SH SYNOPSIS
  796. X.nf
  797. X\fB/usr/sbin/slip\fP
  798. X\fB/usr/sbin/mkslipuser\fP [ #_of_logins  host_address ]
  799. X\fB/usr/sbin/dslipuser\fP
  800. X.fi
  801. X.SH DESCRIPTION
  802. X.PP
  803. XThe \fBslip\fP program sets up a SLIP protocol over a dialup line.
  804. XThe SLIP protocol is obtained by logging into a host and executing
  805. Xthe \fBslip\fP program.
  806. XBecause \fBslip\fP must execute \fIslattach\fP and \fIifconfig\fP, it must run
  807. Xsetuid to root. 
  808. X.PP
  809. XSlip uses two files to control access; a host table (\fI/etc/slip.hosts\fP)
  810. Xthat maps login IDs to internet addresses, and a user file
  811. X(\fI/etc/slip.user\fP) that keeps track of users logged in over \fBslip\fP.
  812. XThe host table file must be created by hand and has the following format:
  813. X.PP
  814. X.nf
  815. X.CW
  816. X#  Lines starting with "#" are ignored.
  817. X#  The first field is the IP address to be assigned the remote host that
  818. X#  is logging in.  The second field is the login ID which is used to find
  819. X#  the appropriate IP address.
  820. X#
  821. X# <IP address> <login ID>
  822. X192.9.2.1       rkl
  823. X192.9.2.2       sjg
  824. X.fi
  825. X.fP
  826. X.PP
  827. XIf the file \fI/var/slip/slip.log\fP exists, \fBslip\fP will append log entries
  828. Xthat show when users invoked \fBslip\fP and when they disconnected.
  829. X.PP
  830. XThe \fBmkslipuser\fP program is used to create a blank user file.
  831. XYou may want to envoke \fBmkslipuser\fP from the \fI/etc/init.d/inetinit\fP
  832. Xrc file to insure a sane system after reboot.
  833. X\fBMkslipuser\fP uses information supplied either on the command line or from
  834. Xthe configuration file \fI/etc/slip.config\fP.
  835. XThe configuration file consists of a number of one-line entries; one for each
  836. Xsimultaneous login that is allowed.
  837. XThe number of simultaneous logins must, of course, be less than or equal to
  838. Xthe number of SLIP interfaces available.
  839. XEach entry contains an internet address (specified by hostname or dot notation
  840. Xformat) for the server side of a SLIP line.
  841. XThe entries may all be the same or unique depending on how you prefer to
  842. Xadminister your network.
  843. XThe configuration file may also contain comments which are lines starting with
  844. Xa "#".
  845. XHere is an example:
  846. X.PP
  847. X.nf
  848. X.CW
  849. X#  Lines that start with "#" are ignored.
  850. X#  This example allows 4 simultaneous SLIP logins all using the same server
  851. X#  side IP address.
  852. X#
  853. X#  <address of server side of point to point link>
  854. Xaslan.acme.com
  855. Xaslan.acme.com
  856. Xaslan.acme.com
  857. Xaslan.acme.com
  858. X.fi
  859. X.fP
  860. X.PP
  861. XIn the case where all of the server side addresses are the same, command line
  862. Xarguments may be used instead of a configuration file. The first argument
  863. Xis the number of simultaneous logins to allow, and the second argument is
  864. Xthe address of the server side of the point-point link.
  865. X.PP
  866. XThe \fBdslipuser\fP program displays the contents of the user file which
  867. Xidentifies who is logged in and what internet addresses they are using.
  868. X.SH SEE ALSO
  869. X.nf
  870. Xifconfig(1M), slattach(1M), slhangupd(1M), slip(7)
  871. X.fi
  872. X.SH FILES
  873. X.nf
  874. X/etc/slip.hosts
  875. X/etc/slip.user
  876. X/etc/slip.config
  877. X/var/slip/slip.log
  878. X.fi
  879. X.SH ORIGINAL AUTHOR
  880. X.nf
  881. XGreg Whitehead 10-02-87
  882. XComputing Services
  883. XUniversity of California, Davis
  884. X.fi
  885. END_OF_FILE
  886.   if test 3069 -ne `wc -c <'man/man1/dslipuser.1'`; then
  887.     echo shar: \"'man/man1/dslipuser.1'\" unpacked with wrong size!
  888.   fi
  889.   # end of 'man/man1/dslipuser.1'
  890. fi
  891. if test -f 'man/man1/mkslipuser.1' -a "${1}" != "-c" ; then 
  892.   echo shar: Will not clobber existing file \"'man/man1/mkslipuser.1'\"
  893. else
  894.   echo shar: Extracting \"'man/man1/mkslipuser.1'\" \(3069 characters\)
  895.   sed "s/^X//" >'man/man1/mkslipuser.1' <<'END_OF_FILE'
  896. X.TH slip 1 "TCP/IP"
  897. X.SH NAME
  898. Xslip, mkslipuser, dslipuser \- dialup SLIP utilities
  899. X.SH SYNOPSIS
  900. X.nf
  901. X\fB/usr/sbin/slip\fP
  902. X\fB/usr/sbin/mkslipuser\fP [ #_of_logins  host_address ]
  903. X\fB/usr/sbin/dslipuser\fP
  904. X.fi
  905. X.SH DESCRIPTION
  906. X.PP
  907. XThe \fBslip\fP program sets up a SLIP protocol over a dialup line.
  908. XThe SLIP protocol is obtained by logging into a host and executing
  909. Xthe \fBslip\fP program.
  910. XBecause \fBslip\fP must execute \fIslattach\fP and \fIifconfig\fP, it must run
  911. Xsetuid to root. 
  912. X.PP
  913. XSlip uses two files to control access; a host table (\fI/etc/slip.hosts\fP)
  914. Xthat maps login IDs to internet addresses, and a user file
  915. X(\fI/etc/slip.user\fP) that keeps track of users logged in over \fBslip\fP.
  916. XThe host table file must be created by hand and has the following format:
  917. X.PP
  918. X.nf
  919. X.CW
  920. X#  Lines starting with "#" are ignored.
  921. X#  The first field is the IP address to be assigned the remote host that
  922. X#  is logging in.  The second field is the login ID which is used to find
  923. X#  the appropriate IP address.
  924. X#
  925. X# <IP address> <login ID>
  926. X192.9.2.1       rkl
  927. X192.9.2.2       sjg
  928. X.fi
  929. X.fP
  930. X.PP
  931. XIf the file \fI/var/slip/slip.log\fP exists, \fBslip\fP will append log entries
  932. Xthat show when users invoked \fBslip\fP and when they disconnected.
  933. X.PP
  934. XThe \fBmkslipuser\fP program is used to create a blank user file.
  935. XYou may want to envoke \fBmkslipuser\fP from the \fI/etc/init.d/inetinit\fP
  936. Xrc file to insure a sane system after reboot.
  937. X\fBMkslipuser\fP uses information supplied either on the command line or from
  938. Xthe configuration file \fI/etc/slip.config\fP.
  939. XThe configuration file consists of a number of one-line entries; one for each
  940. Xsimultaneous login that is allowed.
  941. XThe number of simultaneous logins must, of course, be less than or equal to
  942. Xthe number of SLIP interfaces available.
  943. XEach entry contains an internet address (specified by hostname or dot notation
  944. Xformat) for the server side of a SLIP line.
  945. XThe entries may all be the same or unique depending on how you prefer to
  946. Xadminister your network.
  947. XThe configuration file may also contain comments which are lines starting with
  948. Xa "#".
  949. XHere is an example:
  950. X.PP
  951. X.nf
  952. X.CW
  953. X#  Lines that start with "#" are ignored.
  954. X#  This example allows 4 simultaneous SLIP logins all using the same server
  955. X#  side IP address.
  956. X#
  957. X#  <address of server side of point to point link>
  958. Xaslan.acme.com
  959. Xaslan.acme.com
  960. Xaslan.acme.com
  961. Xaslan.acme.com
  962. X.fi
  963. X.fP
  964. X.PP
  965. XIn the case where all of the server side addresses are the same, command line
  966. Xarguments may be used instead of a configuration file. The first argument
  967. Xis the number of simultaneous logins to allow, and the second argument is
  968. Xthe address of the server side of the point-point link.
  969. X.PP
  970. XThe \fBdslipuser\fP program displays the contents of the user file which
  971. Xidentifies who is logged in and what internet addresses they are using.
  972. X.SH SEE ALSO
  973. X.nf
  974. Xifconfig(1M), slattach(1M), slhangupd(1M), slip(7)
  975. X.fi
  976. X.SH FILES
  977. X.nf
  978. X/etc/slip.hosts
  979. X/etc/slip.user
  980. X/etc/slip.config
  981. X/var/slip/slip.log
  982. X.fi
  983. X.SH ORIGINAL AUTHOR
  984. X.nf
  985. XGreg Whitehead 10-02-87
  986. XComputing Services
  987. XUniversity of California, Davis
  988. X.fi
  989. END_OF_FILE
  990.   if test 3069 -ne `wc -c <'man/man1/mkslipuser.1'`; then
  991.     echo shar: \"'man/man1/mkslipuser.1'\" unpacked with wrong size!
  992.   fi
  993.   # end of 'man/man1/mkslipuser.1'
  994. fi
  995. if test -f 'man/man1/slattach.1' -a "${1}" != "-c" ; then 
  996.   echo shar: Will not clobber existing file \"'man/man1/slattach.1'\"
  997. else
  998.   echo shar: Extracting \"'man/man1/slattach.1'\" \(3089 characters\)
  999.   sed "s/^X//" >'man/man1/slattach.1' <<'END_OF_FILE'
  1000. X.\"
  1001. X.\"             Copyright 1991, Intel Corporation
  1002. X.\"                   All rights reserved.
  1003. X.\"
  1004. X.\" Permission to use, copy, modify, and distribute this software and
  1005. X.\" its documentation for any purpose and without fee is hereby granted,
  1006. X.\" provided that the above copyright notice appear in all copies and
  1007. X.\" that both the copyright notice appear in all copies and that both
  1008. X.\" the copyright notice and this permission notice appear in
  1009. X.\" supporting documentation, and that the name of Intel Corporation
  1010. X.\" not be used in advertising or publicity pertaining to distribution
  1011. X.\" of the software without specific, written prior permission.
  1012. X.\" 
  1013. X.\" COMPANY AND/OR INTEL DISCLAIM ALL WARRANTIES WITH REGARD TO
  1014. X.\" THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  1015. X.\" MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
  1016. X.\" EVENT SHALL COMPANY NOR INTEL BE LIABLE FOR ANY SPECIAL,
  1017. X.\" INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  1018. X.\" RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1019. X.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
  1020. X.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  1021. X.\" OF THIS SOFTWARE.
  1022. X.\" 
  1023. X.TH slattach 1M "TCP/IP"
  1024. X.SH NAME
  1025. Xslattach, sldetach \- assigns and removes serial lines as a SLIP interface
  1026. X.SH SYNOPSIS
  1027. X.nf
  1028. X\fB/usr/sbin/slattach\fP [\fB-i\fP] node_name interface_name
  1029. X\fB/usr/sbin/slattach -d\fP [\fB-i\fP] device_name interface_name [ baudrate ]
  1030. X\fB/usr/sbin/slattach -\fP interface_name [ process_id ]
  1031. X
  1032. X\fB/usr/sbin/sldetach\fP interface_name
  1033. X.fi
  1034. X.SH DESCRIPTION
  1035. X.PP
  1036. X\fBSlattach\fP is used to assign a serial line as a network interface
  1037. Xusing the \fISLIP\fP (Serial Link Internet Protocol) driver.
  1038. X.PP
  1039. XWhen invoked with \fInode_name\fP and \fIinterface_name\fP, \fBslattach\fP
  1040. Xuses BNU (Basic Networking Utilities) to establish an outgoing serial line
  1041. Xconnection.
  1042. XRefer to the \fIAdvanced System Administration Guide\fP for complete
  1043. Xinformation on set up and administration of BNU.
  1044. X.PP
  1045. XThe \fB-i\fP option causes \fBslattach\fP to ignore SIGHUP.
  1046. XBy default \fBslattach\fP exits gracefully whenever a SIGHUP is caught and
  1047. Xprocessed by the \fIslhangupd\fP daemon.
  1048. X.PP
  1049. XThe \fB-d\fP option causes \fBslattach\fP to directly open the specified
  1050. X\fIdevice_name\fP without the use of BNU.
  1051. XIn this case the \fIbaudrate\fP parameter is used to set the speed of the
  1052. Xconnection.
  1053. XThe default baudrate is 9600.
  1054. X.PP
  1055. XThe \fB-\fP option causes stdin to be used as the device to be attached to the
  1056. X\fISLIP\fP driver.
  1057. XThis option is used to convert a remote login line to a SLIP connection.
  1058. XIn this case, SIGHUP can not be ignored.
  1059. XThe optional argument \fIprocess_id\fP, if specified, causes \fBslattach\fP to
  1060. Xsend a SIGHUP to the specified process ID when it receives the SIGHUP signal.
  1061. X.PP
  1062. X\fBSldetach\fP is used to decommission a serial line that was used for a SLIP
  1063. Xconnection.
  1064. X.SH EXAMPLES
  1065. X.nf
  1066. Xslattach venus sl0
  1067. Xslattach -d -i /dev/tty00 sl0 19200
  1068. X
  1069. Xsldetach sl0
  1070. X.fi
  1071. X.SH SEE ALSO
  1072. X.nf
  1073. Xslhangupd(1M), slip(1), asy(7), ip(7), slip(7)
  1074. X\fIAdvanced System Administration Guide\fP.
  1075. X.fi
  1076. X.SH AUTHOR
  1077. XSudji Husodo
  1078. END_OF_FILE
  1079.   if test 3089 -ne `wc -c <'man/man1/slattach.1'`; then
  1080.     echo shar: \"'man/man1/slattach.1'\" unpacked with wrong size!
  1081.   fi
  1082.   # end of 'man/man1/slattach.1'
  1083. fi
  1084. if test -f 'man/man1/sldetach.1' -a "${1}" != "-c" ; then 
  1085.   echo shar: Will not clobber existing file \"'man/man1/sldetach.1'\"
  1086. else
  1087.   echo shar: Extracting \"'man/man1/sldetach.1'\" \(3089 characters\)
  1088.   sed "s/^X//" >'man/man1/sldetach.1' <<'END_OF_FILE'
  1089. X.\"
  1090. X.\"             Copyright 1991, Intel Corporation
  1091. X.\"                   All rights reserved.
  1092. X.\"
  1093. X.\" Permission to use, copy, modify, and distribute this software and
  1094. X.\" its documentation for any purpose and without fee is hereby granted,
  1095. X.\" provided that the above copyright notice appear in all copies and
  1096. X.\" that both the copyright notice appear in all copies and that both
  1097. X.\" the copyright notice and this permission notice appear in
  1098. X.\" supporting documentation, and that the name of Intel Corporation
  1099. X.\" not be used in advertising or publicity pertaining to distribution
  1100. X.\" of the software without specific, written prior permission.
  1101. X.\" 
  1102. X.\" COMPANY AND/OR INTEL DISCLAIM ALL WARRANTIES WITH REGARD TO
  1103. X.\" THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  1104. X.\" MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
  1105. X.\" EVENT SHALL COMPANY NOR INTEL BE LIABLE FOR ANY SPECIAL,
  1106. X.\" INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  1107. X.\" RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1108. X.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
  1109. X.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  1110. X.\" OF THIS SOFTWARE.
  1111. X.\" 
  1112. X.TH slattach 1M "TCP/IP"
  1113. X.SH NAME
  1114. Xslattach, sldetach \- assigns and removes serial lines as a SLIP interface
  1115. X.SH SYNOPSIS
  1116. X.nf
  1117. X\fB/usr/sbin/slattach\fP [\fB-i\fP] node_name interface_name
  1118. X\fB/usr/sbin/slattach -d\fP [\fB-i\fP] device_name interface_name [ baudrate ]
  1119. X\fB/usr/sbin/slattach -\fP interface_name [ process_id ]
  1120. X
  1121. X\fB/usr/sbin/sldetach\fP interface_name
  1122. X.fi
  1123. X.SH DESCRIPTION
  1124. X.PP
  1125. X\fBSlattach\fP is used to assign a serial line as a network interface
  1126. Xusing the \fISLIP\fP (Serial Link Internet Protocol) driver.
  1127. X.PP
  1128. XWhen invoked with \fInode_name\fP and \fIinterface_name\fP, \fBslattach\fP
  1129. Xuses BNU (Basic Networking Utilities) to establish an outgoing serial line
  1130. Xconnection.
  1131. XRefer to the \fIAdvanced System Administration Guide\fP for complete
  1132. Xinformation on set up and administration of BNU.
  1133. X.PP
  1134. XThe \fB-i\fP option causes \fBslattach\fP to ignore SIGHUP.
  1135. XBy default \fBslattach\fP exits gracefully whenever a SIGHUP is caught and
  1136. Xprocessed by the \fIslhangupd\fP daemon.
  1137. X.PP
  1138. XThe \fB-d\fP option causes \fBslattach\fP to directly open the specified
  1139. X\fIdevice_name\fP without the use of BNU.
  1140. XIn this case the \fIbaudrate\fP parameter is used to set the speed of the
  1141. Xconnection.
  1142. XThe default baudrate is 9600.
  1143. X.PP
  1144. XThe \fB-\fP option causes stdin to be used as the device to be attached to the
  1145. X\fISLIP\fP driver.
  1146. XThis option is used to convert a remote login line to a SLIP connection.
  1147. XIn this case, SIGHUP can not be ignored.
  1148. XThe optional argument \fIprocess_id\fP, if specified, causes \fBslattach\fP to
  1149. Xsend a SIGHUP to the specified process ID when it receives the SIGHUP signal.
  1150. X.PP
  1151. X\fBSldetach\fP is used to decommission a serial line that was used for a SLIP
  1152. Xconnection.
  1153. X.SH EXAMPLES
  1154. X.nf
  1155. Xslattach venus sl0
  1156. Xslattach -d -i /dev/tty00 sl0 19200
  1157. X
  1158. Xsldetach sl0
  1159. X.fi
  1160. X.SH SEE ALSO
  1161. X.nf
  1162. Xslhangupd(1M), slip(1), asy(7), ip(7), slip(7)
  1163. X\fIAdvanced System Administration Guide\fP.
  1164. X.fi
  1165. X.SH AUTHOR
  1166. XSudji Husodo
  1167. END_OF_FILE
  1168.   if test 3089 -ne `wc -c <'man/man1/sldetach.1'`; then
  1169.     echo shar: \"'man/man1/sldetach.1'\" unpacked with wrong size!
  1170.   fi
  1171.   # end of 'man/man1/sldetach.1'
  1172. fi
  1173. if test -f 'man/man1/slip.1' -a "${1}" != "-c" ; then 
  1174.   echo shar: Will not clobber existing file \"'man/man1/slip.1'\"
  1175. else
  1176.   echo shar: Extracting \"'man/man1/slip.1'\" \(3069 characters\)
  1177.   sed "s/^X//" >'man/man1/slip.1' <<'END_OF_FILE'
  1178. X.TH slip 1 "TCP/IP"
  1179. X.SH NAME
  1180. Xslip, mkslipuser, dslipuser \- dialup SLIP utilities
  1181. X.SH SYNOPSIS
  1182. X.nf
  1183. X\fB/usr/sbin/slip\fP
  1184. X\fB/usr/sbin/mkslipuser\fP [ #_of_logins  host_address ]
  1185. X\fB/usr/sbin/dslipuser\fP
  1186. X.fi
  1187. X.SH DESCRIPTION
  1188. X.PP
  1189. XThe \fBslip\fP program sets up a SLIP protocol over a dialup line.
  1190. XThe SLIP protocol is obtained by logging into a host and executing
  1191. Xthe \fBslip\fP program.
  1192. XBecause \fBslip\fP must execute \fIslattach\fP and \fIifconfig\fP, it must run
  1193. Xsetuid to root. 
  1194. X.PP
  1195. XSlip uses two files to control access; a host table (\fI/etc/slip.hosts\fP)
  1196. Xthat maps login IDs to internet addresses, and a user file
  1197. X(\fI/etc/slip.user\fP) that keeps track of users logged in over \fBslip\fP.
  1198. XThe host table file must be created by hand and has the following format:
  1199. X.PP
  1200. X.nf
  1201. X.CW
  1202. X#  Lines starting with "#" are ignored.
  1203. X#  The first field is the IP address to be assigned the remote host that
  1204. X#  is logging in.  The second field is the login ID which is used to find
  1205. X#  the appropriate IP address.
  1206. X#
  1207. X# <IP address> <login ID>
  1208. X192.9.2.1       rkl
  1209. X192.9.2.2       sjg
  1210. X.fi
  1211. X.fP
  1212. X.PP
  1213. XIf the file \fI/var/slip/slip.log\fP exists, \fBslip\fP will append log entries
  1214. Xthat show when users invoked \fBslip\fP and when they disconnected.
  1215. X.PP
  1216. XThe \fBmkslipuser\fP program is used to create a blank user file.
  1217. XYou may want to envoke \fBmkslipuser\fP from the \fI/etc/init.d/inetinit\fP
  1218. Xrc file to insure a sane system after reboot.
  1219. X\fBMkslipuser\fP uses information supplied either on the command line or from
  1220. Xthe configuration file \fI/etc/slip.config\fP.
  1221. XThe configuration file consists of a number of one-line entries; one for each
  1222. Xsimultaneous login that is allowed.
  1223. XThe number of simultaneous logins must, of course, be less than or equal to
  1224. Xthe number of SLIP interfaces available.
  1225. XEach entry contains an internet address (specified by hostname or dot notation
  1226. Xformat) for the server side of a SLIP line.
  1227. XThe entries may all be the same or unique depending on how you prefer to
  1228. Xadminister your network.
  1229. XThe configuration file may also contain comments which are lines starting with
  1230. Xa "#".
  1231. XHere is an example:
  1232. X.PP
  1233. X.nf
  1234. X.CW
  1235. X#  Lines that start with "#" are ignored.
  1236. X#  This example allows 4 simultaneous SLIP logins all using the same server
  1237. X#  side IP address.
  1238. X#
  1239. X#  <address of server side of point to point link>
  1240. Xaslan.acme.com
  1241. Xaslan.acme.com
  1242. Xaslan.acme.com
  1243. Xaslan.acme.com
  1244. X.fi
  1245. X.fP
  1246. X.PP
  1247. XIn the case where all of the server side addresses are the same, command line
  1248. Xarguments may be used instead of a configuration file. The first argument
  1249. Xis the number of simultaneous logins to allow, and the second argument is
  1250. Xthe address of the server side of the point-point link.
  1251. X.PP
  1252. XThe \fBdslipuser\fP program displays the contents of the user file which
  1253. Xidentifies who is logged in and what internet addresses they are using.
  1254. X.SH SEE ALSO
  1255. X.nf
  1256. Xifconfig(1M), slattach(1M), slhangupd(1M), slip(7)
  1257. X.fi
  1258. X.SH FILES
  1259. X.nf
  1260. X/etc/slip.hosts
  1261. X/etc/slip.user
  1262. X/etc/slip.config
  1263. X/var/slip/slip.log
  1264. X.fi
  1265. X.SH ORIGINAL AUTHOR
  1266. X.nf
  1267. XGreg Whitehead 10-02-87
  1268. XComputing Services
  1269. XUniversity of California, Davis
  1270. X.fi
  1271. END_OF_FILE
  1272.   if test 3069 -ne `wc -c <'man/man1/slip.1'`; then
  1273.     echo shar: \"'man/man1/slip.1'\" unpacked with wrong size!
  1274.   fi
  1275.   # end of 'man/man1/slip.1'
  1276. fi
  1277. if test -f 'man/man7/slip.7' -a "${1}" != "-c" ; then 
  1278.   echo shar: Will not clobber existing file \"'man/man7/slip.7'\"
  1279. else
  1280.   echo shar: Extracting \"'man/man7/slip.7'\" \(3431 characters\)
  1281.   sed "s/^X//" >'man/man7/slip.7' <<'END_OF_FILE'
  1282. X.\"
  1283. X.\"             Copyright 1991, Intel Corporation
  1284. X.\"                   All rights reserved.
  1285. X.\"
  1286. X.\" Permission to use, copy, modify, and distribute this software and
  1287. X.\" its documentation for any purpose and without fee is hereby granted,
  1288. X.\" provided that the above copyright notice appear in all copies and
  1289. X.\" that both the copyright notice appear in all copies and that both
  1290. X.\" the copyright notice and this permission notice appear in
  1291. X.\" supporting documentation, and that the name of Intel Corporation
  1292. X.\" not be used in advertising or publicity pertaining to distribution
  1293. X.\" of the software without specific, written prior permission.
  1294. X.\" 
  1295. X.\" COMPANY AND/OR INTEL DISCLAIM ALL WARRANTIES WITH REGARD TO
  1296. X.\" THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  1297. X.\" MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
  1298. X.\" EVENT SHALL COMPANY NOR INTEL BE LIABLE FOR ANY SPECIAL,
  1299. X.\" INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  1300. X.\" RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1301. X.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1302. X.\" ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  1303. X.\" OF THIS SOFTWARE.
  1304. X.\" 
  1305. X.TH SLIP 7  "Network Drivers"
  1306. X.SH NAME
  1307. XSLIP \- Serial Link Internet Protocol
  1308. X.SH SYNOPSIS
  1309. X.nf
  1310. X.ft B
  1311. X#include <sys/types.h>
  1312. X#include <sys/socket.h>
  1313. X#include <sys/stream.h>
  1314. X#include <net/if.h>
  1315. X#include <sys/slip.h>
  1316. X
  1317. Xs = open ("/dev/slip", O_RDWR);
  1318. X.ft R
  1319. X.fi
  1320. X.SH DESCRIPTION
  1321. X.PP
  1322. X\fBSLIP\fP is a multiplexing STREAMS driver that implements the
  1323. Xpacket framing protocol specified in RFC1055.
  1324. X.PP
  1325. XThe \fBSLIP\fP driver is usually linked below the \fIip\fP driver and above the
  1326. X\fIasy\fP (serial) driver.
  1327. XThe \fIslattach\fP command constructs the required \fIip\fP to \fBSLIP\fP to
  1328. X\fIasy\fP STREAMS stack so that serial lines can be used as a network interfaces.
  1329. X.PP
  1330. XMultiple serial devices can be linked below the \fBSLIP\fP driver.
  1331. XThe maximum number of serial devices the \fBSLIP\fP driver can have is
  1332. Xcontrolled by the configuration parameter \fBSLIP_NUM\fP in the file
  1333. X\fI/etc/conf/pack.d/slip/space.c\fP.
  1334. XNote that the slip hangup daemon (\fIslhangupd\fP), if used, takes one entry
  1335. Xof \fBSLIP's\fP driver data structure, and should be considered before setting
  1336. X\fBSLIP_NUM\fP.
  1337. X.PP
  1338. X\fII_STR ioctl commands:\fP
  1339. X.PP
  1340. XThe I_STR ioctl commands are provided to add the capability of passing
  1341. XM_HANGUP signal received by the \fBSLIP\fP driver to the process that builds the
  1342. XSLIP protocol stack.
  1343. XThis is necessary because the TCP/IP protocol stack may disregard M_HANGUP
  1344. Xmessages.
  1345. X.PP
  1346. XThe I_STR ioctl commands codes below are defined in <\fIsys/slip.h\fP>.
  1347. X.TP 20
  1348. X.B REG_SLHUP
  1349. XA process that sends this ioctl will be notified of M_HANGUP messages sent
  1350. Xby any of the lower ttys associated with the \fBSLIP\fP driver.
  1351. XThe notification is done by sending an M_DATA messages containing the process
  1352. XID of the program that linked the effected tty to the \fBSLIP\fP driver.
  1353. XThis ioctl is generally sent by SLIP hangup daemon \fIslhangupd\fP.
  1354. XOnly one process can be registered to receive M_HANGUP notifications at any
  1355. Xone time.
  1356. X.TP 20
  1357. X.B UNREG_SLHUP
  1358. XThis ioctl unregisters a process from receiving M_HANGUP notifications.
  1359. XSince only one process can be registered to receive M_HANGUP notifications,
  1360. Xit is important that a process unregister before it exits.
  1361. X.SH SEE ALSO
  1362. Xslattach(1M), sldetach(1M), slhangupd(1M), asy(7), ip(7)
  1363. X.SH FILES
  1364. X/dev/slip
  1365. X.SH AUTHOR
  1366. XSudji Husodo
  1367. END_OF_FILE
  1368.   if test 3431 -ne `wc -c <'man/man7/slip.7'`; then
  1369.     echo shar: \"'man/man7/slip.7'\" unpacked with wrong size!
  1370.   fi
  1371.   # end of 'man/man7/slip.7'
  1372. fi
  1373. if test -f 'utils/slattach.c' -a "${1}" != "-c" ; then 
  1374.   echo shar: Will not clobber existing file \"'utils/slattach.c'\"
  1375. else
  1376.   echo shar: Extracting \"'utils/slattach.c'\" \(9007 characters\)
  1377.   sed "s/^X//" >'utils/slattach.c' <<'END_OF_FILE'
  1378. X/*
  1379. X *            Copyright 1991, Intel Corporation
  1380. X *                  All rights reserved.
  1381. X *
  1382. X * Permission to use, copy, modify, and distribute this software and
  1383. X * its documentation for any purpose and without fee is hereby granted,
  1384. X * provided that the above copyright notice appear in all copies and
  1385. X * that both the copyright notice appear in all copies and that both
  1386. X * the copyright notice and this permission notice appear in
  1387. X * supporting documentation, and that the name of Intel Corporation
  1388. X * not be used in advertising or publicity pertaining to distribution
  1389. X * of the software without specific, written prior premission.
  1390. X * 
  1391. X * COMPANY AND/OR INTEL DISCLAIM ALL WARRANTIES WITH REGARD TO
  1392. X * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  1393. X * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
  1394. X * EVENT SHALL COMPANY NOR INTEL BE LIABLE FOR ANY SPECIAL,
  1395. X * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  1396. X * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1397. X * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1398. X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  1399. X * OF THIS SOFTWARE.
  1400. X */
  1401. X
  1402. X/*
  1403. X * Name:
  1404. X *        slattach
  1405. X *
  1406. X * Synopsis:
  1407. X *        slattach [-i] nodename interface_name
  1408. X *        slattach -d [-i] devname interface_name [ baudrate ]
  1409. X *        slattach -  interface_name process_id
  1410. X *
  1411. X * Description:
  1412. X *        Slattach is used to assign a serial line to a network interface
  1413. X *        using the Internet Protocol.
  1414. X *
  1415. X *        Slattach defaults to use BNU (Basic Networking Utilities) to
  1416. X *        establish an outgoing serial line connection. Look at Advanced
  1417. X *        System Administration Section 7-15. The -d option causes slattach
  1418. X *        to directly open the specified device name, without using BNU, to be
  1419. X *        linked to the slip driver. In this case the baudrate parameter is
  1420. X *        used to set the speed of the connection; the default speed is 9600.
  1421. X *
  1422. X *        The - options specifies that stdin is the device to be attached to
  1423. X *        the slip driver.
  1424. X *
  1425. X *        If the slip hangup daemon (slhangupd) is run, slattach by default
  1426. X *        is set to receive hangup signal (SIGHUP) sent by the slip driver
  1427. X *        through slhangupd. The -i option ignores any hangup signal.
  1428. X *
  1429. X * Example:
  1430. X *        slattach [-i] venus sl0
  1431. X *        slattach -d [-i] /dev/tty00 sl0 19200
  1432. X *        slattach - sl0
  1433. X *
  1434. X * Author:
  1435. X *        Sudji Husodo    1/31/91
  1436. X */
  1437. X
  1438. X#include <stdio.h>
  1439. X#include <stdlib.h>
  1440. X#include <fcntl.h>
  1441. X#include <stropts.h>
  1442. X#include <termio.h>
  1443. X#include <signal.h>
  1444. X
  1445. X#include <sys/types.h>
  1446. X#include <sys/socket.h>
  1447. X#include <sys/sockio.h>
  1448. X#include <sys/stream.h>
  1449. X#include <net/if.h>
  1450. X#include <sys/slip.h>
  1451. X/*
  1452. X#include <dial.h>
  1453. X*/
  1454. X
  1455. X/*
  1456. X * Unix V.4.0.3 doesn't include dial.h in /usr/include directory,
  1457. X * so define typedef CALL.
  1458. X */
  1459. X
  1460. Xtypedef struct {
  1461. X    struct    termio *attr;    /* ptr to termio attribute struct */
  1462. X    int        baud;            /* unused */
  1463. X    int        speed;            /* less than 0 for any speed */
  1464. X    char    *line;            /* device name for out-going line */
  1465. X    char    *telno;            /* ptr to tel-no/system name string */
  1466. X    int        modem;            /* unused */
  1467. X    char    *device;        /* unused */
  1468. X    int        dev_len;        /* unused */
  1469. X} CALL;
  1470. X
  1471. Xchar    *program;
  1472. Xchar    *ipname = "/dev/ip";
  1473. Xchar    *slipname = "/dev/slip";
  1474. Xchar    devname[16], ifname[16];
  1475. Xint        fd_link, fd_ip, fd_slip;
  1476. Xunsigned char fd_dev;
  1477. Xint        ppid = 0;
  1478. X
  1479. XCALL    ds;
  1480. Xstruct    termio    tio;
  1481. Xvoid    slsignal (int);
  1482. X
  1483. Xmain (int argc, char *argv[])
  1484. X{
  1485. X    int        iflag = 0;                    /* ignore hangup signal flag */
  1486. X    int        dflag = 0;
  1487. X    extern    char *optarg;
  1488. X    extern    int  optind;
  1489. X    int        ac;
  1490. X    char    **av;
  1491. X
  1492. X    int        speed;
  1493. X    pid_t    pid;
  1494. X    struct    strioctl iocb;
  1495. X    struct    ifreq    ifr;
  1496. X
  1497. X#ifdef DEBUG
  1498. X    extern int Debug;
  1499. X    Debug = 9;
  1500. X#endif
  1501. X
  1502. X    program = argv[0];
  1503. X
  1504. X    /*
  1505. X     * If first argument is '-' only, we're using stdin as the device
  1506. X     */
  1507. X
  1508. X     if (argv[1][0] == '-' && argv[1][1] == '\0') {
  1509. X        if (strlen(argv[2]) < 1)                /* check for usage */
  1510. X            usage ();
  1511. X    }
  1512. X
  1513. X    /*
  1514. X     * otherwise check for options using getopt
  1515. X     */
  1516. X
  1517. X    else {
  1518. X        while ((speed = getopt (argc, argv, "id")) != EOF)
  1519. X            switch (speed) {
  1520. X                case 'i':    iflag++;    break;
  1521. X                case 'd':    dflag++;    break;
  1522. X                case '?':    usage ();
  1523. X            }
  1524. X
  1525. X        ac = argc - optind + 1;                    /* set ac, argument count */
  1526. X        av = &argv [optind];                    /* and av, arguments */
  1527. X
  1528. X        if (ac < 3)                                /* check legal usage */
  1529. X            usage ();
  1530. X    }
  1531. X
  1532. X    /*
  1533. X     * daemonize the process if it is not a DEBUG version
  1534. X     */
  1535. X
  1536. X#ifndef DEBUG
  1537. X    setpgrp ();
  1538. X
  1539. X    switch (fork()) {
  1540. X    case 0:
  1541. X        break;
  1542. X    case -1:
  1543. X        perror ("fork failed");
  1544. X        exit (2);
  1545. X    default:
  1546. X         if (argv[1][0] == '-' && argv[1][1] == '\0')
  1547. X            sleep (3);
  1548. X        else
  1549. X            wait (0);
  1550. X        exit (0);
  1551. X    }
  1552. X#endif
  1553. X
  1554. X    /*
  1555. X     * If first argument is '-' only, we're using stdin as the device
  1556. X      */
  1557. X
  1558. X     if (argv[1][0] == '-' && argv[1][1] == '\0') {
  1559. X        fd_dev = fileno (stdin);                /* device is stdin */
  1560. X         strcpy (ifname, argv[2]);                /* remember ifname */
  1561. X         ppid = atoi (argv[3]);
  1562. X
  1563. X        ioctl (fd_dev, I_POP, "ldterm");        /* ignore ioctl error */
  1564. X        ioctl (fd_dev, I_POP, "ttcompat");
  1565. X
  1566. X        if (ioctl (fd_dev, TCGETA, &tio) < 0)
  1567. X            slerror ("%s: ioctl TCGETA failed", argv[0]);
  1568. X
  1569. X        tio.c_cflag |= CS8 | CREAD;
  1570. X
  1571. X        if (ioctl (fd_dev, TCSETA, &tio) < 0)
  1572. X            slerror ("%s: ioctl TCSANOW failed", argv[0]);
  1573. X    }
  1574. X
  1575. X    /*
  1576. X     * We are using BNU (default) through dial(3C)
  1577. X     */
  1578. X
  1579. X    else if (!dflag) {
  1580. X        strcpy (devname, av[0]);                /* get nodename and ifname */
  1581. X        strcpy (ifname, av[1]);
  1582. X
  1583. X        /*
  1584. X         * get device file descriptor through BNU's dial call.
  1585. X         * get and set device attributes. pop ldterm and ttcompat.
  1586. X         */
  1587. X
  1588. X        ds.attr  = 0;
  1589. X        ds.speed = -1;
  1590. X        ds.line  = "";
  1591. X        ds.telno = devname;
  1592. X
  1593. X        if ((fd_dev = dial (ds)) < 0)
  1594. X            slerror ("%s: dial failed", argv[0]);
  1595. X
  1596. X        if (ioctl (fd_dev, TCGETA, &tio) < 0)
  1597. X            slerror ("%s: ioctl TCGETA failed", argv[0]);
  1598. X
  1599. X        tio.c_iflag = BRKINT | IGNPAR;
  1600. X        tio.c_cflag = (tio.c_cflag & 0x0f) | CS8 | CREAD;
  1601. X
  1602. X        if (ioctl (fd_dev, TCSETA, &tio) < 0)
  1603. X            slerror ("%s: ioctl TCSANOW failed", argv[0]);
  1604. X
  1605. X        ioctl (fd_dev, I_POP, "ldterm");        /* ignore ioctl error */
  1606. X        ioctl (fd_dev, I_POP, "ttcompat");
  1607. X    }
  1608. X
  1609. X    /*
  1610. X     * we are not using BNU. The next argument is the serial device name.
  1611. X     */
  1612. X
  1613. X    else {
  1614. X        if (*av[0] == '/') {                    /* if device path is absolute */
  1615. X            strcpy (devname, av[0]);            /* copy device as it is */
  1616. X        }
  1617. X        else {                                    /* device path is relative */
  1618. X            strcpy (devname, "/dev/");            /* add "/dev/" to devname */
  1619. X            strcat (devname, av[0]);
  1620. X        }
  1621. X        strcpy (ifname, av[1]);                    /* the next two argument is */
  1622. X        speed = atoi (av[2]);                    /* ifname and baud (optional) */
  1623. X
  1624. X        /*
  1625. X         * open device directly. pop ldterm and ttcompat.
  1626. X         * get and set device attributes.
  1627. X         */
  1628. X
  1629. X        if ((fd_dev = open (devname, O_RDWR)) < 0)
  1630. X            slerror ("%s: open %s failed", argv[0], devname);
  1631. X
  1632. X        ioctl (fd_dev, I_POP, "ldterm");        /* ignore ioctl error */
  1633. X        ioctl (fd_dev, I_POP, "ttcompat");
  1634. X
  1635. X        if (ioctl (fd_dev, TCGETA, &tio) < 0)
  1636. X            slerror ("%s: ioctl TCGETA failed", argv[0]);
  1637. X
  1638. X        tio.c_iflag = BRKINT | IGNPAR;            /* sig break, no parity */
  1639. X        tio.c_cflag = CS8 | CREAD;                /* 8 bits, enable rcver */
  1640. X
  1641. X        switch (speed) {
  1642. X            case 1200:    tio.c_cflag |= B1200;        break;
  1643. X            case 1800:    tio.c_cflag |= B1800;        break;
  1644. X            case 2400:    tio.c_cflag |= B2400;        break;
  1645. X            case 4800:    tio.c_cflag |= B4800;        break;
  1646. X            case 19200: tio.c_cflag |= B19200;        break;
  1647. X            case 38400:    tio.c_cflag |= B38400;        break;
  1648. X            default:    tio.c_cflag |= B9600;        break;
  1649. X        }
  1650. X
  1651. X        if (ioctl (fd_dev, TCSETA, &tio) < 0)
  1652. X            slerror ("%s: ioctl TCSANOW failed", argv[0]);
  1653. X    }
  1654. X
  1655. X    /*
  1656. X     * the default is to catch SIGHUP, but if iflag is set ignore SIGHUP.
  1657. X     */
  1658. X
  1659. X    if (!iflag)
  1660. X        signal (SIGHUP, slsignal);
  1661. X    else
  1662. X        sigignore (SIGHUP);
  1663. X
  1664. X    /*
  1665. X     * link slip to device, open ip, link ip with fd_dev
  1666. X     */
  1667. X
  1668. X    if ((fd_slip = open (slipname, O_RDWR)) < 0)
  1669. X        slerror ("%s: open %s failed", argv[0], slipname);
  1670. X
  1671. X    if ((fd_ip = open (ipname, O_RDWR)) < 0)
  1672. X        slerror ("%s: open %s failed", argv[0], ipname);
  1673. X
  1674. X    if (ioctl (fd_slip, I_LINK, fd_dev) < 0)
  1675. X        slerror ("%s: ioctl I_LINK %s failed", argv[0], slipname);
  1676. X
  1677. X    if ((fd_link = ioctl (fd_ip, I_LINK, fd_slip)) < 0)
  1678. X        slerror ("%s: ioctl I_LINK %s failed", argv[0], ipname);
  1679. X
  1680. X    /*
  1681. X     * send a SIOCSIFNAME (set interface name) ioctl down the stream
  1682. X     * referenced by fd_ip for the link associated with link identier
  1683. X     * fd_link specifying the name ifname
  1684. X     */
  1685. X
  1686. X    strcpy (ifr.ifr_name,ifname);
  1687. X    ifr.ifr_metric = fd_link;
  1688. X
  1689. X    iocb.ic_cmd = SIOCSIFNAME;
  1690. X    iocb.ic_timout = 15;
  1691. X    iocb.ic_len = sizeof (ifr);
  1692. X    iocb.ic_dp = (char *) 𝔦
  1693. X
  1694. X    if (ioctl (fd_ip, I_STR, &iocb) < 0)
  1695. X        slerror ("%s: ioctl SIOCSIFNAME (set interface name) failed", argv[0]);
  1696. X
  1697. X    kill (getppid(), SIGINT);                    /* interrupt signal parent */
  1698. X    pause ();                                    /* wait forever */
  1699. X}
  1700. X
  1701. X/*
  1702. X * slsignal
  1703. X */
  1704. X
  1705. Xvoid slsignal (int x)
  1706. X{
  1707. X    fprintf (stderr,"%s: %s got a SIGHUP, ... exiting ...\n",program,ifname);
  1708. X    if (ppid)
  1709. X        kill (ppid, SIGHUP);
  1710. X    exit (0);
  1711. X}
  1712. X
  1713. X/*
  1714. X * slerror ()
  1715. X */
  1716. X
  1717. Xslerror (s1, s2, s3)
  1718. Xchar *s1, *s2, *s3;
  1719. X{
  1720. X    fprintf (stderr,s1,s2,s3);
  1721. X    fprintf (stderr,"\n");
  1722. X    exit (1);
  1723. X}
  1724. X
  1725. X/*
  1726. X * usage ()
  1727. X */
  1728. X
  1729. Xusage ()
  1730. X{
  1731. X    printf ("\nUsage: %s [-i] system_name interface_name\n",program);
  1732. X    printf (  "OR:    %s -d [-i] device_name interface_name\n",program);
  1733. X    printf (  "OR:    %s - interface_name [process_id]\n",program);
  1734. X    exit (1);
  1735. X}
  1736. END_OF_FILE
  1737.   if test 9007 -ne `wc -c <'utils/slattach.c'`; then
  1738.     echo shar: \"'utils/slattach.c'\" unpacked with wrong size!
  1739.   fi
  1740.   # end of 'utils/slattach.c'
  1741. fi
  1742. if test -f 'utils/slhangupd.c' -a "${1}" != "-c" ; then 
  1743.   echo shar: Will not clobber existing file \"'utils/slhangupd.c'\"
  1744. else
  1745.   echo shar: Extracting \"'utils/slhangupd.c'\" \(3760 characters\)
  1746.   sed "s/^X//" >'utils/slhangupd.c' <<'END_OF_FILE'
  1747. X/*
  1748. X *            Copyright 1991, Intel Corporation
  1749. X *                  All rights reserved.
  1750. X *
  1751. X * Permission to use, copy, modify, and distribute this software and
  1752. X * its documentation for any purpose and without fee is hereby granted,
  1753. X * provided that the above copyright notice appear in all copies and
  1754. X * that both the copyright notice appear in all copies and that both
  1755. X * the copyright notice and this permission notice appear in
  1756. X * supporting documentation, and that the name of Intel Corporation
  1757. X * not be used in advertising or publicity pertaining to distribution
  1758. X * of the software without specific, written prior premission.
  1759. X * 
  1760. X * COMPANY AND/OR INTEL DISCLAIM ALL WARRANTIES WITH REGARD TO
  1761. X * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
  1762. X * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO
  1763. X * EVENT SHALL COMPANY NOR INTEL BE LIABLE FOR ANY SPECIAL,
  1764. X * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  1765. X * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1766. X * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  1767. X * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  1768. X * OF THIS SOFTWARE.
  1769. X */
  1770. X
  1771. X/*
  1772. X * Name:
  1773. X *        slhangup
  1774. X *
  1775. X * Synopsis:
  1776. X *        slhangup
  1777. X *
  1778. X * Description:
  1779. X *        Slhangup is used to receive M_HANGUP messages sent by the slip driver.
  1780. X *        This utility and extensions to the slip driver is necessary because
  1781. X *        tcp and ip throws away messages that they don't understand, such as,
  1782. X *        M_HANGUP.
  1783. X *
  1784. X * Example:
  1785. X *        slhangup
  1786. X *
  1787. X * Author:
  1788. X *        Sudji Husodo    1/31/91
  1789. X */
  1790. X
  1791. X#include <stdio.h>
  1792. X#include <stdlib.h>
  1793. X#include <stdio.h>
  1794. X#include <fcntl.h>
  1795. X#include <stropts.h>
  1796. X#include <termio.h>
  1797. X#include <signal.h>
  1798. X
  1799. X#include <sys/stream.h>
  1800. X#include <sys/socket.h>
  1801. X#include <sys/sockio.h>
  1802. X#include <net/if.h>
  1803. X#include <sys/slip.h>
  1804. X
  1805. Xvoid    unregister (int);
  1806. Xstruct    strioctl iocb;
  1807. Xchar    *slipname = "/dev/slip";
  1808. Xchar    *program;
  1809. Xint        fd_slip;
  1810. X
  1811. Xmain (int argc, char *argv[])
  1812. X{
  1813. X    struct    strbuf    ctlbuf;
  1814. X    pid_t    pid_sl;
  1815. X    int        flags = 0;
  1816. X
  1817. X    /*
  1818. X     * daemonize
  1819. X     */
  1820. X    program = argv[0];
  1821. X    setpgrp ();
  1822. X
  1823. X    switch (fork()) {
  1824. X    case 0:        break;
  1825. X    case -1:    perror ("fork failed");        exit (2);
  1826. X    default:    exit (0);
  1827. X    }
  1828. X
  1829. X    /*
  1830. X     * open the slip driver
  1831. X     */
  1832. X
  1833. X    if ((fd_slip = open (slipname, O_RDWR)) < 0)
  1834. X        slerror ("%s: open %s failed", argv[0], slipname);
  1835. X
  1836. X    iocb.ic_cmd = REG_SLHUP;
  1837. X    iocb.ic_timout = 0;
  1838. X    iocb.ic_len = 0;
  1839. X    iocb.ic_dp = "";
  1840. X
  1841. X    /*
  1842. X     * register the process, so the slip driver knows that there is
  1843. X     * hangup daemon waiting to receive M_HANGUP messages.
  1844. X     */
  1845. X
  1846. X    if (ioctl (fd_slip, I_STR, &iocb) < 0)
  1847. X        slerror ("%s: can't register slip's hangup daemon", argv[0]);
  1848. X
  1849. X    signal (SIGINT, unregister);
  1850. X    signal (SIGQUIT, unregister);
  1851. X    signal (SIGTERM, unregister);
  1852. X
  1853. X    /*
  1854. X     * wait for any message sent by slip, if getmsg completes succesfully,
  1855. X     * send a hangup signal to the slattach process id received in the
  1856. X     * message.
  1857. X     */ 
  1858. X
  1859. X    ctlbuf.maxlen = sizeof (pid_t);
  1860. X    ctlbuf.len = 0;
  1861. X    ctlbuf.buf = (char *) &pid_sl;
  1862. X
  1863. X    while (1) {
  1864. X        if (getmsg (fd_slip, &ctlbuf, NULL, &flags) < 0) {
  1865. X            fprintf (stderr, "\n%s: getmsg returns an error\n", program); 
  1866. X            continue;
  1867. X        }
  1868. X        fprintf (stderr, "\n%s: got M_HANGUP from slip, sending SIGUP to pid %d ...\n", program, pid_sl);
  1869. X
  1870. X        if (kill (pid_sl, SIGHUP) < 0) {
  1871. X            fprintf (stderr,"%s: can't send SIGHUP to pid %d\n",program,pid_sl);
  1872. X            continue;
  1873. X        }
  1874. X        sleep (1);
  1875. X    }
  1876. X}
  1877. X
  1878. X/*
  1879. X * slerror ()
  1880. X */
  1881. X
  1882. Xslerror (s1, s2, s3)
  1883. Xchar *s1, *s2, *s3;
  1884. X{
  1885. X    fprintf (stderr,s1,s2,s3);
  1886. X    fprintf (stderr,"\n");
  1887. X    exit (1);
  1888. X}
  1889. X
  1890. X/*
  1891. X * unregister - unregister if the slip hangup daemon is terminated.
  1892. X */
  1893. X
  1894. Xvoid unregister (int x)
  1895. X{
  1896. X    fprintf (stderr, "\n%s: killed ...\n", program);
  1897. X    iocb.ic_cmd = UNREG_SLHUP;
  1898. X    if (ioctl (fd_slip, I_STR, &iocb) < 0)
  1899. X        slerror ("%s: can't unregister slip's hangup daemon", program);
  1900. X    exit (0);
  1901. X}
  1902. END_OF_FILE
  1903.   if test 3760 -ne `wc -c <'utils/slhangupd.c'`; then
  1904.     echo shar: \"'utils/slhangupd.c'\" unpacked with wrong size!
  1905.   fi
  1906.   # end of 'utils/slhangupd.c'
  1907. fi
  1908. echo shar: End of archive 3 \(of 4\).
  1909. cp /dev/null ark3isdone
  1910. MISSING=""
  1911. for I in 1 2 3 4 ; do
  1912.     if test ! -f ark${I}isdone ; then
  1913.     MISSING="${MISSING} ${I}"
  1914.     fi
  1915. done
  1916. if test "${MISSING}" = "" ; then
  1917.     echo You have unpacked all 4 archives.
  1918.     rm -f ark[1-9]isdone
  1919. else
  1920.     echo You still must unpack the following archives:
  1921.     echo "        " ${MISSING}
  1922. fi
  1923. exit 0
  1924. exit 0 # Just in case...
  1925.