mirror of
https://github.com/nmap/nmap.git
synced 2025-12-10 17:59:04 +00:00
Implementation of UNIX-domain sockets for Nsock.
Implementation of UNIX-domain sockets functionality for Nsock. Also some minor necessary changes to existing Nsock functions, to work properly with UNIX-domain sockets.
This commit is contained in:
@@ -76,6 +76,16 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
#include <sys/un.h>
|
||||||
|
|
||||||
|
#ifndef SUN_LEN
|
||||||
|
#include <string.h>
|
||||||
|
# define SUN_LEN(ptr) (sizeof(*(ptr)) - sizeof((ptr)->sun_path)) \
|
||||||
|
+ strlen ((ptr)->sun_path))
|
||||||
|
#endif
|
||||||
|
#endif /* HAVE_SYS_UN_H */
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@@ -423,6 +433,24 @@ typedef void (*nsock_ev_handler)(nsock_pool, nsock_event, void *);
|
|||||||
/* Initialize an unconnected UDP socket. */
|
/* Initialize an unconnected UDP socket. */
|
||||||
int nsock_setup_udp(nsock_pool nsp, nsock_iod ms_iod, int af);
|
int nsock_setup_udp(nsock_pool nsp, nsock_iod ms_iod, int af);
|
||||||
|
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
|
||||||
|
/* Request a UNIX domain sockets connection to the same system (by path to socket).
|
||||||
|
* This function connects to the socket of type SOCK_STREAM. ss should be a
|
||||||
|
* sockaddr_storage, sockaddr_un as appropriate (just like what you would pass to
|
||||||
|
* connect). sslen should be the sizeof the structure you are passing in. */
|
||||||
|
nsock_event_id nsock_connect_unixsock_stream(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handler handler,
|
||||||
|
int timeout_msecs, void *userdata, struct sockaddr *ss,
|
||||||
|
size_t sslen);
|
||||||
|
|
||||||
|
/* Request a UNIX domain sockets connection to the same system (by path to socket).
|
||||||
|
* This function connects to the socket of type SOCK_DGRAM. ss should be a
|
||||||
|
* sockaddr_storage, sockaddr_un as appropriate (just like what you would pass to
|
||||||
|
* connect). sslen should be the sizeof the structure you are passing in. */
|
||||||
|
nsock_event_id nsock_connect_unixsock_datagram(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handler handler,
|
||||||
|
void *userdata, struct sockaddr *ss, size_t sslen);
|
||||||
|
#endif /* HAVE_SYS_UN_H */
|
||||||
|
|
||||||
/* Request a TCP connection to another system (by IP address). The in_addr is
|
/* Request a TCP connection to another system (by IP address). The in_addr is
|
||||||
* normal network byte order, but the port number should be given in HOST BYTE
|
* normal network byte order, but the port number should be given in HOST BYTE
|
||||||
* ORDER. ss should be a sockaddr_storage, sockaddr_in6, or sockaddr_in as
|
* ORDER. ss should be a sockaddr_storage, sockaddr_in6, or sockaddr_in as
|
||||||
|
|||||||
@@ -75,6 +75,9 @@
|
|||||||
#undef HAVE_NET_BPF_H
|
#undef HAVE_NET_BPF_H
|
||||||
#undef HAVE_SYS_IOCTL_H
|
#undef HAVE_SYS_IOCTL_H
|
||||||
|
|
||||||
|
/* Define to 1 if you have the <sys/un.h> header file. */
|
||||||
|
#undef HAVE_SYS_UN_H
|
||||||
|
|
||||||
#undef HAVE_SSL_SET_TLSEXT_HOST_NAME
|
#undef HAVE_SSL_SET_TLSEXT_HOST_NAME
|
||||||
|
|
||||||
#undef HAVE_EPOLL
|
#undef HAVE_EPOLL
|
||||||
|
|||||||
2
nsock/src/configure
vendored
2
nsock/src/configure
vendored
@@ -4533,7 +4533,7 @@ $as_echo "#define STDC_HEADERS 1" >>confdefs.h
|
|||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for ac_header in net/bpf.h sys/ioctl.h
|
for ac_header in net/bpf.h sys/ioctl.h sys/un.h
|
||||||
do :
|
do :
|
||||||
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
|
||||||
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ AC_CHECK_FUNC(nanosleep, , AC_CHECK_LIB(posix4, nanosleep))
|
|||||||
|
|
||||||
dnl Checks for header files.
|
dnl Checks for header files.
|
||||||
AC_HEADER_STDC
|
AC_HEADER_STDC
|
||||||
AC_CHECK_HEADERS(net/bpf.h sys/ioctl.h)
|
AC_CHECK_HEADERS(net/bpf.h sys/ioctl.h sys/un.h)
|
||||||
|
|
||||||
# We test whether they specified openssl desires explicitly
|
# We test whether they specified openssl desires explicitly
|
||||||
use_openssl="yes"
|
use_openssl="yes"
|
||||||
|
|||||||
@@ -83,6 +83,9 @@
|
|||||||
#if HAVE_FCNTL_H
|
#if HAVE_FCNTL_H
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
#include <sys/un.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static int netutils_debugging = 0;
|
static int netutils_debugging = 0;
|
||||||
|
|
||||||
@@ -134,3 +137,35 @@ int maximize_fdlimit(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
/* Get the UNIX domain socket path or empty string if the address family != AF_UNIX. */
|
||||||
|
const char *get_unixsock_path(struct sockaddr_storage *addr)
|
||||||
|
{
|
||||||
|
if (!addr || addr->ss_family != AF_UNIX)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
struct sockaddr_un *su = (struct sockaddr_un *)addr;
|
||||||
|
return (const char *)su->sun_path;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Get the peer/host address string.
|
||||||
|
* In case we have support for UNIX domain sockets, function returns
|
||||||
|
* string containing path to UNIX socket if the address family is AF_UNIX,
|
||||||
|
* otherwise it returns string containing "<address>:<port>". */
|
||||||
|
char *get_hostaddr_string(struct sockaddr_storage *addr, size_t len, unsigned short port)
|
||||||
|
{
|
||||||
|
static char buffer[PEER_STR_LEN];
|
||||||
|
|
||||||
|
if (!addr)
|
||||||
|
return "";
|
||||||
|
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
if (addr->ss_family == AF_UNIX)
|
||||||
|
sprintf(buffer, "%s", get_unixsock_path(addr));
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
sprintf(buffer, "%s:%hu", inet_ntop_ez(addr, len), port);
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,17 +63,42 @@
|
|||||||
#include "nbase_config.h"
|
#include "nbase_config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_NETINET_IN_H
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include "nbase_winconfig.h"
|
#include "nbase_winconfig.h"
|
||||||
/* nbase_winunix.h somehow reason.h to get included */
|
/* nbase_winunix.h somehow reason.h to get included */
|
||||||
#include "nbase_winunix.h"
|
#include "nbase_winunix.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
#include <sys/un.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
#define PEER_STR_LEN sizeof(((struct sockaddr_un *) 0)->sun_path)
|
||||||
|
#else
|
||||||
|
#define PEER_STR_LEN sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255:xxxxx")
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Maximize the number of file descriptors (including sockets) allowed for this
|
/* Maximize the number of file descriptors (including sockets) allowed for this
|
||||||
* process and return that maximum value (note -- you better not actually open
|
* process and return that maximum value (note -- you better not actually open
|
||||||
* this many -- stdin, stdout, other files opened by libraries you use, etc. all
|
* this many -- stdin, stdout, other files opened by libraries you use, etc. all
|
||||||
* count toward this limit. Leave a little slack */
|
* count toward this limit. Leave a little slack */
|
||||||
int maximize_fdlimit(void);
|
int maximize_fdlimit(void);
|
||||||
|
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
/* Get the UNIX domain socket path or NULL if the socket family != AF_UNIX. */
|
||||||
|
const char *get_unixsock_path(struct sockaddr_storage *addr);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Get the peer/host address string.
|
||||||
|
* In case we have support for UNIX domain sockets, function returns
|
||||||
|
* string containing path to UNIX socket if the address family is AF_UNIX,
|
||||||
|
* otherwise it returns string containing "<address>:<port>". */
|
||||||
|
char *get_hostaddr_string(struct sockaddr_storage *addr, size_t len, unsigned short port);
|
||||||
|
|
||||||
#endif /* NETUTILS_H */
|
#endif /* NETUTILS_H */
|
||||||
|
|
||||||
|
|||||||
@@ -67,9 +67,9 @@
|
|||||||
* broadcast flag. Trying to change these functions after making this call will
|
* broadcast flag. Trying to change these functions after making this call will
|
||||||
* not have an effect. This function needs to be called before you try to read
|
* not have an effect. This function needs to be called before you try to read
|
||||||
* or write on the iod. */
|
* or write on the iod. */
|
||||||
static int nsock_make_socket(mspool *ms, msiod *iod, int family, int proto) {
|
static int nsock_make_socket(mspool *ms, msiod *iod, int family, int type, int proto) {
|
||||||
/* inheritable_socket is from nbase */
|
/* inheritable_socket is from nbase */
|
||||||
iod->sd = (int)inheritable_socket(family, (proto == IPPROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM, proto);
|
iod->sd = (int)inheritable_socket(family, type, proto);
|
||||||
if (iod->sd == -1) {
|
if (iod->sd == -1) {
|
||||||
perror("Socket troubles");
|
perror("Socket troubles");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -84,9 +84,17 @@ static int nsock_make_socket(mspool *ms, msiod *iod, int family, int proto) {
|
|||||||
|
|
||||||
setsockopt(iod->sd, SOL_SOCKET, SO_REUSEADDR, (const char *)&one, sizeof(one));
|
setsockopt(iod->sd, SOL_SOCKET, SO_REUSEADDR, (const char *)&one, sizeof(one));
|
||||||
if (bind(iod->sd, (struct sockaddr *)&iod->local, (int) iod->locallen) == -1) {
|
if (bind(iod->sd, (struct sockaddr *)&iod->local, (int) iod->locallen) == -1) {
|
||||||
if (ms->tracelevel > 0)
|
if (ms->tracelevel > 0) {
|
||||||
nsock_trace(ms, "Bind to %s failed (IOD #%li)",
|
const char *addrstr = NULL;
|
||||||
inet_ntop_ez(&iod->local, iod->locallen), iod->id);
|
#if HAVE_SYS_UN_H
|
||||||
|
if (iod->local.ss_family == AF_UNIX)
|
||||||
|
addrstr = get_unixsock_path(&iod->local);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
addrstr = inet_ntop_ez(&iod->local, iod->locallen);
|
||||||
|
|
||||||
|
nsock_trace(ms, "Bind to %s failed (IOD #%li)", addrstr, iod->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (iod->ipoptslen && family == AF_INET) {
|
if (iod->ipoptslen && family == AF_INET) {
|
||||||
@@ -122,7 +130,7 @@ int nsock_setup_udp(nsock_pool nsp, nsock_iod ms_iod, int af) {
|
|||||||
if (ms->tracelevel > 0)
|
if (ms->tracelevel > 0)
|
||||||
nsock_trace(ms, "UDP unconnected socket (IOD #%li)", nsi->id);
|
nsock_trace(ms, "UDP unconnected socket (IOD #%li)", nsi->id);
|
||||||
|
|
||||||
if (nsock_make_socket(ms, nsi, af, IPPROTO_UDP) == -1)
|
if (nsock_make_socket(ms, nsi, af, SOCK_DGRAM, IPPROTO_UDP) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return nsi->sd;
|
return nsi->sd;
|
||||||
@@ -130,7 +138,7 @@ int nsock_setup_udp(nsock_pool nsp, nsock_iod ms_iod, int af) {
|
|||||||
|
|
||||||
/* This does the actual logistics of requesting a TCP connection. It is shared
|
/* This does the actual logistics of requesting a TCP connection. It is shared
|
||||||
* by nsock_connect_tcp and nsock_connect_ssl */
|
* by nsock_connect_tcp and nsock_connect_ssl */
|
||||||
void nsock_connect_internal(mspool *ms, msevent *nse, int proto, struct sockaddr_storage *ss, size_t sslen,
|
void nsock_connect_internal(mspool *ms, msevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen,
|
||||||
unsigned short port) {
|
unsigned short port) {
|
||||||
|
|
||||||
struct sockaddr_in *sin = (struct sockaddr_in *)ss;
|
struct sockaddr_in *sin = (struct sockaddr_in *)ss;
|
||||||
@@ -140,15 +148,19 @@ void nsock_connect_internal(mspool *ms, msevent *nse, int proto, struct sockaddr
|
|||||||
msiod *iod = nse->iod;
|
msiod *iod = nse->iod;
|
||||||
|
|
||||||
/* Now it is time to actually attempt the connection */
|
/* Now it is time to actually attempt the connection */
|
||||||
if (nsock_make_socket(ms, iod, ss->ss_family, proto) == -1) {
|
if (nsock_make_socket(ms, iod, ss->ss_family, type, proto) == -1) {
|
||||||
nse->event_done = 1;
|
nse->event_done = 1;
|
||||||
nse->status = NSE_STATUS_ERROR;
|
nse->status = NSE_STATUS_ERROR;
|
||||||
nse->errnum = socket_errno();
|
nse->errnum = socket_errno();
|
||||||
} else {
|
} else {
|
||||||
if (sin->sin_family == AF_INET) {
|
if (ss->ss_family == AF_INET) {
|
||||||
sin->sin_port = htons(port);
|
sin->sin_port = htons(port);
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
} else if (ss->ss_family == AF_INET6) {
|
||||||
|
#else
|
||||||
} else {
|
} else {
|
||||||
assert(sin->sin_family == AF_INET6);
|
#endif
|
||||||
|
assert(ss->ss_family == AF_INET6);
|
||||||
#if HAVE_IPV6
|
#if HAVE_IPV6
|
||||||
sin6->sin6_port = htons(port);
|
sin6->sin6_port = htons(port);
|
||||||
#else
|
#else
|
||||||
@@ -174,6 +186,62 @@ void nsock_connect_internal(mspool *ms, msevent *nse, int proto, struct sockaddr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
|
||||||
|
/* Request a UNIX domain sockets connection to the same system (by path to socket).
|
||||||
|
* This function connects to the socket of type SOCK_STREAM. ss should be a
|
||||||
|
* sockaddr_storage, sockaddr_un as appropriate (just like what you would pass to
|
||||||
|
* connect). sslen should be the sizeof the structure you are passing in. */
|
||||||
|
nsock_event_id nsock_connect_unixsock_stream(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handler handler, int timeout_msecs,
|
||||||
|
void *userdata, struct sockaddr *saddr, size_t sslen) {
|
||||||
|
msiod *nsi = (msiod *)nsiod;
|
||||||
|
mspool *ms = (mspool *)nsp;
|
||||||
|
msevent *nse;
|
||||||
|
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||||
|
|
||||||
|
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||||
|
|
||||||
|
nse = msevent_new(ms, NSE_TYPE_CONNECT, nsi, timeout_msecs, handler, userdata);
|
||||||
|
assert(nse);
|
||||||
|
|
||||||
|
if (ms->tracelevel > 0)
|
||||||
|
nsock_trace(ms, "UNIX domain socket (STREAM) connection requested to %s (IOD #%li) EID %li",
|
||||||
|
get_unixsock_path(ss), nsi->id, nse->id);
|
||||||
|
|
||||||
|
nsock_connect_internal(ms, nse, SOCK_STREAM, 0, ss, sslen, 0);
|
||||||
|
nsp_add_event(ms, nse);
|
||||||
|
|
||||||
|
return nse->id;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Request a UNIX domain sockets connection to the same system (by path to socket).
|
||||||
|
* This function connects to the socket of type SOCK_DGRAM. ss should be a
|
||||||
|
* sockaddr_storage, sockaddr_un as appropriate (just like what you would pass to
|
||||||
|
* connect). sslen should be the sizeof the structure you are passing in. */
|
||||||
|
nsock_event_id nsock_connect_unixsock_datagram(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handler handler,
|
||||||
|
void *userdata, struct sockaddr *saddr, size_t sslen) {
|
||||||
|
msiod *nsi = (msiod *)nsiod;
|
||||||
|
mspool *ms = (mspool *)nsp;
|
||||||
|
msevent *nse;
|
||||||
|
struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;
|
||||||
|
|
||||||
|
assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);
|
||||||
|
|
||||||
|
nse = msevent_new(ms, NSE_TYPE_CONNECT, nsi, -1, handler, userdata);
|
||||||
|
assert(nse);
|
||||||
|
|
||||||
|
if (ms->tracelevel > 0)
|
||||||
|
nsock_trace(ms, "UNIX domain socket (DGRAM) connection requested to %s (IOD #%li) EID %li",
|
||||||
|
get_unixsock_path(ss), nsi->id, nse->id);
|
||||||
|
|
||||||
|
nsock_connect_internal(ms, nse, SOCK_DGRAM, 0, ss, sslen, 0);
|
||||||
|
nsp_add_event(ms, nse);
|
||||||
|
|
||||||
|
return nse->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_SYS_UN_H */
|
||||||
|
|
||||||
/* Request a TCP connection to another system (by IP address). The in_addr is
|
/* Request a TCP connection to another system (by IP address). The in_addr is
|
||||||
* normal network byte order, but the port number should be given in HOST BYTE
|
* normal network byte order, but the port number should be given in HOST BYTE
|
||||||
@@ -198,7 +266,7 @@ nsock_event_id nsock_connect_tcp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_hand
|
|||||||
inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
|
inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
|
||||||
|
|
||||||
/* Do the actual connect() */
|
/* Do the actual connect() */
|
||||||
nsock_connect_internal(ms, nse, IPPROTO_TCP, ss, sslen, port);
|
nsock_connect_internal(ms, nse, SOCK_STREAM, IPPROTO_TCP, ss, sslen, port);
|
||||||
nsp_add_event(ms, nse);
|
nsp_add_event(ms, nse);
|
||||||
|
|
||||||
return nse->id;
|
return nse->id;
|
||||||
@@ -227,7 +295,7 @@ nsock_event_id nsock_connect_sctp(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_han
|
|||||||
inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
|
inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
|
||||||
|
|
||||||
/* Do the actual connect() */
|
/* Do the actual connect() */
|
||||||
nsock_connect_internal(ms, nse, IPPROTO_SCTP, ss, sslen, port);
|
nsock_connect_internal(ms, nse, SOCK_STREAM, IPPROTO_SCTP, ss, sslen, port);
|
||||||
nsp_add_event(ms, nse);
|
nsp_add_event(ms, nse);
|
||||||
|
|
||||||
return nse->id;
|
return nse->id;
|
||||||
@@ -269,7 +337,7 @@ nsock_event_id nsock_connect_ssl(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
|
|||||||
inet_ntop_ez(ss, sslen), port, (proto == IPPROTO_TCP ? "tcp" : "sctp"), nsi->id, nse->id);
|
inet_ntop_ez(ss, sslen), port, (proto == IPPROTO_TCP ? "tcp" : "sctp"), nsi->id, nse->id);
|
||||||
|
|
||||||
/* Do the actual connect() */
|
/* Do the actual connect() */
|
||||||
nsock_connect_internal(ms, nse, proto, ss, sslen, port);
|
nsock_connect_internal(ms, nse, SOCK_STREAM, proto, ss, sslen, port);
|
||||||
nsp_add_event(ms, nse);
|
nsp_add_event(ms, nse);
|
||||||
|
|
||||||
return nse->id;
|
return nse->id;
|
||||||
@@ -342,7 +410,7 @@ nsock_event_id nsock_connect_udp(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
|
|||||||
if (ms->tracelevel > 0)
|
if (ms->tracelevel > 0)
|
||||||
nsock_trace(ms, "UDP connection requested to %s:%hu (IOD #%li) EID %li", inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
|
nsock_trace(ms, "UDP connection requested to %s:%hu (IOD #%li) EID %li", inet_ntop_ez(ss, sslen), port, nsi->id, nse->id);
|
||||||
|
|
||||||
nsock_connect_internal(ms, nse, IPPROTO_UDP, ss, sslen, port);
|
nsock_connect_internal(ms, nse, SOCK_DGRAM, IPPROTO_UDP, ss, sslen, port);
|
||||||
nsp_add_event(ms, nse);
|
nsp_add_event(ms, nse);
|
||||||
|
|
||||||
return nse->id;
|
return nse->id;
|
||||||
@@ -378,7 +446,7 @@ int nsi_getlastcommunicationinfo(nsock_iod ms_iod, int *protocol, int *af, struc
|
|||||||
if (*protocol == -1) res = 0;
|
if (*protocol == -1) res = 0;
|
||||||
}
|
}
|
||||||
if (af) {
|
if (af) {
|
||||||
*af = ((struct sockaddr_in *)&nsi->peer)->sin_family;
|
*af = nsi->peer.ss_family;
|
||||||
}
|
}
|
||||||
if (local) {
|
if (local) {
|
||||||
if (nsi->sd >= 0) {
|
if (nsi->sd >= 0) {
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ void handle_connect_result(mspool *ms, msevent *nse, enum nse_status status) {
|
|||||||
saved_ev = iod->watched_events;
|
saved_ev = iod->watched_events;
|
||||||
ms->engine->iod_unregister(ms, iod);
|
ms->engine->iod_unregister(ms, iod);
|
||||||
close(iod->sd);
|
close(iod->sd);
|
||||||
nsock_connect_internal(ms, nse, iod->lastproto, &iod->peer, iod->peerlen, nsi_peerport(iod));
|
nsock_connect_internal(ms, nse, SOCK_STREAM, iod->lastproto, &iod->peer, iod->peerlen, nsi_peerport(iod));
|
||||||
ms->engine->iod_register(ms, iod, saved_ev);
|
ms->engine->iod_register(ms, iod, saved_ev);
|
||||||
|
|
||||||
SSL_clear(iod->ssl);
|
SSL_clear(iod->ssl);
|
||||||
@@ -1272,18 +1272,19 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) {
|
|||||||
switch(nse->type) {
|
switch(nse->type) {
|
||||||
case NSE_TYPE_CONNECT:
|
case NSE_TYPE_CONNECT:
|
||||||
case NSE_TYPE_CONNECT_SSL:
|
case NSE_TYPE_CONNECT_SSL:
|
||||||
nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s:%d]",
|
nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s]",
|
||||||
nse_type2str(nse->type), nse_status2str(nse->status), errstr,
|
nse_type2str(nse->type), nse_status2str(nse->status),
|
||||||
nse->id, inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi));
|
errstr, nse->id, get_hostaddr_string(&nsi->peer,
|
||||||
|
nsi->peerlen, (unsigned short)nsi_peerport(nsi)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSE_TYPE_READ:
|
case NSE_TYPE_READ:
|
||||||
if (nse->status != NSE_STATUS_SUCCESS) {
|
if (nse->status != NSE_STATUS_SUCCESS) {
|
||||||
if (nsi->peerlen > 0) {
|
if (nsi->peerlen > 0) {
|
||||||
nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s:%d]",
|
nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s]",
|
||||||
nse_type2str(nse->type), nse_status2str(nse->status),
|
nse_type2str(nse->type), nse_status2str(nse->status),
|
||||||
errstr, nse->id, inet_ntop_ez(&nsi->peer, nsi->peerlen),
|
errstr, nse->id, get_hostaddr_string(&nsi->peer,
|
||||||
nsi_peerport(nsi));
|
nsi->peerlen, (unsigned short)nsi_peerport(nsi)));
|
||||||
} else {
|
} else {
|
||||||
nsock_trace(ms, "Callback: %s %s %sfor EID %li (peer unspecified)",
|
nsock_trace(ms, "Callback: %s %s %sfor EID %li (peer unspecified)",
|
||||||
nse_type2str(nse->type), nse_status2str(nse->status),
|
nse_type2str(nse->type), nse_status2str(nse->status),
|
||||||
@@ -1301,11 +1302,11 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (nsi->peerlen > 0) {
|
if (nsi->peerlen > 0) {
|
||||||
nsock_trace(ms, "Callback: %s %s for EID %li [%s:%d] %s(%d bytes)%s",
|
nsock_trace(ms, "Callback: %s %s for EID %li [%s] %s(%d bytes)%s",
|
||||||
nse_type2str(nse->type), nse_status2str(nse->status),
|
nse_type2str(nse->type), nse_status2str(nse->status),
|
||||||
nse->id, inet_ntop_ez(&nsi->peer, nsi->peerlen),
|
nse->id, get_hostaddr_string(&nsi->peer, nsi->peerlen,
|
||||||
nsi_peerport(nsi), nse_eof(nse)? "[EOF]" : "", strlength,
|
(unsigned short)nsi_peerport(nsi)),
|
||||||
displaystr);
|
nse_eof(nse)? "[EOF]" : "", strlength, displaystr);
|
||||||
} else {
|
} else {
|
||||||
nsock_trace(ms, "Callback %s %s for EID %li (peer unspecified) %s(%d bytes)%s",
|
nsock_trace(ms, "Callback %s %s for EID %li (peer unspecified) %s(%d bytes)%s",
|
||||||
nse_type2str(nse->type), nse_status2str(nse->status),
|
nse_type2str(nse->type), nse_status2str(nse->status),
|
||||||
@@ -1315,10 +1316,10 @@ void nsock_trace_handler_callback(mspool *ms, msevent *nse) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NSE_TYPE_WRITE:
|
case NSE_TYPE_WRITE:
|
||||||
nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s:%d]",
|
nsock_trace(ms, "Callback: %s %s %sfor EID %li [%s]",
|
||||||
nse_type2str(nse->type), nse_status2str(nse->status), errstr,
|
nse_type2str(nse->type), nse_status2str(nse->status), errstr,
|
||||||
nse->id, inet_ntop_ez(&nsi->peer, nsi->peerlen),
|
nse->id, get_hostaddr_string(&nsi->peer, nsi->peerlen,
|
||||||
nsi_peerport(nsi));
|
(unsigned short)nsi_peerport(nsi)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSE_TYPE_TIMER:
|
case NSE_TYPE_TIMER:
|
||||||
|
|||||||
@@ -97,6 +97,9 @@
|
|||||||
#if HAVE_STRINGS_H
|
#if HAVE_STRINGS_H
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#endif
|
#endif
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
#include <sys/un.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef IPPROTO_SCTP
|
#ifndef IPPROTO_SCTP
|
||||||
#define IPPROTO_SCTP 132
|
#define IPPROTO_SCTP 132
|
||||||
@@ -255,7 +258,8 @@ typedef struct {
|
|||||||
struct sockaddr_storage local;
|
struct sockaddr_storage local;
|
||||||
|
|
||||||
/* The length of peer/local actually used (sizeof(sockaddr_in) or
|
/* The length of peer/local actually used (sizeof(sockaddr_in) or
|
||||||
* sizeof(sockaddr_in6), or 0 if peer/local has not been filled in */
|
* sizeof(sockaddr_in6), SUN_LEN(sockaddr_un), or 0 if peer/local
|
||||||
|
* has not been filled in */
|
||||||
size_t locallen;
|
size_t locallen;
|
||||||
size_t peerlen;
|
size_t peerlen;
|
||||||
|
|
||||||
@@ -424,7 +428,7 @@ void msevent_delete(mspool *nsp, msevent *nse);
|
|||||||
* etc. */
|
* etc. */
|
||||||
void nsp_add_event(mspool *nsp, msevent *nse);
|
void nsp_add_event(mspool *nsp, msevent *nse);
|
||||||
|
|
||||||
void nsock_connect_internal(mspool *ms, msevent *nse, int proto, struct sockaddr_storage *ss, size_t sslen, unsigned short port);
|
void nsock_connect_internal(mspool *ms, msevent *nse, int type, int proto, struct sockaddr_storage *ss, size_t sslen, unsigned short port);
|
||||||
|
|
||||||
/* Comments on using the following handle_*_result functions are available in nsock_core.c */
|
/* Comments on using the following handle_*_result functions are available in nsock_core.c */
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,9 @@ nsock_event_id nsock_readlines(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handle
|
|||||||
|
|
||||||
if (ms->tracelevel > 0) {
|
if (ms->tracelevel > 0) {
|
||||||
if (nsi->peerlen > 0)
|
if (nsi->peerlen > 0)
|
||||||
nsock_trace(ms, "Read request for %d lines from IOD #%li [%s:%d] EID %li",
|
nsock_trace(ms, "Read request for %d lines from IOD #%li [%s] EID %li",
|
||||||
nlines, nsi->id, inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), nse->id);
|
nlines, nsi->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)),
|
||||||
|
nse->id);
|
||||||
else
|
else
|
||||||
nsock_trace(ms, "Read request for %d lines from IOD #%li (peer unspecified) EID %li",
|
nsock_trace(ms, "Read request for %d lines from IOD #%li (peer unspecified) EID %li",
|
||||||
nlines, nsi->id, nse->id);
|
nlines, nsi->id, nse->id);
|
||||||
@@ -102,8 +103,9 @@ nsock_event_id nsock_readbytes(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handle
|
|||||||
|
|
||||||
if (ms->tracelevel > 0) {
|
if (ms->tracelevel > 0) {
|
||||||
if (nsi->peerlen > 0)
|
if (nsi->peerlen > 0)
|
||||||
nsock_trace(ms, "Read request for %d bytes from IOD #%li [%s:%d] EID %li",
|
nsock_trace(ms, "Read request for %d bytes from IOD #%li [%s] EID %li",
|
||||||
nbytes, nsi->id, inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), nse->id);
|
nbytes, nsi->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)),
|
||||||
|
nse->id);
|
||||||
else
|
else
|
||||||
nsock_trace(ms, "Read request for %d bytes from IOD #%li (peer unspecified) EID %li",
|
nsock_trace(ms, "Read request for %d bytes from IOD #%li (peer unspecified) EID %li",
|
||||||
nbytes, nsi->id, nse->id);
|
nbytes, nsi->id, nse->id);
|
||||||
@@ -130,8 +132,9 @@ nsock_event_id nsock_read(nsock_pool nsp, nsock_iod ms_iod, nsock_ev_handler han
|
|||||||
|
|
||||||
if (ms->tracelevel > 0) {
|
if (ms->tracelevel > 0) {
|
||||||
if (nsi->peerlen > 0)
|
if (nsi->peerlen > 0)
|
||||||
nsock_trace(ms, "Read request from IOD #%li [%s:%d] (timeout: %dms) EID %li",
|
nsock_trace(ms, "Read request from IOD #%li [%s] (timeout: %dms) EID %li",
|
||||||
nsi->id, inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), timeout_msecs, nse->id);
|
nsi->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)),
|
||||||
|
timeout_msecs, nse->id);
|
||||||
else
|
else
|
||||||
nsock_trace(ms, "Read request from IOD #%li (peer unspecified) (timeout: %dms) EID %li",
|
nsock_trace(ms, "Read request from IOD #%li (peer unspecified) (timeout: %dms) EID %li",
|
||||||
nsi->id, timeout_msecs, nse->id);
|
nsi->id, timeout_msecs, nse->id);
|
||||||
|
|||||||
@@ -76,10 +76,14 @@ nsock_event_id nsock_sendto(nsock_pool ms_pool, nsock_iod ms_iod, nsock_ev_handl
|
|||||||
nse = msevent_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
|
nse = msevent_new(nsp, NSE_TYPE_WRITE, nsi, timeout_msecs, handler, userdata);
|
||||||
assert(nse);
|
assert(nse);
|
||||||
|
|
||||||
if (sin->sin_family == AF_INET) {
|
if (saddr->sa_family == AF_INET) {
|
||||||
sin->sin_port = htons(port);
|
sin->sin_port = htons(port);
|
||||||
|
#if HAVE_SYS_UN_H
|
||||||
|
} else if (saddr->sa_family == AF_INET6) {
|
||||||
|
#else
|
||||||
} else {
|
} else {
|
||||||
assert(sin->sin_family == AF_INET6);
|
#endif
|
||||||
|
assert(saddr->sa_family == AF_INET6);
|
||||||
#if HAVE_IPV6
|
#if HAVE_IPV6
|
||||||
sin6->sin6_port = htons(port);
|
sin6->sin6_port = htons(port);
|
||||||
#else
|
#else
|
||||||
@@ -107,9 +111,9 @@ nsock_event_id nsock_sendto(nsock_pool ms_pool, nsock_iod ms_iod, nsock_ev_handl
|
|||||||
} else {
|
} else {
|
||||||
displaystr[0] = '\0';
|
displaystr[0] = '\0';
|
||||||
}
|
}
|
||||||
nsock_trace(nsp, "Sendto request for %d bytes to IOD #%li EID %li [%s:%hu]%s",
|
nsock_trace(nsp, "Sendto request for %d bytes to IOD #%li EID %li [%s]%s",
|
||||||
datalen, nsi->id, nse->id,
|
datalen, nsi->id, nse->id,
|
||||||
inet_ntop_ez(&nse->writeinfo.dest, nse->writeinfo.destlen), port,
|
get_hostaddr_string(&nse->writeinfo.dest, nse->writeinfo.destlen, port),
|
||||||
displaystr);
|
displaystr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,8 +151,9 @@ nsock_event_id nsock_write(nsock_pool ms_pool, nsock_iod ms_iod,
|
|||||||
replacenonprintable(displaystr + 2, datalen, '.');
|
replacenonprintable(displaystr + 2, datalen, '.');
|
||||||
} else displaystr[0] = '\0';
|
} else displaystr[0] = '\0';
|
||||||
if (nsi->peerlen > 0)
|
if (nsi->peerlen > 0)
|
||||||
nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li [%s:%d]%s", datalen, nsi->id,
|
nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s", datalen, nsi->id,
|
||||||
nse->id, inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), displaystr);
|
nse->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)),
|
||||||
|
displaystr);
|
||||||
else
|
else
|
||||||
nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s", datalen,
|
nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s", datalen,
|
||||||
nsi->id, nse->id, displaystr);
|
nsi->id, nse->id, displaystr);
|
||||||
@@ -220,8 +225,9 @@ nsock_event_id nsock_printf(nsock_pool ms_pool, nsock_iod ms_iod,
|
|||||||
displaystr[0] = '\0';
|
displaystr[0] = '\0';
|
||||||
}
|
}
|
||||||
if (nsi->peerlen > 0)
|
if (nsi->peerlen > 0)
|
||||||
nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li [%s:%d]%s", strlength, nsi->id,
|
nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li [%s]%s", strlength, nsi->id,
|
||||||
nse->id, inet_ntop_ez(&nsi->peer, nsi->peerlen), nsi_peerport(nsi), displaystr);
|
nse->id, get_hostaddr_string(&nsi->peer, nsi->peerlen, (unsigned short)nsi_peerport(nsi)),
|
||||||
|
displaystr);
|
||||||
else
|
else
|
||||||
nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s", strlength,
|
nsock_trace(nsp, "Write request for %d bytes to IOD #%li EID %li (peer unspecified)%s", strlength,
|
||||||
nsi->id, nse->id, displaystr);
|
nsi->id, nse->id, displaystr);
|
||||||
|
|||||||
Reference in New Issue
Block a user