* dcc.ml: Use Hostlong.t instead of Naddr.{encode,decode}.
* naddr.ml: Remove.
-(* 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 =
_ -> Printf.eprintf "Open failed.\n"; flush Pervasives.stderr; exit 1
in
let size = (fstat fd).st_size in
+ let hl = (Hostlong.of_address_string haddr) in
close fd;
Printf.printf "DCC send %s %d %s %d\n"
- (Filename.basename filename) port (Naddr.encode haddr) size;
+ (Filename.basename filename) port (Hostlong.to_string hl) size;
flush Pervasives.stdout;
accept_connection (fun t -> write_file filename size t) s;
with
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));
+ let hl = Hostlong.of_string host in
+ let inet_addr =
+ inet_addr_of_string (Hostlong.to_address_string hl)
+ in
+ connect s (ADDR_INET (inet_addr, port));
read_file filename size s; ()
let chat_loop s =
ADDR_INET (addr, port) -> port
| _ -> port
in
+ let hl = Hostlong.of_address_string haddr in
listen s 1;
- Printf.printf "DCC chat %s %d\n" (Naddr.encode haddr) port;
+ Printf.printf "DCC chat %s %d\n" (Hostlong.to_string hl) port;
flush Pervasives.stdout;
accept_connection
(fun t ->
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));
+ let hl = Hostlong.of_string host in
+ let inet_addr =
+ inet_addr_of_string (Hostlong.to_address_string hl)
+ in
+ connect s (ADDR_INET (inet_addr, port));
Printf.printf "DCC chat established\n";
flush Pervasives.stdout;
chat_loop s; ()
--- /dev/null
+type t = int32
+
+let address_regexp =
+ let octet_regexp_string = "\([0-9][0-9]?[0-9]?\)" in
+ let address_regexp_string =
+ octet_regexp_string ^ "\." ^ octet_regexp_string ^ "\." ^
+ octet_regexp_string ^ "\." ^ octet_regexp_string
+ in
+ Str.regexp ("^" ^ address_regexp_string ^ "$")
+
+let of_int32 = function n -> n
+
+let to_int32 = function n -> n
+
+let of_string = Int32.of_string
+
+let to_string = Int32.to_string
+
+let of_address_string string =
+ let n = ref Int32.zero in
+ if (Str.string_match address_regexp string 0) then
+ for i = 1 to 4 do
+ let octet = Int32.of_string (Str.matched_group i string) in
+ n := Int32.logor !n (Int32.shift_left octet (8 * (3 - i)))
+ done
+ else
+ failwith "hostlong_of_string";
+ !n
+
+let to_address_string n =
+ let octets = ref [] in
+ let octet_mask = Int32.of_int 0xff in
+ for i = 0 to 3 do
+ let octet =
+ Int32.logand octet_mask (Int32.shift_right_logical n (i * 8))
+ in
+ octets := (Int32.to_string octet) :: !octets
+ done;
+ String.concat "." !octets
--- /dev/null
+type t
+
+val of_int32 : int32 -> t
+ (* Convert the given 32-bit integer (type [int32]) to a hostlong
+ (type [Hostlong.t]). *)
+val to_int32 : t -> int32
+ (* Convert the given hostlong (type [Hostlong.t]) to a 32-bit integer
+ (type [int32]). *)
+
+val of_string : string -> t
+ (* Convert the given string to a hostlong (type [Hostlong.t]). *)
+
+val to_string : t -> string
+ (* Return the string representation of its argument,
+ in signed decimal. *)
+
+val of_address_string : string -> t
+ (* Convert the given string to a hostlong (type [Hostlong.t]). *)
+
+val to_address_string : t -> string
+ (* Return the string representation of its argument,
+ in signed decimal. *)
+++ /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. *)