## Process this file with automake to produce Makefile.in
-
DEFS = -I$(srcdir) -I$(top_srcdir) $(CFLAGS) @DEFS@
-LIBS = -L. -ldcc @LIBS@
+LIBS = @LIBOBJS@
+EXTRA_DIST = getopt.c getopt.h getopt1.c
CLEANFILES = ldcc ltcp
-noinst_LIBRARIES = libdcc.a
bin_PROGRAMS = ldcc ltcp
-libdcc_a_SOURCES = getopt1.c getopt.c getaddrinfo.c
-noinst_HEADERS = getopt.h getaddrinfo.h
-
-ltcp_SOURCES = tcp.c
+ltcp_SOURCES = tcp.c
ldcc_SOURCES = dcc.c
-
-#MLHDRS = naddr.mli
-#MLSRCS = naddr.ml dcc.ml
-#MLOBJS = $(MLSRCS:.ml=.cmo)
-#MLINTF = $(MLHDRS:.mli=.cmi)
-#EXTRA_ldcc_SOURCES = $(MLHDRS) $(MLSRCS)
-#ldcc_SOURCES = $(MLSRCS)
-#ldcc_COMPILE = @OCAMLC@
-#ldcc_LINK = $(OCAMLC) -custom unix.cma nums.cma str.cma
-#ldcc_LDFLAGS = -cclib -lunix -cclib -lnums -cclib -lstr -o ldcc
-
-#SUFFIXES = .ml .mli .cmo .cmi
-
-#$(MLOBJS): $(MLINTF)
-
-#.mli.cmi:
-# $(OCAMLC) -c $<
-
-#.ml.cmo:
-# $(OCAMLC) -c $<
--- /dev/null
+/* Return the name-within-directory of a file name.
+ Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <string.h>
+
+#define _LIBC
+#ifndef _LIBC
+/* We cannot generally use the name `basename' since XPG defines an unusable
+ variant of the function but we cannot use it. */
+# define basename gnu_basename
+#endif
+
+
+char *
+basename (filename)
+ const char *filename;
+{
+ char *p = strrchr (filename, '/');
+ return p ? p + 1 : (char *) filename;
+}
-/* This file is part of Liece.
- Copyright (C) 1998 Daiki Ueno <daiki@kake.info.waseda.ac.jp>
-
- Author: Daiki Ueno <daiki@kake.info.waseda.ac.jp>
- Created: 1998-09-28
- Revised: 1999-01-28
- Keywords: IRC, liece, DCC
-
- This file is part of Liece.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNU Emacs; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
+/* dcc.c
+ * Copyright (C) 1998-2002 Daiki Ueno
+ *
+ * This file is part of Liece.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
#include <sys/types.h>
#include <sys/time.h>
+++ /dev/null
-(* DCC module.
-
-This file is part of Liece.
-
-Author: Daiki Ueno <daiki@kake.info.waseda.ac.jp>
-Created: 1998-09-28
-Revised: 1999-01-28
-Keywords: IRC, liece, DCC
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. *)
-
-open Unix
-
-let usage prefix progname =
- String.concat "\n"
- (List.map (fun x -> (Printf.sprintf "%s: %s %s" prefix progname x))
- [ "send <port> <filename>";
- "receive <host> <port> <size> <filename>";
- "chat listen <port>";
- "chat connect <host> <port>" ])
-
-let buff = String.create 1024
-
-let print_exc exc =
- match exc with
- Unix_error (err, fun_name, arg) ->
- prerr_string "\"";
- prerr_string fun_name;
- prerr_string "\" failed";
- if String.length arg > 0 then
- begin
- prerr_string " on \""; prerr_string arg; prerr_string "\""; ()
- end;
- prerr_string ": ";
- prerr_endline (error_message err);
- flush Pervasives.stderr; ()
- | _ ->
- try Printexc.print raise exc with
- _ -> ()
-
-let accept_connection f s =
- let (t, addr) = accept s in
- f t; close t; ()
-
-let write_file filename size t =
- let fd =
- try openfile filename [ O_RDONLY ] 0 with
- _ -> Printf.eprintf "Open failed.\n"; flush Pervasives.stderr; exit 1
- in
- let (len, rlen) = ref 0, ref 0 in
- while len := read fd buff 0 (String.length buff); !len <> 0
- do
- let rec loop i =
- let j = i + write t buff i (!len - i) in
- if j == !len then () else loop j
- in
- loop 0;
- flush (out_channel_of_descr t);
- rlen := !rlen + !len;
- Printf.printf "DCC %s %d%% (%d/%d bytes) sent.\n"
- filename (100 * !rlen / size) !rlen size;
- flush Pervasives.stdout
- done;
- close fd; close t; ()
-
-let send_file port filename =
- try
- let host = gethostbyname (gethostname ()) in
- let haddr = string_of_inet_addr host.h_addr_list.(0) in
- let s = socket PF_INET SOCK_STREAM 0 in
- setsockopt s SO_REUSEADDR true;
- bind s (ADDR_INET (inet_addr_any, port));
- let port =
- match (getsockname s) with
- ADDR_INET (addr, port) -> port
- | _ -> port
- in
- listen s 1;
- let fd =
- try openfile filename [ O_RDONLY ] 0 with
- _ -> Printf.eprintf "Open failed.\n"; flush Pervasives.stderr; exit 1
- in
- let size = (fstat fd).st_size in
- close fd;
- Printf.printf "DCC send %s %d %s %d\n"
- (Filename.basename filename) port (Naddr.encode haddr) size;
- flush Pervasives.stdout;
- accept_connection (fun t -> write_file filename size t) s;
- with
- exc -> print_exc exc
-
-let read_file filename size t =
- let fd =
- try openfile filename [ O_WRONLY; O_CREAT ] 0o600 with
- _ -> Printf.eprintf "Open failed.\n"; flush Pervasives.stderr; exit 1
- in
- let (len, rlen) = ref 0, ref 0 in
- while len := read t buff 0 (String.length buff); !len <> 0
- do
- let _ = write fd buff 0 !len in
- flush (out_channel_of_descr fd);
- rlen := !rlen + !len;
- Printf.printf "DCC %s %d%% (%d/%d bytes) received.\n"
- filename (100 * !rlen / size) !rlen size;
- flush Pervasives.stdout
- done;
- close fd; close t
-
-let receive_file host port size filename =
- let s = socket PF_INET SOCK_STREAM 0 in
- connect s (ADDR_INET (inet_addr_of_string (Naddr.decode host), port));
- read_file filename size s; ()
-
-let chat_loop s =
- let sel = ref [s; stdin] in
- while !sel <> [] do
- let (l, _, _) =
- try
- select !sel [] [] (-1.0)
- with
- _ -> exit 0
- in
- List.iter
- (fun x ->
- let (rfd, wfd) =
- if x == s then
- (s, stdout)
- else if x == stdin then
- (stdin, s)
- else
- (stdin, stdout)
- in
- let len = ref 0
- in
- len := read rfd buff 0 (String.length buff);
- if !len == 0 then
- begin try shutdown wfd SHUTDOWN_SEND; () with
- _ -> exit 0
- end
- else
- begin
- let rec loop i =
- let j = i + write wfd buff i (!len - i) in
- if j == !len then () else loop j
- in
- loop 0;
- flush (out_channel_of_descr wfd)
- end;
- ())
- l
- done
-
-let chat_listen port =
- let host = gethostbyname (gethostname ()) in
- let haddr = string_of_inet_addr host.h_addr_list.(0) in
- let s = socket PF_INET SOCK_STREAM 0 in
- setsockopt s SO_REUSEADDR true;
- bind s (ADDR_INET (inet_addr_any, port));
- let port =
- match (getsockname s) with
- ADDR_INET (addr, port) -> port
- | _ -> port
- in
- listen s 1;
- Printf.printf "DCC chat %s %d\n" (Naddr.encode haddr) port;
- flush Pervasives.stdout;
- accept_connection
- (fun t ->
- Printf.printf "DCC chat established\n";
- flush Pervasives.stdout;
- chat_loop t) s; ()
-
-let chat_connect host port =
- let s = socket PF_INET SOCK_STREAM 0 in
- connect s (ADDR_INET (inet_addr_of_string (Naddr.decode host), port));
- Printf.printf "DCC chat established\n";
- flush Pervasives.stdout;
- chat_loop s; ()
-
-let getaddr_ext server =
- let addr =
- try (gethostbyname server).h_addr_list.(0) with
- _ -> inet_addr_of_string "198.41.0.4"
- and port = 7 in
- let s = socket PF_INET SOCK_DGRAM 0 in
- connect s (ADDR_INET (addr, port));
- match (getsockname s) with
- ADDR_INET (addr, port) -> addr
- | _ -> raise Not_found
-
-let main () =
- let a = ref [] in
- let usage = usage "Usage" (Filename.basename Sys.argv.(0)) in
- let speclist = [] in
- Arg.parse speclist (fun x -> a := !a @ [x]) usage;
- begin match !a with
- "send" :: [ port; filename ] ->
- let port =
- try int_of_string port with
- _ -> Arg.usage speclist usage; exit 1
- in
- send_file port filename;
- exit 0; ()
- | "receive" :: [ host; port; size; filename ] ->
- let (port, size) =
- try
- int_of_string port,
- int_of_string size
- with
- _ -> Arg.usage speclist usage; exit 1
- in
- receive_file host port size filename;
- exit 0; ()
- | "chat" :: [ "listen"; port ] ->
- let port =
- try
- int_of_string port
- with
- _ -> Arg.usage speclist usage; exit 1
- in
- chat_listen port;
- exit 0; ()
- | "chat" :: [ "connect"; host; port ] ->
- let port =
- try
- int_of_string port
- with
- _ -> Arg.usage speclist usage; exit 1
- in
- chat_connect host port;
- exit 0; ()
- | _ -> Arg.usage speclist usage; exit 1
- end
-
-let _ = Printexc.catch main ()
+++ /dev/null
-/*
- * getaddrinfo(2) emulation.
- * Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
-
- * Author: Daiki Ueno <daiki@kiss.kake.info.waseda.ac.jp>
-
-This file is not part of any package.
-
-GNU Emacs is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
- */
-
-#ifndef HAVE_GETADDRINFO
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <netinet/in.h>
-
-#ifdef HAVE_NETINET6_IN6_H
-# include <netinet6/in6.h>
-#endif /* HAVE_NETINET6_IN6_H */
-
-#include "getaddrinfo.h"
-
-int getaddrinfo (hostname, servname, hints, res)
- const char *hostname;
- const char *servname;
- const struct addrinfo *hints;
- struct addrinfo **res;
-{
- struct hostent *host = NULL;
- struct servent *serv = NULL;
- struct protoent *proto;
- int port = 0;
-
-#if (defined (HAVE_SOCKADDR_IN6) && defined (INET6))
- struct sockaddr_in6 *sin =
- (struct sockaddr_in6 *) calloc (1, sizeof (struct sockaddr_in6));
-#else /* (defined (HAVE_SOCKADDR_IN6) && defined (INET6)) */
- struct sockaddr_in *sin =
- (struct sockaddr_in *) calloc (1, sizeof (struct sockaddr_in));
-#endif /* !(defined (HAVE_SOCKADDR_IN6) && defined (INET6)) */
-
- struct addrinfo *ai = *res =
- (struct addrinfo *) calloc (1, sizeof (struct addrinfo));
-
- if ((~ hints->ai_flags & AI_PASSIVE) && hostname &&
- (host = gethostbyname (hostname)) == NULL) {
- perror ("gethostbyname");
- return EAI_NONAME;
- }
-
- if (hints->ai_protocol &&
- (proto = getprotobynumber (hints->ai_protocol)) == NULL) {
- perror ("getprotobynumber");
- return EAI_NONAME;
- }
-
- if (servname)
- if (isdigit (servname[0]))
- port = atoi (servname);
- else {
- if ((serv = getservbyname (servname, proto->p_name)) == NULL) {
- perror ("getservbyname");
- return EAI_NONAME;
- }
- port = serv->s_port;
- }
-
-#if (defined (HAVE_SOCKADDR_IN6) && defined (INET6))
- if (host)
- memcpy (&sin->sin6_addr, host->h_addr, host->h_length);
- sin->sin6_port = htons (port);
-#else /* (defined (HAVE_SOCKADDR_IN6) && defined (INET6)) */
- if (host)
- memcpy (&sin->sin_addr, host->h_addr, host->h_length);
- sin->sin_port = htons (port);
-#endif /* !(defined (HAVE_SOCKADDR_IN6) && defined (INET6)) */
-
- if (hints->ai_family == AF_UNSPEC)
- ai->ai_family = host->h_addrtype;
- else
- ai->ai_family = hints->ai_family;
-#if (defined (HAVE_SOCKADDR_IN6) && defined (INET6))
- sin->sin6_family = ai->ai_family;
-#else /* (defined (HAVE_SOCKADDR_IN6) && defined (INET6)) */
- sin->sin_family = ai->ai_family;
-#endif /* !(defined (HAVE_SOCKADDR_IN6) && defined (INET6)) */
-
- ai->ai_protocol = hints->ai_protocol;
- ai->ai_socktype = hints->ai_socktype;
- ai->ai_addrlen = sizeof (*sin);
- ai->ai_addr = (struct sockaddr *)sin;
-
- return 0;
-}
-
-void freeaddrinfo (ai)
- struct addrinfo *ai;
-{
- struct addrinfo *p;
-
- while (ai != NULL) {
- p = ai;
- ai = ai->ai_next;
- free (p);
- }
-}
-
-#endif /* HAVE_GETADDRINFO */
+++ /dev/null
-/*
- * getaddrinfo(2) emulation.
- * Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
-
- * Author: Daiki Ueno <daiki@kiss.kake.info.waseda.ac.jp>
-
-This file is not part of any package.
-
-GNU Emacs is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
- */
-
-struct addrinfo {
- int ai_flags;
- int ai_family;
- int ai_socktype;
- int ai_protocol;
- size_t ai_addrlen;
- char *ai_canonname;
- struct sockaddr *ai_addr;
- struct addrinfo *ai_next;
-};
-
-/* Possible values for `ai_flags' field in `addrinfo' structure. */
-# define AI_PASSIVE 1 /* Socket address is intended for `bind'. */
-# define AI_CANONNAME 2 /* Request for canonical name. */
-# define AI_NUMERICHOST 3 /* Don't use name resolution. */
-
-/* Error values for `getaddrinfo' function. */
-#define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
-#define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
-#define EAI_AGAIN -3 /* Temporary failure in name resolution. */
-#define EAI_FAIL -4 /* Non-recoverable failure in name res. */
-#define EAI_NODATA -5 /* No address associated with NAME. */
-#define EAI_FAMILY -6 /* `ai_family' not supported. */
-#define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
-#define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
-#define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
-#define EAI_MEMORY -10 /* Memory allocation failure. */
-#define EAI_SYSTEM -11 /* System error returned in `errno'. */
-
-#define NI_MAXHOST 1025
-#define NI_MAXSERV 32
-
-#define NI_NUMERICHOST 1 /* Don't try to look up hostname. */
-#define NI_NUMERICSERV 2 /* Don't convert port number to name. */
-#define NI_NOFQDN 4 /* Only return nodename portion. */
-#define NI_NAMEREQD 8 /* Don't return numeric addresses. */
-#define NI_DGRAM 16 /* Look up UDP service rather than TCP. */
-
-extern int getaddrinfo (const char *, const char *, const struct addrinfo *,
- struct addrinfo **);
-
-extern void freeaddrinfo (struct addrinfo *ai);
-
-
-
+++ /dev/null
-(* Network address handling module.
-
-This file is part of Liece.
-
-Author: Daiki Ueno <daiki@kake.info.waseda.ac.jp>
-Created: 1998-09-28
-Revised: 1999-01-28
-Keywords: IRC, liece, DCC
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. *)
-
-open Num
-open Big_int
-open Str
-
-let encode str =
- let _ = string_match
- (regexp "\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)\.\([0-9]+\)") str 0 in
- let (a1, a2, a3, a4) =
- try
- int_of_string (matched_group 1 str),
- int_of_string (matched_group 2 str),
- int_of_string (matched_group 3 str),
- int_of_string (matched_group 4 str)
- with
- _ ->
- Printf.eprintf "Invalid address\n"; flush Pervasives.stdout; exit 1;
- in
- let (s1, s2, s3, s4) =
- Int (1 lsl 24),
- Int (1 lsl 16),
- Int (1 lsl 8),
- Int 1
- in
- let ul =
- ((Int a1) */ s1) +/ ((Int a2) */ s2) +/ ((Int a3) */ s3) +/ (Int a4)
- in
- string_of_num ul
-
-let decode str =
- let ul =
- try
- num_of_string str
- with
- _ ->
- Printf.eprintf "Invalid address\n"; flush Pervasives.stdout; exit 1;
- in
- let (s1, s2, s3, s4) =
- Int (1 lsl 24),
- Int (1 lsl 16),
- Int (1 lsl 8),
- Int 1
- in
- let (a1, a2, a3, a4) =
- floor_num (ul // s1),
- floor_num ((mod_num ul s1) // s2),
- floor_num ((mod_num (mod_num ul s1) s2) // s3),
- (mod_num (mod_num (mod_num ul s1) s2) s3)
- in
- Printf.sprintf "%s.%s.%s.%s"
- (string_of_num a1)
- (string_of_num a2)
- (string_of_num a3)
- (string_of_num a4)
+++ /dev/null
-(* Network address handling module.
-
-This file is part of Liece.
-
-Author: Daiki Ueno <daiki@kake.info.waseda.ac.jp>
-Created: 1998-09-28
-Revised: 1999-01-28
-Keywords: IRC, liece, DCC
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. *)
-
-val encode : string -> string;;
- (* [Naddr.encode s] encodes the XXX.XXX.XXX.XXX address [s] into
- another string packed by network byte order. *)
-
-val decode : string -> string;;
- (* [Naddr.decode s] does the inverse job than [Naddr.encode],
- restoring initial expression of address. *)
-/*
- * TCP/IP stream emulation for GNU Emacs.
+/* tcp.c - TCP/IP stream emulation for GNU Emacs.
* Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
-
- * Author: Masanobu Umeda <umerin@mse.kyutech.ac.jp>
- * Daiki Ueno <daiki@kiss.kake.info.waseda.ac.jp>
-
-This file is part of GNU Emacs.
-
-GNU Emacs is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Emacs is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
+ * Copyright (C) 1998-2002 Daiki Ueno
+ *
+ * This file is part of Liece.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+/* This program is based on `tcp' comming from old GNUS distribution
+ written by Masanobu Umeda <umerin@mse.kyutech.ac.jp>. */
#include <sys/types.h>
#include <sys/time.h>
#define _GNU_SOURCE
#include <getopt.h>
-#ifdef HAVE_SOCKS_H
-#include <socks.h>
-#endif
-
-#ifndef HAVE_GETADDRINFO
-#include "getaddrinfo.h"
-#endif /* !HAVE_GETADDRINFO */
-
#ifdef HAVE_BASENAME
# ifdef HAVE_LIBGEN_H
# include <libgen.h>
char *argv[];
{
struct protoent *proto;
-
+ int family, socktype;
+ struct sockaddr *addr;
+ size_t addrlen;
+#ifdef HAVE_GETADDRINFO
struct addrinfo *in, hints;
-
+#else
+ struct hostent *host;
+ struct servent *serv;
+ struct sockaddr_in sin;
+#endif
char *hostname = NULL, *service = "ircd";
- int family, port;
+ int port;
fd_set *readfds, *writefds;
int server, emacsIn = fileno (stdin), emacsOut = fileno (stdout);
char buffer[1024], *retry;
progname = (char *) basename (argv[0]);
- while (1) {
- int this_option_optind = optind ? optind : 1;
- int option_index = 0;
- static struct option long_options[] = {
- {"version", 0, 0, 'v'},
- {"help", 0, 0, 'h'},
- {0, 0, 0, 0}
- };
+ while (1)
+ {
+ int this_option_optind = optind ? optind : 1;
+ int option_index = 0;
+ static struct option long_options[] =
+ {
+ {"version", 0, 0, 'v'},
+ {"help", 0, 0, 'h'},
+ {0, 0, 0, 0}
+ };
- c = getopt_long (argc, argv, "vh", long_options, &option_index);
- if (c == -1)
- break;
+ c = getopt_long (argc, argv, "vh", long_options, &option_index);
+ if (c == -1)
+ break;
- switch (c) {
- case 'v':
- version();
- exit(1);
- break;
- case 'h':
- usage();
- exit(1);
- break;
- default:
- break;
+ switch (c)
+ {
+ case 'v':
+ version ();
+ exit (1);
+ break;
+ case 'h':
+ usage ();
+ exit (1);
+ break;
+ default:
+ break;
+ }
}
- }
if (argc < 2)
{
if (argc >= 3)
service = argv[2];
- if ((proto = getprotobyname ("tcp")) == NULL) {
- perror ("getprotobyname");
- exit (1);
- }
-
+ proto = getprotobyname ("tcp");
+ if (!proto)
+ {
+ perror ("getprotobyname");
+ exit (1);
+ }
+
+#ifdef HAVE_GETADDRINFO
memset (&hints, 0, sizeof (hints));
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = proto->p_proto;
- if (getaddrinfo (hostname, service, &hints, &in) < 0) {
- perror ("getaddrinfo");
- exit (1);
- }
-
- if ((server = socket (in->ai_family, in->ai_socktype, 0)) < 0) {
- perror ("socket");
- exit (1);
- }
-
- if (setsockopt (server, SOL_SOCKET, SO_REUSEADDR,
- (const char *) &false, sizeof (false))) {
- perror ("setsockopt");
- exit (1);
- }
-
- if (connect (server, in->ai_addr, in->ai_addrlen) < 0) {
- perror ("connect");
- close (server);
- exit (1);
- }
+ if (getaddrinfo (hostname, service, &hints, &in) < 0)
+ {
+ perror ("getaddrinfo");
+ exit (1);
+ }
+ family = in->ai_family;
+ socktype = in->ai_socktype;
+ addr = in->ai_addr;
+ addrlen = in->ai_addrlen;
+ freeaddrinfo (in);
+#else
+ memset (&sin, 0, sizeof (sin));
+ host = gethostbyname (hostname);
+ if (!host)
+ return -1;
+ memcpy (&sin.sin_addr, host->h_addr, host->h_length);
+ serv = getservbyname (service, proto->p_name);
+ if (serv)
+ sin.sin_port = htons (serv->s_port);
+ else if (isdigit (service[0]))
+ sin.sin_port = htons (atoi (service));
+ family = sin.sin_family = AF_INET;
+ socktype = SOCK_STREAM;
+ addr = (struct sockaddr *)&sin;
+ addrlen = sizeof (sin);
+#endif
+
+ server = socket (family, socktype, 0);
+ if (server == -1)
+ {
+ perror ("socket");
+ exit (1);
+ }
+
+ setsockopt (server, SOL_SOCKET, SO_REUSEADDR,
+ (const char *) &false, sizeof (false));
+
+ if (connect (server, addr, addrlen) < 0)
+ {
+ perror ("connect");
+ close (server);
+ exit (1);
+ }
#ifdef O_NDELAY
fcntl (server, F_SETFL, O_NDELAY);