2 * sys-str.c - System-dependent procedures for setting up
3 * PPP interfaces on systems which use the STREAMS ppp interface.
5 * Copyright (c) 1989 Carnegie Mellon University.
8 * Redistribution and use in source and binary forms are permitted
9 * provided that the above copyright notice and this paragraph are
10 * duplicated in all such forms and that any documentation,
11 * advertising materials, and other materials related to such
12 * distribution and use acknowledge that the software was developed
13 * by Carnegie Mellon University. The name of the
14 * University may not be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 static char rcsid[] = "$Id: sys-str.c,v 1.13 1994/09/16 02:35:42 paulus Exp $";
38 #include <sys/types.h>
39 #include <sys/socket.h>
40 #include <sys/sockio.h>
42 #include <sys/stream.h>
43 #include <sys/stropts.h>
46 #include <net/route.h>
47 #include <net/if_arp.h>
48 #include <netinet/in.h>
52 #include <net/ppp_str.h>
55 #define ifr_mtu ifr_metric
58 #define MAXMODULES 10 /* max number of module names to save */
59 static struct modlist {
60 char modname[FMNAMESZ+1];
61 } str_modules[MAXMODULES];
62 static int str_module_count = 0;
63 static int pushed_ppp;
64 static int closed_stdio;
66 static int restore_term; /* 1 => we've munged the terminal */
67 static struct termios inittermios; /* Initial TTY termios */
70 * sys_init - System-dependent initialization.
75 openlog("pppd", LOG_PID | LOG_NDELAY, LOG_PPP);
76 setlogmask(LOG_UPTO(LOG_INFO));
78 setlogmask(LOG_UPTO(LOG_DEBUG));
82 * note_debug_level - note a change in the debug level.
88 syslog(LOG_INFO, "Debug turned ON, Level %d", debug);
89 setlogmask(LOG_UPTO(LOG_DEBUG));
91 setlogmask(LOG_UPTO(LOG_WARNING));
96 * daemon - Detach us from the terminal session.
99 daemon(nochdir, noclose)
100 int nochdir, noclose;
104 if ((pid = fork()) < 0)
107 exit(0); /* parent dies */
112 fclose(stdin); /* don't need stdin, stdout, stderr */
121 * ppp_available - check if this kernel supports PPP.
128 fd = open("/dev/tty", O_RDONLY, 0);
130 return 1; /* can't find out - assume we have ppp */
131 ret = ioctl(fd, I_FIND, "pppasync") >= 0;
138 * establish_ppp - Turn the serial port into a ppp interface.
143 /* go through and save the name of all the modules, then pop em */
145 if (ioctl(fd, I_LOOK, str_modules[str_module_count].modname) < 0 ||
146 ioctl(fd, I_POP, 0) < 0)
148 MAINDEBUG((LOG_DEBUG, "popped stream module : %s",
149 str_modules[str_module_count].modname));
153 /* now push the async/fcs module */
154 if (ioctl(fd, I_PUSH, "pppasync") < 0) {
155 syslog(LOG_ERR, "ioctl(I_PUSH, ppp_async): %m");
158 /* push the compress module */
159 if (ioctl(fd, I_PUSH, "pppcomp") < 0) {
160 syslog(LOG_WARNING, "ioctl(I_PUSH, ppp_comp): %m");
162 /* finally, push the ppp_if module that actually handles the */
163 /* network interface */
164 if (ioctl(fd, I_PUSH, "pppif") < 0) {
165 syslog(LOG_ERR, "ioctl(I_PUSH, ppp_if): %m");
169 /* read mode, message non-discard mode */
170 if (ioctl(fd, I_SRDOPT, RMSGN) < 0) {
171 syslog(LOG_ERR, "ioctl(I_SRDOPT, RMSGN): %m");
175 * Find out which interface we were given.
176 * (ppp_if handles this ioctl)
178 if (ioctl(fd, SIOCGETU, &ifunit) < 0) {
179 syslog(LOG_ERR, "ioctl(SIOCGETU): %m");
183 /* Set debug flags in driver */
184 if (ioctl(fd, SIOCSIFDEBUG, &kdebugflag) < 0) {
185 syslog(LOG_ERR, "ioctl(SIOCSIFDEBUG): %m");
188 /* close stdin, stdout, stderr if they might refer to the device */
189 if (default_device && !closed_stdio) {
192 for (i = 0; i <= 2; ++i)
193 if (i != fd && i != s)
200 * disestablish_ppp - Restore the serial port to normal operation.
201 * It attempts to reconstruct the stream with the previously popped
202 * modules. This shouldn't call die() because it's called from die().
211 /* we can't push or pop modules after the stream has hung up */
212 str_module_count = 0;
213 restore_term = 0; /* nor can we fix up terminal settings */
219 * Check whether the link seems not to be 8-bit clean.
221 if (ioctl(fd, SIOCGIFDEBUG, (caddr_t) &flags) == 0) {
223 switch (~flags & PAI_FLAGS_HIBITS) {
225 s = "bit 7 set to 1";
228 s = "bit 7 set to 0";
230 case PAI_FLAGS_PAR_EVEN:
233 case PAI_FLAGS_PAR_ODD:
238 syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
239 syslog(LOG_WARNING, "All received characters had %s", s);
244 while (ioctl(fd, I_POP, 0) == 0) /* pop any we pushed */
248 for (; str_module_count > 0; str_module_count--) {
249 if (ioctl(fd, I_PUSH, str_modules[str_module_count-1].modname)) {
251 syslog(LOG_WARNING, "str_restore: couldn't push module %s: %m",
252 str_modules[str_module_count-1].modname);
254 MAINDEBUG((LOG_INFO, "str_restore: pushed module %s",
255 str_modules[str_module_count-1].modname));
262 * List of valid speeds.
265 int speed_int, speed_val;
337 * Translate from bits/second to a speed_t.
343 struct speed *speedp;
347 for (speedp = speeds; speedp->speed_int; speedp++)
348 if (bps == speedp->speed_int)
349 return speedp->speed_val;
350 syslog(LOG_WARNING, "speed %d not supported", bps);
355 * Translate from a speed_t to bits/second.
361 struct speed *speedp;
365 for (speedp = speeds; speedp->speed_int; speedp++)
366 if (speed == speedp->speed_val)
367 return speedp->speed_int;
372 * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
373 * at the requested speed, etc. If `local' is true, set CLOCAL
374 * regardless of whether the modem option was specified.
376 set_up_tty(fd, local)
382 if (tcgetattr(fd, &tios) < 0) {
383 syslog(LOG_ERR, "tcgetattr: %m");
390 tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
392 tios.c_cflag |= CRTSCTS;
393 else if (crtscts < 0)
394 tios.c_cflag &= ~CRTSCTS;
396 tios.c_cflag |= CS8 | CREAD | HUPCL;
398 tios.c_cflag |= CLOCAL;
399 tios.c_iflag = IGNBRK | IGNPAR;
403 tios.c_cc[VTIME] = 0;
406 tios.c_iflag |= IXOFF;
407 tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
408 tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
411 speed = translate_speed(inspeed);
413 cfsetospeed(&tios, speed);
414 cfsetispeed(&tios, speed);
416 speed = cfgetospeed(&tios);
418 * We can't proceed if the serial port speed is B0,
419 * since that implies that the serial port is disabled.
422 syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
428 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
429 syslog(LOG_ERR, "tcsetattr: %m");
433 baud_rate = inspeed = baud_rate_of(speed);
438 * restore_tty - restore the terminal to the saved settings.
444 if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
446 syslog(LOG_WARNING, "tcsetattr: %m");
452 * setdtr - control the DTR line on the serial port.
453 * This is called from die(), so it shouldn't call die().
458 int modembits = TIOCM_DTR;
460 ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits);
465 * output - Output PPP packet.
476 MAINDEBUG((LOG_WARNING, "output: unit != 0!"));
478 log_packet(p, len, "sent ");
481 str.buf = (caddr_t) p;
482 if (putmsg(fd, NULL, &str, 0) < 0) {
483 if (errno != ENXIO) {
484 syslog(LOG_ERR, "putmsg: %m");
491 * wait_input - wait for input, for a length of time specified in *timo.
494 struct timeval *timo;
499 t = timo == NULL? -1: timo->tv_sec * 1000 + timo->tv_usec / 1000;
501 pfd.events = POLLIN | POLLPRI | POLLHUP;
502 if (poll(&pfd, 1, t) < 0 && errno != EINTR) {
503 syslog(LOG_ERR, "poll: %m");
509 * read_packet - get a PPP packet from the serial device.
515 struct strbuf str, ctl;
517 unsigned char ctlbuf[16];
519 str.maxlen = MTU+DLLHEADERLEN;
520 str.buf = (caddr_t) buf;
521 ctl.maxlen = sizeof(ctlbuf);
522 ctl.buf = (caddr_t) ctlbuf;
524 len = getmsg(fd, &ctl, &str, &i);
526 if (errno == EAGAIN || errno == EWOULDBLOCK) {
529 syslog(LOG_ERR, "getmsg(fd) %m");
533 MAINDEBUG((LOG_DEBUG, "getmsg returned 0x%x",len));
535 syslog(LOG_NOTICE, "got ctrl msg len %d %x %x\n", ctl.len,
536 ctlbuf[0], ctlbuf[1]);
539 MAINDEBUG((LOG_DEBUG, "getmsg short return length %d", str.len));
548 * ppp_send_config - configure the transmit characteristics of
552 ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
560 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
562 if (ioctl(s, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
563 syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
567 if(ioctl(fd, SIOCSIFASYNCMAP, (caddr_t) &asyncmap) < 0) {
568 syslog(LOG_ERR, "ioctl(SIOCSIFASYNCMAP): %m");
573 if(ioctl(fd, SIOCSIFCOMPPROT, &c) < 0) {
574 syslog(LOG_ERR, "ioctl(SIOCSIFCOMPPROT): %m");
579 if(ioctl(fd, SIOCSIFCOMPAC, &c) < 0) {
580 syslog(LOG_ERR, "ioctl(SIOCSIFCOMPAC): %m");
587 * ppp_set_xaccm - set the extended transmit ACCM for the interface.
590 ppp_set_xaccm(unit, accm)
594 if (ioctl(fd, SIOCSIFXASYNCMAP, accm) < 0 && errno != ENOTTY)
595 syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
600 * ppp_recv_config - configure the receive-side characteristics of
604 ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
611 if (ioctl(fd, SIOCSIFMRU, &mru) < 0) {
612 syslog(LOG_ERR, "ioctl(SIOCSIFMRU): %m");
615 if (ioctl(fd, SIOCSIFRASYNCMAP, (caddr_t) &asyncmap) < 0) {
616 syslog(LOG_ERR, "ioctl(SIOCSIFRASYNCMAP): %m");
619 c = 2 + (pcomp? 1: 0);
620 if(ioctl(fd, SIOCSIFCOMPPROT, &c) < 0) {
621 syslog(LOG_ERR, "ioctl(SIOCSIFCOMPPROT): %m");
624 c = 2 + (accomp? 1: 0);
625 if (ioctl(fd, SIOCSIFCOMPAC, &c) < 0) {
626 syslog(LOG_ERR, "ioctl(SIOCSIFCOMPAC): %m");
631 * ccp_test - ask kernel whether a given compression method
632 * is acceptable for use.
634 ccp_test(unit, opt_ptr, opt_len, for_transmit)
635 int unit, opt_len, for_transmit;
638 struct ppp_option_data data;
640 if ((unsigned) opt_len > MAX_PPP_OPTION)
641 opt_len = MAX_PPP_OPTION;
642 data.length = opt_len;
643 data.transmit = for_transmit;
644 BCOPY(opt_ptr, data.opt_data, opt_len);
645 return ioctl(fd, SIOCSCOMPRESS, (caddr_t) &data) >= 0;
649 * ccp_flags_set - inform kernel about the current state of CCP.
652 ccp_flags_set(unit, isopen, isup)
653 int unit, isopen, isup;
657 x = (isopen? 1: 0) + (isup? 2: 0);
658 if (ioctl(fd, SIOCSIFCOMP, (caddr_t) &x) < 0 && errno != ENOTTY)
659 syslog(LOG_ERR, "ioctl (SIOCSIFCOMP): %m");
663 * ccp_fatal_error - returns 1 if decompression was disabled as a
664 * result of an error detected after decompression of a packet,
665 * 0 otherwise. This is necessary because of patent nonsense.
668 ccp_fatal_error(unit)
673 if (ioctl(fd, SIOCGIFCOMP, (caddr_t) &x) < 0) {
674 syslog(LOG_ERR, "ioctl(SIOCGIFCOMP): %m");
677 return x & CCP_FATALERROR;
681 * sifvjcomp - config tcp header compression
684 sifvjcomp(u, vjcomp, cidcomp, maxcid)
685 int u, vjcomp, cidcomp, maxcid;
689 x = (vjcomp? 1: 0) + (cidcomp? 0: 2) + (maxcid << 4);
690 if (ioctl(fd, SIOCSIFVJCOMP, (caddr_t) &x) < 0) {
691 syslog(LOG_ERR, "ioctl(SIOCSIFVJCOMP): %m");
698 * sifup - Config the interface up.
706 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
707 if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
708 syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
711 ifr.ifr_flags |= IFF_UP;
712 if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
713 syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
720 * sifdown - Config the interface down.
727 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
728 if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
729 syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
732 ifr.ifr_flags &= ~IFF_UP;
733 if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
734 syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
741 * SET_SA_FAMILY - initialize a struct sockaddr, setting the sa_family field.
743 #define SET_SA_FAMILY(addr, family) \
744 BZERO((char *) &(addr), sizeof(addr)); \
745 addr.sa_family = (family);
748 * sifaddr - Config the interface IP addresses and netmask.
759 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
760 SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
761 ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
762 if (ioctl(s, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
763 syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m");
766 ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
767 if (ioctl(s, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
768 syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
772 ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
773 syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
774 if (ioctl(s, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
775 syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
783 * cifaddr - Clear the interface IP addresses, and delete routes
784 * through the interface if possible.
793 SET_SA_FAMILY(rt.rt_dst, AF_INET);
794 ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = h;
795 SET_SA_FAMILY(rt.rt_gateway, AF_INET);
796 ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
797 rt.rt_flags = RTF_HOST;
798 if (ioctl(s, SIOCDELRT, (caddr_t) &rt) < 0) {
799 syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
806 * sifdefaultroute - assign a default route through the address given.
809 sifdefaultroute(u, g)
815 SET_SA_FAMILY(rt.rt_dst, AF_INET);
816 SET_SA_FAMILY(rt.rt_gateway, AF_INET);
817 ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
818 rt.rt_flags = RTF_GATEWAY;
819 if (ioctl(s, SIOCADDRT, &rt) < 0) {
820 syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m");
827 * cifdefaultroute - delete a default route through the address given.
830 cifdefaultroute(u, g)
836 SET_SA_FAMILY(rt.rt_dst, AF_INET);
837 SET_SA_FAMILY(rt.rt_gateway, AF_INET);
838 ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
839 rt.rt_flags = RTF_GATEWAY;
840 if (ioctl(s, SIOCDELRT, &rt) < 0) {
841 syslog(LOG_ERR, "default route ioctl(SIOCDELRT): %m");
848 * sifproxyarp - Make a proxy ARP entry for the peer.
851 sifproxyarp(unit, hisaddr)
855 struct arpreq arpreq;
857 BZERO(&arpreq, sizeof(arpreq));
860 * Get the hardware address of an interface on the same subnet
861 * as our local address.
863 if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
864 syslog(LOG_WARNING, "Cannot determine ethernet address for proxy ARP");
868 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
869 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
870 arpreq.arp_flags = ATF_PERM | ATF_PUBL;
871 if (ioctl(s, SIOCSARP, (caddr_t)&arpreq) < 0) {
872 syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
880 * cifproxyarp - Delete the proxy ARP entry for the peer.
883 cifproxyarp(unit, hisaddr)
887 struct arpreq arpreq;
889 BZERO(&arpreq, sizeof(arpreq));
890 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
891 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
892 if (ioctl(s, SIOCDARP, (caddr_t)&arpreq) < 0) {
893 syslog(LOG_ERR, "ioctl(SIOCDARP): %m");
900 * get_ether_addr - get the hardware address of an interface on the
901 * the same subnet as ipaddr. Code borrowed from myetheraddr.c
902 * in the cslip-2.6 distribution, which is subject to the following
903 * copyright notice (which also applies to logwtmp below):
905 * Copyright (c) 1990, 1992 The Regents of the University of California.
906 * All rights reserved.
908 * Redistribution and use in source and binary forms, with or without
909 * modification, are permitted provided that: (1) source code distributions
910 * retain the above copyright notice and this paragraph in its entirety, (2)
911 * distributions including binary code include the above copyright notice and
912 * this paragraph in its entirety in the documentation or other materials
913 * provided with the distribution, and (3) all advertising materials mentioning
914 * features or use of this software display the following acknowledgement:
915 * ``This product includes software developed by the University of California,
916 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
917 * the University nor the names of its contributors may be used to endorse
918 * or promote products derived from this software without specific prior
919 * written permission.
920 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
921 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
922 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
928 #include <arpa/inet.h>
930 /* XXX SunOS 4.1 defines this and 3.5 doesn't... */
936 #include <netinet/in_var.h>
938 #include <netinet/if_ether.h>
940 /* Cast a struct sockaddr to a structaddr_in */
941 #define SATOSIN(sa) ((struct sockaddr_in *)(sa))
943 /* Determine if "bits" is set in "flag" */
944 #define ALLSET(flag, bits) (((flag) & (bits)) == (bits))
946 static struct nlist nl[] = {
955 get_ether_addr(ipaddr, hwaddr)
957 struct sockaddr *hwaddr;
960 register struct ifnet *ifp;
961 register struct arpcom *ac;
962 struct arpcom arpcom;
965 register struct ifaddr *ifa;
966 register struct in_ifaddr *in;
974 /* Open kernel memory for reading */
975 kd = kvm_open(0, 0, 0, O_RDONLY, NULL);
977 syslog(LOG_ERR, "kvm_open: %m");
982 if (kvm_nlist(kd, nl) != 0) {
983 syslog(LOG_ERR, "kvm_nlist failed");
994 if (kvm_read(kd, nl[N_IFNET].n_value, (char *)&addr, sizeof(addr))
996 syslog(LOG_ERR, "error reading ifnet addr");
999 for ( ; addr; addr = (uint32)ifp->if_next) {
1000 if (kvm_read(kd, addr, (char *)ac, sizeof(*ac)) != sizeof(*ac)) {
1001 syslog(LOG_ERR, "error reading ifnet");
1005 /* Only look at configured, broadcast interfaces */
1006 if (!ALLSET(ifp->if_flags, IFF_UP | IFF_BROADCAST))
1009 /* This probably can't happen... */
1010 if (ifp->if_addrlist == 0)
1014 /* Get interface ip address */
1016 if (kvm_read(kd, (uint32)ifp->if_addrlist, (char *)&ifaddr,
1017 sizeof(ifaddr)) != sizeof(ifaddr)) {
1018 syslog(LOG_ERR, "error reading ifaddr");
1021 inp = &SATOSIN(&ifa->ifa_addr)->sin_addr;
1023 inp = &SATOSIN(&ifp->if_addr)->sin_addr;
1026 /* Check if this interface on the right subnet */
1028 mask = in->ia_subnetmask;
1030 mask = ifp->if_subnetmask;
1032 if ((ipaddr & mask) != (inp->s_addr & mask))
1035 /* Copy out the local ethernet address */
1036 hwaddr->sa_family = AF_UNSPEC;
1037 BCOPY((caddr_t) &arpcom.ac_enaddr, hwaddr->sa_data,
1038 sizeof(arpcom.ac_enaddr));
1039 return 1; /* success! */
1042 /* couldn't find one */
1046 #define WTMPFILE "/usr/adm/wtmp"
1049 logwtmp(line, name, host)
1050 char *line, *name, *host;
1056 if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
1058 if (!fstat(fd, &buf)) {
1059 (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
1060 (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
1061 (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
1062 (void)time(&ut.ut_time);
1063 if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp))
1064 (void)ftruncate(fd, buf.st_size);