mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-30 03:40:34 +02:00
Merge commit 'b9b88351ea
'
Conflicts: libguile/deprecated.h test-suite/tests/00-socket.test
This commit is contained in:
commit
c8b7b0dad3
4 changed files with 4 additions and 143 deletions
|
@ -1,7 +1,7 @@
|
|||
@c -*-texinfo-*-
|
||||
@c This is part of the GNU Guile Reference Manual.
|
||||
@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2007,
|
||||
@c 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
|
||||
@c 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
|
||||
@c See the file guile.texi for copying conditions.
|
||||
|
||||
@node POSIX
|
||||
|
@ -3393,55 +3393,6 @@ file descriptor:
|
|||
any unflushed buffered port data is ignored.
|
||||
@end deffn
|
||||
|
||||
The following functions can be used to convert short and long integers
|
||||
between ``host'' and ``network'' order. Although the procedures above do
|
||||
this automatically for addresses, the conversion will still need to
|
||||
be done when sending or receiving encoded integer data from the network.
|
||||
|
||||
@deffn {Scheme Procedure} htons value
|
||||
@deffnx {C Function} scm_htons (value)
|
||||
Convert a 16 bit quantity from host to network byte ordering.
|
||||
@var{value} is packed into 2 bytes, which are then converted
|
||||
and returned as a new integer.
|
||||
@end deffn
|
||||
|
||||
@deffn {Scheme Procedure} ntohs value
|
||||
@deffnx {C Function} scm_ntohs (value)
|
||||
Convert a 16 bit quantity from network to host byte ordering.
|
||||
@var{value} is packed into 2 bytes, which are then converted
|
||||
and returned as a new integer.
|
||||
@end deffn
|
||||
|
||||
@deffn {Scheme Procedure} htonl value
|
||||
@deffnx {C Function} scm_htonl (value)
|
||||
Convert a 32 bit quantity from host to network byte ordering.
|
||||
@var{value} is packed into 4 bytes, which are then converted
|
||||
and returned as a new integer.
|
||||
@end deffn
|
||||
|
||||
@deffn {Scheme Procedure} ntohl value
|
||||
@deffnx {C Function} scm_ntohl (value)
|
||||
Convert a 32 bit quantity from network to host byte ordering.
|
||||
@var{value} is packed into 4 bytes, which are then converted
|
||||
and returned as a new integer.
|
||||
@end deffn
|
||||
|
||||
These procedures are inconvenient to use at present, but consider:
|
||||
|
||||
@example
|
||||
(define write-network-long
|
||||
(lambda (value port)
|
||||
(let ((v (make-uniform-vector 1 1 0)))
|
||||
(uniform-vector-set! v 0 (htonl value))
|
||||
(uniform-vector-write v port))))
|
||||
|
||||
(define read-network-long
|
||||
(lambda (port)
|
||||
(let ((v (make-uniform-vector 1 1 0)))
|
||||
(uniform-vector-read! v port)
|
||||
(ntohl (uniform-vector-ref v 0)))))
|
||||
@end example
|
||||
|
||||
|
||||
@node Internet Socket Examples
|
||||
@subsubsection Network Socket Examples
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/* Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
|
||||
* 2006, 2007, 2009, 2011, 2012, 2013 Free Software Foundation, Inc.
|
||||
* 2006, 2007, 2009, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
|
@ -92,50 +92,6 @@ typedef union
|
|||
|
||||
|
||||
|
||||
SCM_DEFINE (scm_htons, "htons", 1, 0, 0,
|
||||
(SCM value),
|
||||
"Convert a 16 bit quantity from host to network byte ordering.\n"
|
||||
"@var{value} is packed into 2 bytes, which are then converted\n"
|
||||
"and returned as a new integer.")
|
||||
#define FUNC_NAME s_scm_htons
|
||||
{
|
||||
return scm_from_ushort (htons (scm_to_ushort (value)));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_ntohs, "ntohs", 1, 0, 0,
|
||||
(SCM value),
|
||||
"Convert a 16 bit quantity from network to host byte ordering.\n"
|
||||
"@var{value} is packed into 2 bytes, which are then converted\n"
|
||||
"and returned as a new integer.")
|
||||
#define FUNC_NAME s_scm_ntohs
|
||||
{
|
||||
return scm_from_ushort (ntohs (scm_to_ushort (value)));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_htonl, "htonl", 1, 0, 0,
|
||||
(SCM value),
|
||||
"Convert a 32 bit quantity from host to network byte ordering.\n"
|
||||
"@var{value} is packed into 4 bytes, which are then converted\n"
|
||||
"and returned as a new integer.")
|
||||
#define FUNC_NAME s_scm_htonl
|
||||
{
|
||||
return scm_from_ulong (htonl (scm_to_uint32 (value)));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
SCM_DEFINE (scm_ntohl, "ntohl", 1, 0, 0,
|
||||
(SCM value),
|
||||
"Convert a 32 bit quantity from network to host byte ordering.\n"
|
||||
"@var{value} is packed into 4 bytes, which are then converted\n"
|
||||
"and returned as a new integer.")
|
||||
#define FUNC_NAME s_scm_ntohl
|
||||
{
|
||||
return scm_from_ulong (ntohl (scm_to_uint32 (value)));
|
||||
}
|
||||
#undef FUNC_NAME
|
||||
|
||||
#ifdef HAVE_INET_NETOF
|
||||
SCM_DEFINE (scm_inet_netof, "inet-netof", 1, 0, 0,
|
||||
(SCM address),
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#ifndef SCM_SOCKET_H
|
||||
#define SCM_SOCKET_H
|
||||
|
||||
/* Copyright (C) 1995,1996,1997,2000,2001, 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1995,1996,1997,2000,2001, 2004, 2005, 2006, 2008, 2014 Free Software Foundation, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License
|
||||
|
@ -27,10 +27,6 @@
|
|||
|
||||
|
||||
|
||||
SCM_API SCM scm_htons (SCM in);
|
||||
SCM_API SCM scm_ntohs (SCM in);
|
||||
SCM_API SCM scm_htonl (SCM in);
|
||||
SCM_API SCM scm_ntohl (SCM in);
|
||||
SCM_API SCM scm_inet_aton (SCM address);
|
||||
SCM_API SCM scm_inet_ntoa (SCM inetid);
|
||||
SCM_API SCM scm_inet_netof (SCM address);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
;;;; 00-socket.test --- test socket functions -*- scheme -*-
|
||||
;;;;
|
||||
;;;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010,
|
||||
;;;; 2011, 2012, 2013 Free Software Foundation, Inc.
|
||||
;;;; 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
|
||||
;;;;
|
||||
;;;; This library is free software; you can redistribute it and/or
|
||||
;;;; modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -27,27 +27,6 @@
|
|||
|
||||
|
||||
|
||||
;;;
|
||||
;;; htonl
|
||||
;;;
|
||||
|
||||
(if (defined? 'htonl)
|
||||
(with-test-prefix "htonl"
|
||||
|
||||
(pass-if "0" (eqv? 0 (htonl 0)))
|
||||
|
||||
(pass-if-exception "-1" exception:out-of-range
|
||||
(htonl -1))
|
||||
|
||||
;; prior to guile 1.6.9 and 1.8.1, systems with 64-bit longs didn't detect
|
||||
;; an overflow for values 2^32 <= x < 2^63
|
||||
(pass-if-exception "2^32" exception:out-of-range
|
||||
(htonl (ash 1 32)))
|
||||
|
||||
(pass-if-exception "2^1024" exception:out-of-range
|
||||
(htonl (ash 1 1024)))))
|
||||
|
||||
|
||||
;;;
|
||||
;;; inet-ntop
|
||||
;;;
|
||||
|
@ -154,27 +133,6 @@
|
|||
(and (= (sockaddr:fam sa) AF_UNIX)
|
||||
(string=? (sockaddr:path sa) "/tmp/unix-socket"))))))
|
||||
|
||||
;;;
|
||||
;;; ntohl
|
||||
;;;
|
||||
|
||||
(if (defined? 'ntohl)
|
||||
(with-test-prefix "ntohl"
|
||||
|
||||
(pass-if "0" (eqv? 0 (ntohl 0)))
|
||||
|
||||
(pass-if-exception "-1" exception:out-of-range
|
||||
(ntohl -1))
|
||||
|
||||
;; prior to guile 1.6.9 and 1.8.1, systems with 64-bit longs didn't detect
|
||||
;; an overflow for values 2^32 <= x < 2^63
|
||||
(pass-if-exception "2^32" exception:out-of-range
|
||||
(ntohl (ash 1 32)))
|
||||
|
||||
(pass-if-exception "2^1024" exception:out-of-range
|
||||
(ntohl (ash 1 1024)))))
|
||||
|
||||
|
||||
|
||||
;;;
|
||||
;;; AF_UNIX sockets and `make-socket-address'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue