2 * sys-ultrix.c - System-dependent procedures for setting up
3 * PPP interfaces on Ultrix systems.
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-ultrix.c,v 1.7 1994/11/22 02:42:09 paulus Exp $";
34 #include <sys/types.h>
36 #include <sys/socket.h>
37 #include <sys/ioctl.h>
39 #include <sys/errno.h>
43 #include <net/ppp_defs.h>
44 #include <net/if_ppp.h>
45 #include <net/route.h>
46 #include <netinet/in.h>
50 static int initdisc = -1; /* Initial TTY discipline */
52 static int restore_term; /* 1 => we've munged the terminal */
53 static struct termios inittermios; /* Initial TTY termios */
56 * sys_init - System-dependent initialization.
61 openlog("pppd", LOG_PID);
65 * note_debug_level - note a change in the debug level.
74 * daemon - Detach us from the terminal session.
77 daemon(nochdir, noclose)
82 if ((pid = fork()) < 0)
85 exit(0); /* parent dies */
90 fclose(stdin); /* don't need stdin, stdout, stderr */
99 * ppp_available - check whether the system has any ppp interfaces
100 * (in fact we check whether we can do an ioctl on ppp0).
109 if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
110 return 1; /* can't tell - maybe we're not root */
112 strncpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name));
113 ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0;
121 * establish_ppp - Turn the serial port into a ppp interface.
126 int pppdisc = PPPDISC;
129 if (ioctl(fd, TIOCGETD, &initdisc) < 0) {
130 syslog(LOG_ERR, "ioctl(TIOCGETD): %m");
133 if (ioctl(fd, TIOCSETD, &pppdisc) < 0) {
134 syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
139 * Find out which interface we were given.
141 if (ioctl(fd, PPPIOCGUNIT, &ifunit) < 0) {
142 syslog(LOG_ERR, "ioctl(PPPIOCGUNIT): %m");
147 * Enable debug in the driver if requested.
150 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
151 syslog(LOG_WARNING, "ioctl (PPPIOCGFLAGS): %m");
153 x |= (kdebugflag & 0xFF) * SC_DEBUG;
154 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
155 syslog(LOG_WARNING, "ioctl(PPPIOCSFLAGS): %m");
162 * disestablish_ppp - Restore the serial port to normal operation.
163 * This shouldn't call die() because it's called from die().
173 * Check whether the link seems not to be 8-bit clean.
175 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) == 0) {
177 switch (~x & (SC_RCV_B7_0|SC_RCV_B7_1|SC_RCV_EVNP|SC_RCV_ODDP)) {
179 s = "bit 7 set to 1";
182 s = "bit 7 set to 0";
192 syslog(LOG_WARNING, "Serial link is not 8-bit clean:");
193 syslog(LOG_WARNING, "All received characters had %s", s);
196 if (ioctl(fd, TIOCSETD, &initdisc) < 0)
197 syslog(LOG_ERR, "ioctl(TIOCSETD): %m");
203 * List of valid speeds.
206 int speed_int, speed_val;
278 * Translate from bits/second to a speed_t.
284 struct speed *speedp;
288 for (speedp = speeds; speedp->speed_int; speedp++)
289 if (bps == speedp->speed_int)
290 return speedp->speed_val;
291 syslog(LOG_WARNING, "speed %d not supported", bps);
296 * Translate from a speed_t to bits/second.
302 struct speed *speedp;
306 for (speedp = speeds; speedp->speed_int; speedp++)
307 if (speed == speedp->speed_val)
308 return speedp->speed_int;
313 * set_up_tty: Set up the serial port on `fd' for 8 bits, no parity,
314 * at the requested speed, etc. If `local' is true, set CLOCAL
315 * regardless of whether the modem option was specified.
317 set_up_tty(fd, local)
323 if (tcgetattr(fd, &tios) < 0) {
324 syslog(LOG_ERR, "tcgetattr: %m");
331 tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
334 tios.c_cflag |= CRTSCTS;
335 else if (crtscts < 0)
336 tios.c_cflag &= ~CRTSCTS;
339 tios.c_cflag |= CS8 | CREAD | HUPCL;
341 tios.c_cflag |= CLOCAL;
342 tios.c_iflag = IGNBRK | IGNPAR;
346 tios.c_cc[VTIME] = 0;
349 tios.c_iflag |= IXOFF;
350 tios.c_cc[VSTOP] = 0x13; /* DC3 = XOFF = ^S */
351 tios.c_cc[VSTART] = 0x11; /* DC1 = XON = ^Q */
354 speed = translate_speed(inspeed);
356 cfsetospeed(&tios, speed);
357 cfsetispeed(&tios, speed);
359 speed = cfgetospeed(&tios);
361 * We can't proceed if the serial port speed is B0,
362 * since that implies that the serial port is disabled.
365 syslog(LOG_ERR, "Baud rate for %s is 0; need explicit baud rate",
371 if (tcsetattr(fd, TCSAFLUSH, &tios) < 0) {
372 syslog(LOG_ERR, "tcsetattr: %m");
377 if (ioctl(fd, (crtscts || modem)? TIOCMODEM: TIOCNMODEM, &x) < 0)
378 syslog(LOG_WARNING, "TIOC(N)MODEM: %m");
379 if (ioctl(fd, (local || !modem)? TIOCNCAR: TIOCCAR) < 0)
380 syslog(LOG_WARNING, "TIOC(N)CAR: %m");
382 baud_rate = inspeed = baud_rate_of(speed);
387 * restore_tty - restore the terminal to the saved settings.
393 if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
395 syslog(LOG_WARNING, "tcsetattr: %m");
396 restore_term = FALSE;
401 * setdtr - control the DTR line on the serial port.
402 * This is called from die(), so it shouldn't call die().
407 int modembits = TIOCM_DTR;
409 ioctl(fd, (on? TIOCMBIS: TIOCMBIC), &modembits);
414 * output - Output PPP packet.
423 MAINDEBUG((LOG_WARNING, "output: unit != 0!"));
425 log_packet(p, len, "sent ");
427 if (write(fd, p, len) < 0) {
428 syslog(LOG_ERR, "write: %m");
435 * wait_input - wait until there is data available on fd,
436 * for the length of time specified by *timo (indefinite
440 struct timeval *timo;
447 n = select(fd+1, &ready, NULL, &ready, timo);
448 if (n < 0 && errno != EINTR) {
449 syslog(LOG_ERR, "select: %m");
456 * read_packet - get a PPP packet from the serial device.
464 if ((len = read(fd, buf, PPP_MTU + PPP_HDRLEN)) < 0) {
465 if (errno == EWOULDBLOCK || errno == EINTR) {
466 MAINDEBUG((LOG_DEBUG, "read(fd): %m"));
469 syslog(LOG_ERR, "read(fd): %m");
477 * ppp_send_config - configure the transmit characteristics of
481 ppp_send_config(unit, mtu, asyncmap, pcomp, accomp)
489 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
491 if (ioctl(s, SIOCSIFMTU, (caddr_t) &ifr) < 0) {
492 syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m");
496 if (ioctl(fd, PPPIOCSASYNCMAP, (caddr_t) &asyncmap) < 0) {
497 syslog(LOG_ERR, "ioctl(PPPIOCSASYNCMAP): %m");
501 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
502 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
505 x = pcomp? x | SC_COMP_PROT: x &~ SC_COMP_PROT;
506 x = accomp? x | SC_COMP_AC: x &~ SC_COMP_AC;
507 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
508 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
515 * ppp_set_xaccm - set the extended transmit ACCM for the interface.
518 ppp_set_xaccm(unit, accm)
522 if (ioctl(fd, PPPIOCSXASYNCMAP, accm) < 0 && errno != ENOTTY)
523 syslog(LOG_WARNING, "ioctl(set extended ACCM): %m");
528 * ppp_recv_config - configure the receive-side characteristics of
532 ppp_recv_config(unit, mru, asyncmap, pcomp, accomp)
539 if (ioctl(fd, PPPIOCSMRU, (caddr_t) &mru) < 0) {
540 syslog(LOG_ERR, "ioctl(PPPIOCSMRU): %m");
543 if (ioctl(fd, PPPIOCSRASYNCMAP, (caddr_t) &asyncmap) < 0) {
544 syslog(LOG_ERR, "ioctl(PPPIOCSRASYNCMAP): %m");
547 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
548 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
551 x = !accomp? x | SC_REJ_COMP_AC: x &~ SC_REJ_COMP_AC;
552 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
553 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
559 * ccp_test - ask kernel whether a given compression method
560 * is acceptable for use.
562 ccp_test(unit, opt_ptr, opt_len, for_transmit)
563 int unit, opt_len, for_transmit;
566 struct ppp_option_data data;
569 data.length = opt_len;
570 data.transmit = for_transmit;
571 return ioctl(fd, PPPIOCSCOMPRESS, (caddr_t) &data) >= 0;
575 * ccp_flags_set - inform kernel about the current state of CCP.
578 ccp_flags_set(unit, isopen, isup)
579 int unit, isopen, isup;
583 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
584 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
587 x = isopen? x | SC_CCP_OPEN: x &~ SC_CCP_OPEN;
588 x = isup? x | SC_CCP_UP: x &~ SC_CCP_UP;
589 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0)
590 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
594 * ccp_fatal_error - returns 1 if decompression was disabled as a
595 * result of an error detected after decompression of a packet,
596 * 0 otherwise. This is necessary because of patent nonsense.
599 ccp_fatal_error(unit)
604 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
605 syslog(LOG_ERR, "ioctl(PPPIOCGFLAGS): %m");
608 return x & SC_DC_FERROR;
612 * sifvjcomp - config tcp header compression
615 sifvjcomp(u, vjcomp, cidcomp, maxcid)
616 int u, vjcomp, cidcomp, maxcid;
620 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
621 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
624 x = vjcomp ? x | SC_COMP_TCP: x &~ SC_COMP_TCP;
625 x = cidcomp? x & ~SC_NO_TCP_CCID: x | SC_NO_TCP_CCID;
626 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
627 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
630 if (ioctl(fd, PPPIOCSMAXCID, (caddr_t) &maxcid) < 0) {
631 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
638 * sifup - Config the interface up and enable IP packets to pass.
641 #define SC_ENABLE_IP 0x100 /* compat for old versions of kernel code */
652 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
653 if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
654 syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
657 ifr.ifr_flags |= IFF_UP;
658 if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
659 syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
662 npi.protocol = PPP_IP;
663 npi.mode = NPMODE_PASS;
664 if (ioctl(fd, PPPIOCSNPMODE, &npi) < 0) {
665 if (errno != ENOTTY) {
666 syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m");
669 /* for backwards compatibility */
670 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
671 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
675 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
676 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
684 * sifdown - Config the interface down and disable IP.
696 npi.protocol = PPP_IP;
697 npi.mode = NPMODE_ERROR;
698 if (ioctl(fd, PPPIOCSNPMODE, (caddr_t) &npi) < 0) {
699 if (errno != ENOTTY) {
700 syslog(LOG_ERR, "ioctl(PPPIOCSNPMODE): %m");
703 /* backwards compatibility */
704 if (ioctl(fd, PPPIOCGFLAGS, (caddr_t) &x) < 0) {
705 syslog(LOG_ERR, "ioctl (PPPIOCGFLAGS): %m");
709 if (ioctl(fd, PPPIOCSFLAGS, (caddr_t) &x) < 0) {
710 syslog(LOG_ERR, "ioctl(PPPIOCSFLAGS): %m");
717 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
718 if (ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) {
719 syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m");
722 ifr.ifr_flags &= ~IFF_UP;
723 if (ioctl(s, SIOCSIFFLAGS, (caddr_t) &ifr) < 0) {
724 syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m");
732 * SET_SA_FAMILY - set the sa_family field of a struct sockaddr,
735 #define SET_SA_FAMILY(addr, family) \
736 BZERO((char *) &(addr), sizeof(addr)); \
737 addr.sa_family = (family);
740 * sifaddr - Config the interface IP addresses and netmask.
751 strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name));
752 SET_SA_FAMILY(ifr.ifr_addr, AF_INET);
753 ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o;
754 if (ioctl(s, SIOCSIFADDR, (caddr_t) &ifr) < 0) {
755 syslog(LOG_ERR, "ioctl(SIOCSIFADDR): %m");
758 ((struct sockaddr_in *) &ifr.ifr_dstaddr)->sin_addr.s_addr = h;
759 if (ioctl(s, SIOCSIFDSTADDR, (caddr_t) &ifr) < 0) {
760 syslog(LOG_ERR, "ioctl(SIOCSIFDSTADDR): %m");
764 ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = m;
765 syslog(LOG_INFO, "Setting interface mask to %s\n", ip_ntoa(m));
766 if (ioctl(s, SIOCSIFNETMASK, (caddr_t) &ifr) < 0) {
767 syslog(LOG_ERR, "ioctl(SIOCSIFNETMASK): %m");
775 * cifaddr - Clear the interface IP addresses, and delete routes
776 * through the interface if possible.
785 SET_SA_FAMILY(rt.rt_dst, AF_INET);
786 ((struct sockaddr_in *) &rt.rt_dst)->sin_addr.s_addr = h;
787 SET_SA_FAMILY(rt.rt_gateway, AF_INET);
788 ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = o;
789 rt.rt_flags = RTF_HOST;
790 if (ioctl(s, SIOCDELRT, (caddr_t) &rt) < 0) {
791 syslog(LOG_ERR, "ioctl(SIOCDELRT): %m");
798 * sifdefaultroute - assign a default route through the address given.
801 sifdefaultroute(u, g)
805 SET_SA_FAMILY(rt.rt_dst, AF_INET);
806 SET_SA_FAMILY(rt.rt_gateway, AF_INET);
807 ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
808 rt.rt_flags = RTF_GATEWAY;
809 if (ioctl(s, SIOCADDRT, &rt) < 0) {
810 syslog(LOG_ERR, "default route ioctl(SIOCADDRT): %m");
817 * cifdefaultroute - delete a default route through the address given.
820 cifdefaultroute(u, g)
824 SET_SA_FAMILY(rt.rt_dst, AF_INET);
825 SET_SA_FAMILY(rt.rt_gateway, AF_INET);
826 ((struct sockaddr_in *) &rt.rt_gateway)->sin_addr.s_addr = g;
827 rt.rt_flags = RTF_GATEWAY;
828 if (ioctl(s, SIOCDELRT, &rt) < 0)
829 syslog(LOG_WARNING, "default route ioctl(SIOCDELRT): %m");
833 * sifproxyarp - Make a proxy ARP entry for the peer.
836 sifproxyarp(unit, hisaddr)
840 struct arpreq arpreq;
842 BZERO(&arpreq, sizeof(arpreq));
845 * Get the hardware address of an interface on the same subnet
846 * as our local address.
848 if (!get_ether_addr(hisaddr, &arpreq.arp_ha)) {
849 syslog(LOG_ERR, "Cannot determine ethernet address for proxy ARP");
853 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
854 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
855 arpreq.arp_flags = ATF_PERM | ATF_PUBL;
856 if (ioctl(s, SIOCSARP, (caddr_t)&arpreq) < 0) {
857 syslog(LOG_ERR, "ioctl(SIOCSARP): %m");
865 * cifproxyarp - Delete the proxy ARP entry for the peer.
868 cifproxyarp(unit, hisaddr)
872 struct arpreq arpreq;
874 BZERO(&arpreq, sizeof(arpreq));
875 SET_SA_FAMILY(arpreq.arp_pa, AF_INET);
876 ((struct sockaddr_in *) &arpreq.arp_pa)->sin_addr.s_addr = hisaddr;
877 if (ioctl(s, SIOCDARP, (caddr_t)&arpreq) < 0) {
878 syslog(LOG_WARNING, "ioctl(SIOCDARP): %m");
885 * get_ether_addr - get the hardware address of an interface on the
886 * the same subnet as ipaddr.
891 get_ether_addr(ipaddr, hwaddr)
893 struct sockaddr *hwaddr;
895 struct ifreq *ifr, *ifend, *ifp;
897 struct sockaddr_dl *dla;
900 struct ifreq ifs[MAX_IFS];
902 ifc.ifc_len = sizeof(ifs);
904 if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
905 syslog(LOG_ERR, "ioctl(SIOCGIFCONF): %m");
910 * Scan through looking for an interface with an Internet
911 * address on the same subnet as `ipaddr'.
913 ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
914 for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
915 ((char *)&ifr->ifr_addr + sizeof(struct sockaddr))) {
916 if (ifr->ifr_addr.sa_family == AF_INET) {
917 ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
918 strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
920 * Check that the interface is up, and not point-to-point
923 if (ioctl(s, SIOCGIFFLAGS, &ifreq) < 0)
925 if ((ifreq.ifr_flags &
926 (IFF_UP|IFF_BROADCAST|IFF_POINTOPOINT|IFF_LOOPBACK|IFF_NOARP))
927 != (IFF_UP|IFF_BROADCAST))
930 * Get its netmask and check that it's on the right subnet.
932 if (ioctl(s, SIOCGIFNETMASK, &ifreq) < 0)
934 mask = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
935 if ((ipaddr & mask) != (ina & mask))
944 syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
947 * Now scan through again looking for a link-level address
948 * for this interface.
951 for (ifr = ifc.ifc_req; ifr < ifend; ) {
952 if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0
953 && ifr->ifr_addr.sa_family == AF_DLI) {
954 /* && ifr->ifr_addr.sa_family == AF_LINK) { Per! Kolla !!! ROHACK */
956 * Found the link-level address - copy it out
958 dla = (struct sockaddr_dl *)&ifr->ifr_addr;
959 hwaddr->sa_family = AF_UNSPEC;
960 BCOPY(dla, hwaddr->sa_data, sizeof(hwaddr->sa_data));
963 ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + sizeof(struct sockaddr)
972 Seems like strdup() is not part of string package in Ultrix.
973 If I understood the man-page on the sun this should work.
978 char *strdup( in ) char *in;
981 if(! (dup = (char *) malloc( strlen( in ) +1 ))) return NULL;
982 (void) strcpy( dup, in );
987 * This logwtmp() implementation is subject to the following copyright:
989 * Copyright (c) 1988 The Regents of the University of California.
990 * All rights reserved.
992 * Redistribution and use in source and binary forms are permitted
993 * provided that the above copyright notice and this paragraph are
994 * duplicated in all such forms and that any documentation,
995 * advertising materials, and other materials related to such
996 * distribution and use acknowledge that the software was developed
997 * by the University of California, Berkeley. The name of the
998 * University may not be used to endorse or promote products derived
999 * from this software without specific prior written permission.
1000 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1001 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1002 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1005 #define WTMPFILE "/usr/adm/wtmp"
1008 logwtmp(line, name, host)
1009 char *line, *name, *host;
1015 if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
1017 if (!fstat(fd, &buf)) {
1018 (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line));
1019 (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name));
1020 (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host));
1021 (void)time(&ut.ut_time);
1022 if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp))
1023 (void)ftruncate(fd, buf.st_size);