/* Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005,
- * 2006, 2007, 2009, 2011 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
#endif
#include <errno.h>
+#include <verify.h>
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#ifdef HAVE_UNIX_DOMAIN_SOCKETS
+#include <sys/un.h>
+#endif
+#include <netinet/in.h>
+#include <netdb.h>
+#include <arpa/inet.h>
+
#include <gmp.h>
#include "libguile/_scm.h"
# include "libguile/deprecation.h"
#endif
-#ifdef __MINGW32__
-#include "win32-socket.h"
-#include <netdb.h>
-#endif
-#ifdef HAVE_STDINT_H
-#include <stdint.h>
-#endif
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <sys/types.h>
-#ifdef HAVE_WINSOCK2_H
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#ifdef HAVE_UNIX_DOMAIN_SOCKETS
-#include <sys/un.h>
-#endif
-#include <netinet/in.h>
-#include <netdb.h>
-#include <arpa/inet.h>
-#endif
#if defined (HAVE_UNIX_DOMAIN_SOCKETS) && !defined (SUN_LEN)
-#define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
+#define SUN_LEN(ptr) (offsetof (struct sockaddr_un, sun_path) \
+ strlen ((ptr)->sun_path))
#endif
\f
-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),
"@defvarx SO_OOBINLINE\n"
"@defvarx SO_NO_CHECK\n"
"@defvarx SO_PRIORITY\n"
+ "@defvarx SO_REUSEPORT\n"
"The value returned is an integer.\n"
"@end defvar\n"
"\n"
"@defvar SO_LINGER\n"
- "The @var{value} returned is a pair of integers\n"
- "@code{(@var{ENABLE} . @var{TIMEOUT})}. On old systems without\n"
+ "The value returned is a pair of integers\n"
+ "@code{(@var{enable} . @var{timeout})}. On old systems without\n"
"timeout support (ie.@: without @code{struct linger}), only\n"
- "@var{ENABLE} has an effect but the value in Guile is always a\n"
+ "@var{enable} has an effect but the value in Guile is always a\n"
"pair.\n"
"@end defvar")
#define FUNC_NAME s_scm_getsockopt
"@defvarx SO_OOBINLINE\n"
"@defvarx SO_NO_CHECK\n"
"@defvarx SO_PRIORITY\n"
+ "@defvarx SO_REUSEPORT\n"
"@var{value} is an integer.\n"
"@end defvar\n"
"\n"
}
#undef FUNC_NAME
+/* Our documentation hard-codes this mapping, so make sure it holds. */
+verify (SHUT_RD == 0);
+verify (SHUT_WR == 1);
+verify (SHUT_RDWR == 2);
+
SCM_DEFINE (scm_shutdown, "shutdown", 2, 0, 0,
(SCM sock, SCM how),
"Sockets can be closed simply by using @code{close-port}. The\n"
size_t path_len = 0;
path = SCM_SIMPLE_VECTOR_REF (address, 1);
- if ((!scm_is_string (path)) && (path != SCM_BOOL_F))
+ if (!scm_is_string (path) && !scm_is_false (path))
scm_misc_error (FUNC_NAME, "invalid unix address "
"path: ~A", scm_list_1 (path));
else
{
struct sockaddr_un c_unix;
- if (path == SCM_BOOL_F)
+ if (scm_is_false (path))
path_len = 0;
else
path_len = scm_c_string_length (path);
sock = SCM_COERCE_OUTPORT (sock);
SCM_VALIDATE_OPFPORT (1, sock);
fd = SCM_FPORT_FDES (sock);
- newfd = accept (fd, (struct sockaddr *) &addr, &addr_size);
+ SCM_SYSCALL (newfd = accept (fd, (struct sockaddr *) &addr, &addr_size));
if (newfd == -1)
SCM_SYSERROR;
newsock = SCM_SOCK_FD_TO_PORT (newfd);
(SCM sock, SCM message, SCM fam_or_sockaddr, SCM address, SCM args_and_flags),
"Transmit bytevector @var{message} on socket port\n"
"@var{sock}. The\n"
- "destination address is specified using the @var{fam},\n"
+ "destination address is specified using the @var{fam_or_sockaddr},\n"
"@var{address} and\n"
"@var{args_and_flags} arguments, or just a socket address object "
"returned by @code{make-socket-address}, in a similar way to the\n"
#ifdef AF_UNSPEC
scm_c_define ("AF_UNSPEC", scm_from_int (AF_UNSPEC));
#endif
-#ifdef AF_UNIX
+#if defined HAVE_UNIX_DOMAIN_SOCKETS && defined AF_UNIX
scm_c_define ("AF_UNIX", scm_from_int (AF_UNIX));
#endif
#ifdef AF_INET
#ifdef SO_LINGER
scm_c_define ("SO_LINGER", scm_from_int (SO_LINGER));
#endif
+#ifdef SO_REUSEPORT /* new in Linux 3.9 */
+ scm_c_define ("SO_REUSEPORT", scm_from_int (SO_REUSEPORT));
+#endif
/* recv/send options. */
#ifdef MSG_DONTWAIT
scm_c_define ("MSG_DONTROUTE", scm_from_int (MSG_DONTROUTE));
#endif
-#ifdef __MINGW32__
- scm_i_init_socket_Win32 ();
-#endif
-
#ifdef IP_ADD_MEMBERSHIP
scm_c_define ("IP_ADD_MEMBERSHIP", scm_from_int (IP_ADD_MEMBERSHIP));
scm_c_define ("IP_DROP_MEMBERSHIP", scm_from_int (IP_DROP_MEMBERSHIP));