From: ueno Date: Sun, 27 Jan 2002 17:22:19 +0000 (+0000) Subject: * getaddrinfo.h: Removed and gave up to emulate getaddrinfo(3). Thus X-Git-Tag: liece-2_0_0-pre1~1 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=4867e075e0e952abe8f3c780f8274527d01aa0c8;p=elisp%2Fliece.git * getaddrinfo.h: Removed and gave up to emulate getaddrinfo(3). Thus on systems where there is no such thing, we are now being unable to use IPv6. * getaddrinfo.c: Ditto. * dcc.ml: Removed. * naddr.ml: Removed. * naddr.mli: Removed. * basename.c: New file. * dcc.c: Fix header info. * tcp.c: Fix header info. * tcp.c (main) [!HAVE_GETADDRINFO]: Don't use the fake getaddrinfo. --- diff --git a/dcc/Makefile.am b/dcc/Makefile.am index 9c54399..81b32b3 100644 --- a/dcc/Makefile.am +++ b/dcc/Makefile.am @@ -1,34 +1,10 @@ ## 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 $< diff --git a/dcc/basename.c b/dcc/basename.c new file mode 100644 index 0000000..8fae497 --- /dev/null +++ b/dcc/basename.c @@ -0,0 +1,40 @@ +/* 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 +#endif + +#include + +#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; +} diff --git a/dcc/dcc.c b/dcc/dcc.c index 7671cc0..cd0ccd6 100644 --- a/dcc/dcc.c +++ b/dcc/dcc.c @@ -1,28 +1,22 @@ -/* This file is part of Liece. - Copyright (C) 1998 Daiki Ueno - - Author: Daiki Ueno - 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 #include diff --git a/dcc/dcc.ml b/dcc/dcc.ml deleted file mode 100644 index 0b852dc..0000000 --- a/dcc/dcc.ml +++ /dev/null @@ -1,248 +0,0 @@ -(* DCC module. - -This file is part of Liece. - -Author: Daiki Ueno -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 "; - "receive "; - "chat listen "; - "chat connect " ]) - -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 () diff --git a/dcc/getaddrinfo.c b/dcc/getaddrinfo.c deleted file mode 100644 index 18eeccf..0000000 --- a/dcc/getaddrinfo.c +++ /dev/null @@ -1,124 +0,0 @@ -/* - * getaddrinfo(2) emulation. - * Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc. - - * Author: Daiki Ueno - -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 -#include -#include -#include -#include - -#ifdef HAVE_NETINET6_IN6_H -# include -#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 */ diff --git a/dcc/getaddrinfo.h b/dcc/getaddrinfo.h deleted file mode 100644 index d88883f..0000000 --- a/dcc/getaddrinfo.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * getaddrinfo(2) emulation. - * Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc. - - * Author: Daiki Ueno - -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); - - - diff --git a/dcc/naddr.ml b/dcc/naddr.ml deleted file mode 100644 index 24179a9..0000000 --- a/dcc/naddr.ml +++ /dev/null @@ -1,77 +0,0 @@ -(* Network address handling module. - -This file is part of Liece. - -Author: Daiki Ueno -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) diff --git a/dcc/naddr.mli b/dcc/naddr.mli deleted file mode 100644 index 0c9917a..0000000 --- a/dcc/naddr.mli +++ /dev/null @@ -1,31 +0,0 @@ -(* Network address handling module. - -This file is part of Liece. - -Author: Daiki Ueno -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. *) diff --git a/dcc/tcp.c b/dcc/tcp.c index 266b1ad..8ed67fe 100644 --- a/dcc/tcp.c +++ b/dcc/tcp.c @@ -1,27 +1,25 @@ -/* - * 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 - * Daiki Ueno - -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 . */ #include #include @@ -38,14 +36,6 @@ Boston, MA 02111-1307, USA. #define _GNU_SOURCE #include -#ifdef HAVE_SOCKS_H -#include -#endif - -#ifndef HAVE_GETADDRINFO -#include "getaddrinfo.h" -#endif /* !HAVE_GETADDRINFO */ - #ifdef HAVE_BASENAME # ifdef HAVE_LIBGEN_H # include @@ -82,11 +72,18 @@ main (argc, argv) 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; @@ -95,32 +92,35 @@ main (argc, argv) 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) { @@ -132,36 +132,61 @@ main (argc, argv) 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);