+ if (!NILP (tem))
+ {
+ val = XCAR (XCDR (tem));
+ if (CONSP (val))
+ val = XCDR (val);
+ }
+ else if (!NILP (Vcoding_system_for_write))
+ val = Vcoding_system_for_write;
+ else if (NILP (current_buffer->enable_multibyte_characters))
+ val = Qnil;
+ else
+ {
+ if (EQ (coding_systems, Qt))
+ {
+ if (NILP (host) || NILP (service))
+ coding_systems = Qnil;
+ else
+ {
+ args[0] = Qopen_network_stream, args[1] = name,
+ args[2] = buffer, args[3] = host, args[4] = service;
+ GCPRO1 (proc);
+ coding_systems = Ffind_operation_coding_system (5, args);
+ UNGCPRO;
+ }
+ }
+ if (CONSP (coding_systems))
+ val = XCDR (coding_systems);
+ else if (CONSP (Vdefault_process_coding_system))
+ val = XCDR (Vdefault_process_coding_system);
+ else
+ val = Qnil;
+ }
+ p->encode_coding_system = val;
+ }
+ setup_process_coding_systems (proc);
+
+ p->decoding_buf = make_uninit_string (0);
+ p->decoding_carryover = make_number (0);
+ p->encoding_buf = make_uninit_string (0);
+ p->encoding_carryover = make_number (0);
+
+ p->inherit_coding_system_flag
+ = (!NILP (tem) || NILP (buffer) || !inherit_process_coding_system
+ ? Qnil : Qt);
+
+ UNGCPRO;
+ return proc;
+}
+#endif /* HAVE_SOCKETS */
+
+\f
+#if defined(HAVE_SOCKETS) && defined(HAVE_NET_IF_H) && defined(HAVE_SYS_IOCTL_H)
+
+#ifdef SIOCGIFCONF
+DEFUN ("network-interface-list", Fnetwork_interface_list, Snetwork_interface_list, 0, 0, 0,
+ doc: /* Return an alist of all network interfaces and their network address.
+Each element is a cons, the car of which is a string containing the
+interface name, and the cdr is the network address in internal
+format; see the description of ADDRESS in `make-network-process'. */)
+ ()
+{
+ struct ifconf ifconf;
+ struct ifreq *ifreqs = NULL;
+ int ifaces = 0;
+ int buf_size, s;
+ Lisp_Object res;
+
+ s = socket (AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ return Qnil;
+
+ again:
+ ifaces += 25;
+ buf_size = ifaces * sizeof(ifreqs[0]);
+ ifreqs = (struct ifreq *)xrealloc(ifreqs, buf_size);
+ if (!ifreqs)
+ {
+ close (s);
+ return Qnil;
+ }
+
+ ifconf.ifc_len = buf_size;
+ ifconf.ifc_req = ifreqs;
+ if (ioctl (s, SIOCGIFCONF, &ifconf))
+ {
+ close (s);
+ return Qnil;
+ }
+
+ if (ifconf.ifc_len == buf_size)
+ goto again;
+
+ close (s);
+ ifaces = ifconf.ifc_len / sizeof (ifreqs[0]);
+
+ res = Qnil;
+ while (--ifaces >= 0)
+ {
+ struct ifreq *ifq = &ifreqs[ifaces];
+ char namebuf[sizeof (ifq->ifr_name) + 1];
+ if (ifq->ifr_addr.sa_family != AF_INET)
+ continue;
+ bcopy (ifq->ifr_name, namebuf, sizeof (ifq->ifr_name));
+ namebuf[sizeof (ifq->ifr_name)] = 0;
+ res = Fcons (Fcons (build_string (namebuf),
+ conv_sockaddr_to_lisp (&ifq->ifr_addr,
+ sizeof (struct sockaddr))),
+ res);
+ }
+
+ return res;
+}
+#endif /* SIOCGIFCONF */
+
+#if defined(SIOCGIFADDR) || defined(SIOCGIFHWADDR) || defined(SIOCGIFFLAGS)
+
+struct ifflag_def {
+ int flag_bit;
+ char *flag_sym;
+};
+
+static struct ifflag_def ifflag_table[] = {
+#ifdef IFF_UP
+ { IFF_UP, "up" },
+#endif
+#ifdef IFF_BROADCAST
+ { IFF_BROADCAST, "broadcast" },
+#endif
+#ifdef IFF_DEBUG
+ { IFF_DEBUG, "debug" },
+#endif
+#ifdef IFF_LOOPBACK
+ { IFF_LOOPBACK, "loopback" },
+#endif
+#ifdef IFF_POINTOPOINT
+ { IFF_POINTOPOINT, "pointopoint" },
+#endif
+#ifdef IFF_RUNNING
+ { IFF_RUNNING, "running" },
+#endif
+#ifdef IFF_NOARP
+ { IFF_NOARP, "noarp" },
+#endif
+#ifdef IFF_PROMISC
+ { IFF_PROMISC, "promisc" },
+#endif
+#ifdef IFF_NOTRAILERS
+ { IFF_NOTRAILERS, "notrailers" },
+#endif
+#ifdef IFF_ALLMULTI
+ { IFF_ALLMULTI, "allmulti" },
+#endif
+#ifdef IFF_MASTER
+ { IFF_MASTER, "master" },
+#endif
+#ifdef IFF_SLAVE
+ { IFF_SLAVE, "slave" },
+#endif
+#ifdef IFF_MULTICAST
+ { IFF_MULTICAST, "multicast" },
+#endif
+#ifdef IFF_PORTSEL
+ { IFF_PORTSEL, "portsel" },
+#endif
+#ifdef IFF_AUTOMEDIA
+ { IFF_AUTOMEDIA, "automedia" },
+#endif
+#ifdef IFF_DYNAMIC
+ { IFF_DYNAMIC, "dynamic" },
+#endif
+ { 0, 0 }
+};
+
+DEFUN ("network-interface-info", Fnetwork_interface_info, Snetwork_interface_info, 1, 1, 0,
+ doc: /* Return information about network interface named IFNAME.
+The return value is a list (ADDR BCAST NETMASK HWADDR FLAGS),
+where ADDR is the layer 3 address, BCAST is the layer 3 broadcast address,
+NETMASK is the layer 3 network mask, HWADDR is the layer 2 addres, and
+FLAGS is the current flags of the interface. */)
+ (ifname)
+ Lisp_Object ifname;
+{
+ struct ifreq rq;
+ Lisp_Object res = Qnil;
+ Lisp_Object elt;
+ int s;
+ int any = 0;
+
+ CHECK_STRING (ifname);
+
+ bzero (rq.ifr_name, sizeof rq.ifr_name);
+ strncpy (rq.ifr_name, SDATA (ifname), sizeof (rq.ifr_name));
+
+ s = socket (AF_INET, SOCK_STREAM, 0);
+ if (s < 0)
+ return Qnil;
+
+ elt = Qnil;
+#if defined(SIOCGIFFLAGS) && defined(HAVE_STRUCT_IFREQ_IFR_FLAGS)
+ if (ioctl (s, SIOCGIFFLAGS, &rq) == 0)
+ {
+ int flags = rq.ifr_flags;
+ struct ifflag_def *fp;
+ int fnum;