📄 sys-ultrix.c
字号:
tios.c_iflag |= IXON | IXOFF; tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */ tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */ } speed = translate_speed(inspeed); if (speed) { cfsetospeed(&tios, speed); cfsetispeed(&tios, speed); } else { speed = cfgetospeed(&tios); /* * We can't proceed if the serial port speed is B0, * since that implies that the serial port is disabled. */ if (speed == B0) fatal("Baud rate for %s is 0; need explicit baud rate", devnam); } if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) fatal("tcsetattr: %m"); x = 0; if (ioctl(fd, (crtscts > 0 || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0) warn("TIOC(N)MODEM: %m"); if (ioctl(fd, (local || !modem)? TIOCNCAR: TIOCCAR) < 0) warn("TIOC(N)CAR: %m"); baud_rate = inspeed = baud_rate_of(speed); restore_term = 1;}/* * restore_tty - restore the terminal to the saved settings. */voidrestore_tty(fd) int fd;{ if (restore_term) { if (!default_device) { /* * Turn off echoing, because otherwise we can get into * a loop with the tty and the modem echoing to each other. * We presume we are the sole user of this tty device, so * when we close it, it will revert to its defaults anyway. */ inittermios.c_lflag &= ~(ECHO | ECHONL); } if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0) if (errno != ENXIO) warn("tcsetattr: %m"); ioctl(fd, TIOCSWINSZ, &wsinfo); restore_term = 0; }}/* * setdtr - control the DTR line on the serial port. * This is called from die(), so it shouldn't call die(). */voidsetdtr(fd, on)int fd, on;{ int modembits = TIOCM_DTR; ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits);}/* * open_ppp_loopback - open the device we use for getting * packets in demand mode, and connect it to a ppp interface. * Here we use would use a pty, except that Ultrix ptys are brain-dead. */intopen_ppp_loopback(){ fatal("open_ppp_loopback called!"); /* return loop_master; */}/* * output - Output PPP packet. */voidoutput(unit, p, len) int unit; u_char *p; int len;{ if (debug) dbglog("sent %P", p, len); if (write(ttyfd, p, len) < 0) { if (errno != EIO) error("write: %m"); }}/* * wait_input - wait until there is data available, * for the length of time specified by *timo (indefinite * if timo is NULL). */voidwait_input(timo) struct timeval *timo;{ fd_set ready; int n; ready = in_fds; n = select(ttyfd+1, &ready, NULL, &ready, timo); if (n < 0 && errno != EINTR) fatal("select: %m");}/* * add_fd - add an fd to the set that wait_input waits for. */void add_fd(fd) int fd;{ FD_SET(fd, &in_fds); if (fd > max_in_fd) max_in_fd = fd;}/* * remove_fd - remove an fd from the set that wait_input waits for. */void remove_fd(fd) int fd;{ FD_CLR(fd, &in_fds);}#if 0/* * wait_loop_output - wait until there is data available on the * loopback, for the length of time specified by *timo (indefinite * if timo is NULL). */voidwait_loop_output(timo) struct timeval *timo;{ wait_time(timo);}/* * wait_time - wait for a given length of time or until a * signal is received. */voidwait_time(timo) struct timeval *timo;{ int n; n = select(0, NULL, NULL, NULL, timo); if (n < 0 && errno != EINTR) fatal("select: %m");}#endif/* * read_packet - get a PPP packet from the serial device. */intread_packet(buf) u_char *buf;{ int len; if ((len = read(ttyfd, buf, PPP_MTU + PPP_HDRLEN)) < 0) { if (errno == EWOULDBLOCK || errno == EINTR) return -1; fatal("read(fd): %m"); } return len;}/* * get_loop_output - read characters from the loopback, form them * into frames, and detect when we want to bring the real link up. * Return value is 1 if we need to bring up the link, 0 otherwise. */intget_loop_output(){ return 0;}/* * ppp_send_config - configure the transmit characteristics of * the ppp interface. */voidppp_send_config(unit, mtu, asyncmap, pcomp, accomp) int unit, mtu; u_int32_t asyncmap; int pcomp, accomp;{ u_int x; if (ioctl(ppp_fd, PPPIOCSMTU, &mtu) < 0) fatal("ioctl(PPPIOCSMTU): %m"); if (ioctl(ppp_fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) fatal("ioctl(PPPIOCSASYNCMAP): %m"); if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) fatal("ioctl (PPPIOCGFLAGS): %m"); x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT; x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC; if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) fatal("ioctl(PPPIOCSFLAGS): %m");}/* * ppp_set_xaccm - set the extended transmit ACCM for the interface. */voidppp_set_xaccm(unit, accm) int unit; ext_accm accm;{ if (ioctl(ppp_fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY) warn("ioctl(set extended ACCM): %m");}/* * ppp_recv_config - configure the receive-side characteristics of * the ppp interface. */voidppp_recv_config(unit, mru, asyncmap, pcomp, accomp) int unit, mru; u_int32_t asyncmap; int pcomp, accomp;{ int x; if (ioctl(ppp_fd, PPPIOCSMRU, (caddr_t) &mru) < 0) fatal("ioctl(PPPIOCSMRU): %m"); if (ioctl(ppp_fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) fatal("ioctl(PPPIOCSRASYNCMAP): %m"); if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) fatal("ioctl (PPPIOCGFLAGS): %m"); x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC; if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) fatal("ioctl(PPPIOCSFLAGS): %m");}/* * ccp_test - ask kernel whether a given compression method * is acceptable for use. Returns 1 if the method and parameters * are OK, 0 if the method is known but the parameters are not OK * (e.g. code size should be reduced), or -1 if the method is unknown. */intccp_test(unit, opt_ptr, opt_len, for_transmit) int unit, opt_len, for_transmit; u_char *opt_ptr;{ struct ppp_option_data data; data.ptr = opt_ptr; data.length = opt_len; data.transmit = for_transmit; if (ioctl(ttyfd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0) return 1; return (errno == ENOBUFS)? 0: -1;}/* * ccp_flags_set - inform kernel about the current state of CCP. */voidccp_flags_set(unit, isopen, isup) int unit, isopen, isup;{ int x; if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { error("ioctl (PPPIOCGFLAGS): %m"); return; } x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN; x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP; if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) error("ioctl(PPPIOCSFLAGS): %m");}/* * ccp_fatal_error - returns 1 if decompression was disabled as a * result of an error detected after decompression of a packet, * 0 otherwise. This is necessary because of patent nonsense. */intccp_fatal_error(unit) int unit;{ int x; if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { error("ioctl(PPPIOCGFLAGS): %m"); return 0; } return x & SC_DC_FERROR;}/* * get_idle_time - return how long the link has been idle. */intget_idle_time(u, ip) int u; struct ppp_idle *ip;{ return ioctl(ppp_fd, PPPIOCGIDLE, ip) >= 0;}/* * get_ppp_stats - return statistics for the link. */intget_ppp_stats(u, stats) int u; struct pppd_stats *stats;{ struct ifpppstatsreq req; memset (&req, 0, sizeof (req)); strlcpy(req.ifr_name, interface, sizeof(req.ifr_name)); if (ioctl(sockfd, SIOCGPPPSTATS, &req) < 0) { error("Couldn't get PPP statistics: %m"); return 0; } stats->bytes_in = req.stats.p.ppp_ibytes; stats->bytes_out = req.stats.p.ppp_obytes; return 1;}/* * sifvjcomp - config tcp header compression */intsifvjcomp(u, vjcomp, cidcomp, maxcid) int u, vjcomp, cidcomp, maxcid;{ u_int x; if (ioctl(ppp_fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) { error("ioctl (PPPIOCGFLAGS): %m"); return 0; } x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP; x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID; if (ioctl(ppp_fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) { error("ioctl(PPPIOCSFLAGS): %m"); return 0; } if (ioctl(ppp_fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) { error("ioctl(PPPIOCSFLAGS): %m"); return 0; } return 1;}/* * sifup - Config the interface up and enable IP packets to pass. */intsifup(u) int u;{ struct ifreq ifr; strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { error("ioctl (SIOCGIFFLAGS): %m"); return 0; } ifr.ifr_flags |= IFF_UP; if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { error("ioctl(SIOCSIFFLAGS): %m"); return 0; } if_is_up = 1; return 1;}/* * sifnpmode - Set the mode for handling packets for a given NP. */intsifnpmode(u, proto, mode) int u; int proto; enum NPmode mode;{ struct npioctl npi; npi.protocol = proto; npi.mode = mode; if (ioctl(ppp_fd, PPPIOCSNPMODE, &npi) < 0) { error("ioctl(set NP %d mode to %d): %m", proto, mode); return 0; } return 1;}/* * sifdown - Config the interface down and disable IP. */intsifdown(u) int u;{ struct ifreq ifr; int rv; struct npioctl npi; rv = 1; npi.protocol = PPP_IP; npi.mode = NPMODE_ERROR; ioctl(ppp_fd, PPPIOCSNPMODE, (caddr_t) &npi); /* ignore errors, because ppp_fd might have been closed by now. */ strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { error("ioctl (SIOCGIFFLAGS): %m"); rv = 0; } else { ifr.ifr_flags &= ~IFF_UP; if (ioctl(sockfd, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) { error("ioctl(SIOCSIFFLAGS): %m"); rv = 0; } else if_is_up = 0; } return rv;}/* * SET_SA_FAMILY - set the sa_family field of a struct sockaddr, * if it exists. */#define SET_SA_FAMILY(addr, family) \ BZERO((char *) &(addr), sizeof(addr)); \ addr.sa_family = (family);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -