mirror of
https://github.com/nmap/nmap.git
synced 2025-12-14 11:49:01 +00:00
Consistently renamed nsi_XXX calls into nsock_iod_XXX
This is part of the effort to make nsock expose only nsock_ prefixed symbols and simplify the API.
This commit is contained in:
@@ -180,7 +180,7 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) {
|
||||
|
||||
/* If there was a previous nsock pool, delete it */
|
||||
if (this->pcap_nsi) {
|
||||
nsi_delete(this->pcap_nsi, NSOCK_PENDING_SILENT);
|
||||
nsock_iod_delete(this->pcap_nsi, NSOCK_PENDING_SILENT);
|
||||
}
|
||||
if (this->nsock_init) {
|
||||
nsock_event_cancel(this->nsp, this->pcap_ev_id, 0);
|
||||
@@ -203,7 +203,7 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) {
|
||||
nsock_pool_set_broadcast(this->nsp, 1);
|
||||
|
||||
/* Allocate an NSI for packet capture */
|
||||
this->pcap_nsi = nsi_new(this->nsp, NULL);
|
||||
this->pcap_nsi = nsock_iod_new(this->nsp, NULL);
|
||||
this->first_pcap_scheduled = false;
|
||||
|
||||
/* Flag it as already initialized so we free this nsp next time */
|
||||
|
||||
@@ -248,20 +248,20 @@ static void connect_report(nsock_iod nsi)
|
||||
union sockaddr_u peer;
|
||||
zmem(&peer, sizeof(peer.storage));
|
||||
|
||||
nsi_getlastcommunicationinfo(nsi, NULL, NULL, NULL,
|
||||
&peer.sockaddr, sizeof(peer.storage));
|
||||
|
||||
nsock_iod_get_communication_info(nsi, NULL, NULL, NULL, &peer.sockaddr,
|
||||
sizeof(peer.storage));
|
||||
if (o.verbose) {
|
||||
#ifdef HAVE_OPENSSL
|
||||
if (nsi_checkssl(nsi)) {
|
||||
if (nsock_iod_check_ssl(nsi)) {
|
||||
X509 *cert;
|
||||
X509_NAME *subject;
|
||||
char digest_buf[SHA1_STRING_LENGTH + 1];
|
||||
char *fp;
|
||||
|
||||
loguser("SSL connection to %s:%hu.", inet_socktop(&peer), nsi_peerport(nsi));
|
||||
loguser("SSL connection to %s:%hu.", inet_socktop(&peer),
|
||||
nsock_iod_get_peerport(nsi));
|
||||
|
||||
cert = SSL_get_peer_certificate((SSL *) nsi_getssl(nsi));
|
||||
cert = SSL_get_peer_certificate((SSL *)nsock_iod_get_ssl(nsi));
|
||||
ncat_assert(cert != NULL);
|
||||
|
||||
subject = X509_get_subject_name(cert);
|
||||
@@ -285,7 +285,8 @@ static void connect_report(nsock_iod nsi)
|
||||
loguser("Connected to %s.\n", peer.un.sun_path);
|
||||
else
|
||||
#endif
|
||||
loguser("Connected to %s:%hu.\n", inet_socktop(&peer), nsi_peerport(nsi));
|
||||
loguser("Connected to %s:%hu.\n", inet_socktop(&peer),
|
||||
nsock_iod_get_peerport(nsi));
|
||||
}
|
||||
#else
|
||||
#if HAVE_SYS_UN_H
|
||||
@@ -293,7 +294,8 @@ static void connect_report(nsock_iod nsi)
|
||||
loguser("Connected to %s.\n", peer.un.sun_path);
|
||||
else
|
||||
#endif
|
||||
loguser("Connected to %s:%hu.\n", inet_socktop(&peer), nsi_peerport(nsi));
|
||||
loguser("Connected to %s:%hu.\n", inet_socktop(&peer),
|
||||
nsock_iod_get_peerport(nsi));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -894,11 +896,11 @@ int ncat_connect(void)
|
||||
|
||||
if (!o.proxytype) {
|
||||
/* A non-proxy connection. Create an iod for a new socket. */
|
||||
cs.sock_nsi = nsi_new(mypool, NULL);
|
||||
cs.sock_nsi = nsock_iod_new(mypool, NULL);
|
||||
if (cs.sock_nsi == NULL)
|
||||
bye("Failed to create nsock_iod.");
|
||||
|
||||
if (nsi_set_hostname(cs.sock_nsi, o.target) == -1)
|
||||
if (nsock_iod_set_hostname(cs.sock_nsi, o.target) == -1)
|
||||
bye("Failed to set hostname on iod.");
|
||||
|
||||
#if HAVE_SYS_UN_H
|
||||
@@ -915,7 +917,8 @@ int ncat_connect(void)
|
||||
strncpy(srcaddr.un.sun_path, tmp_name, sizeof(srcaddr.un.sun_path));
|
||||
free (tmp_name);
|
||||
}
|
||||
nsi_set_localaddr(cs.sock_nsi, &srcaddr.storage, SUN_LEN((struct sockaddr_un *)&srcaddr.storage));
|
||||
nsock_iod_set_localaddr(cs.sock_nsi, &srcaddr.storage,
|
||||
SUN_LEN((struct sockaddr_un *)&srcaddr.storage));
|
||||
|
||||
if (o.verbose)
|
||||
loguser("[%s] used as source DGRAM Unix domain socket.\n", srcaddr.un.sun_path);
|
||||
@@ -926,20 +929,24 @@ int ncat_connect(void)
|
||||
case AF_UNSPEC:
|
||||
break;
|
||||
case AF_INET:
|
||||
nsi_set_localaddr(cs.sock_nsi, &srcaddr.storage, sizeof(srcaddr.in));
|
||||
nsock_iod_set_localaddr(cs.sock_nsi, &srcaddr.storage,
|
||||
sizeof(srcaddr.in));
|
||||
break;
|
||||
#ifdef AF_INET6
|
||||
case AF_INET6:
|
||||
nsi_set_localaddr(cs.sock_nsi, &srcaddr.storage, sizeof(srcaddr.in6));
|
||||
nsock_iod_set_localaddr(cs.sock_nsi, &srcaddr.storage,
|
||||
sizeof(srcaddr.in6));
|
||||
break;
|
||||
#endif
|
||||
#if HAVE_SYS_UN_H
|
||||
case AF_UNIX:
|
||||
nsi_set_localaddr(cs.sock_nsi, &srcaddr.storage, SUN_LEN((struct sockaddr_un *)&srcaddr.storage));
|
||||
nsock_iod_set_localaddr(cs.sock_nsi, &srcaddr.storage,
|
||||
SUN_LEN((struct sockaddr_un *)&srcaddr.storage));
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
nsi_set_localaddr(cs.sock_nsi, &srcaddr.storage, sizeof(srcaddr.storage));
|
||||
nsock_iod_set_localaddr(cs.sock_nsi, &srcaddr.storage,
|
||||
sizeof(srcaddr.storage));
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -951,7 +958,7 @@ int ncat_connect(void)
|
||||
bye("Sorry, -g can only currently be used with IPv4.");
|
||||
ipopts = buildsrcrte(targetss.in.sin_addr, o.srcrtes, o.numsrcrtes, o.srcrteptr, &ipoptslen);
|
||||
|
||||
nsi_set_ipoptions(cs.sock_nsi, ipopts, ipoptslen);
|
||||
nsock_iod_set_ipoptions(cs.sock_nsi, ipopts, ipoptslen);
|
||||
free(ipopts); /* Nsock has its own copy */
|
||||
}
|
||||
|
||||
@@ -1025,10 +1032,10 @@ int ncat_connect(void)
|
||||
|
||||
/* Once the proxy negotiation is done, Nsock takes control of the
|
||||
socket. */
|
||||
cs.sock_nsi = nsi_new2(mypool, connect_socket, NULL);
|
||||
cs.sock_nsi = nsock_iod_new2(mypool, connect_socket, NULL);
|
||||
|
||||
/* Create IOD for nsp->stdin */
|
||||
if ((cs.stdin_nsi = nsi_new2(mypool, 0, NULL)) == NULL)
|
||||
if ((cs.stdin_nsi = nsock_iod_new2(mypool, 0, NULL)) == NULL)
|
||||
bye("Failed to create stdin nsiod.");
|
||||
|
||||
post_connect(mypool, cs.sock_nsi);
|
||||
@@ -1043,8 +1050,8 @@ int ncat_connect(void)
|
||||
gettimeofday(&end_time, NULL);
|
||||
time = TIMEVAL_MSEC_SUBTRACT(end_time, start_time) / 1000.0;
|
||||
loguser("%lu bytes sent, %lu bytes received in %.2f seconds.\n",
|
||||
nsi_get_write_count(cs.sock_nsi),
|
||||
nsi_get_read_count(cs.sock_nsi), time);
|
||||
nsock_iod_get_write_count(cs.sock_nsi),
|
||||
nsock_iod_get_read_count(cs.sock_nsi), time);
|
||||
}
|
||||
|
||||
#if HAVE_SYS_UN_H
|
||||
@@ -1078,10 +1085,10 @@ static void connect_handler(nsock_pool nsp, nsock_event evt, void *data)
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
if (nsi_checkssl(cs.sock_nsi)) {
|
||||
if (nsock_iod_check_ssl(cs.sock_nsi)) {
|
||||
/* Check the domain name. ssl_post_connect_check prints an
|
||||
error message if appropriate. */
|
||||
if (!ssl_post_connect_check((SSL *) nsi_getssl(cs.sock_nsi), o.target))
|
||||
if (!ssl_post_connect_check((SSL *)nsock_iod_get_ssl(cs.sock_nsi), o.target))
|
||||
bye("Certificate verification error.");
|
||||
}
|
||||
#endif
|
||||
@@ -1089,7 +1096,7 @@ static void connect_handler(nsock_pool nsp, nsock_event evt, void *data)
|
||||
connect_report(cs.sock_nsi);
|
||||
|
||||
/* Create IOD for nsp->stdin */
|
||||
if ((cs.stdin_nsi = nsi_new2(nsp, 0, NULL)) == NULL)
|
||||
if ((cs.stdin_nsi = nsock_iod_new2(nsp, 0, NULL)) == NULL)
|
||||
bye("Failed to create stdin nsiod.");
|
||||
|
||||
post_connect(nsp, nse_iod(evt));
|
||||
@@ -1103,9 +1110,9 @@ static void post_connect(nsock_pool nsp, nsock_iod iod)
|
||||
if (o.cmdexec) {
|
||||
struct fdinfo info;
|
||||
|
||||
info.fd = nsi_getsd(iod);
|
||||
info.fd = nsock_iod_get_sd(iod);
|
||||
#ifdef HAVE_OPENSSL
|
||||
info.ssl = (SSL *) nsi_getssl(iod);
|
||||
info.ssl = (SSL *)nsock_iod_get_ssl(iod);
|
||||
#endif
|
||||
/* Convert Nsock's non-blocking socket to an ordinary blocking one. It's
|
||||
possible for a program to write fast enough that it will get an
|
||||
@@ -1141,7 +1148,7 @@ static void read_stdin_handler(nsock_pool nsp, nsock_event evt, void *data)
|
||||
ncat_assert(type == NSE_TYPE_READ);
|
||||
|
||||
if (status == NSE_STATUS_EOF) {
|
||||
shutdown(nsi_getsd(cs.sock_nsi), SHUT_WR);
|
||||
shutdown(nsock_iod_get_sd(cs.sock_nsi), SHUT_WR);
|
||||
/* In --send-only mode or non-TCP mode, exit after EOF on stdin. */
|
||||
if (o.proto != IPPROTO_TCP || (o.proto == IPPROTO_TCP && o.sendonly))
|
||||
nsock_loop_quit(nsp);
|
||||
@@ -1211,7 +1218,7 @@ static void read_socket_handler(nsock_pool nsp, nsock_event evt, void *data)
|
||||
ncat_delay_timer(o.linedelay);
|
||||
|
||||
if (o.telnet)
|
||||
dotelnet(nsi_getsd(nse_iod(evt)), (unsigned char *) buf, nbytes);
|
||||
dotelnet(nsock_iod_get_sd(nse_iod(evt)), (unsigned char *) buf, nbytes);
|
||||
|
||||
/* Write socket data to stdout */
|
||||
Write(STDOUT_FILENO, buf, nbytes);
|
||||
|
||||
@@ -361,7 +361,7 @@ static void close_dns_servers() {
|
||||
|
||||
for(serverI = servs.begin(); serverI != servs.end(); serverI++) {
|
||||
if (serverI->connected) {
|
||||
nsi_delete(serverI->nsd, NSOCK_PENDING_SILENT);
|
||||
nsock_iod_delete(serverI->nsd, NSOCK_PENDING_SILENT);
|
||||
serverI->connected = 0;
|
||||
serverI->to_process.clear();
|
||||
serverI->in_process.clear();
|
||||
@@ -870,15 +870,15 @@ static void add_dns_server(char *ipaddrs) {
|
||||
static void connect_dns_servers() {
|
||||
std::list<dns_server>::iterator serverI;
|
||||
for(serverI = servs.begin(); serverI != servs.end(); serverI++) {
|
||||
serverI->nsd = nsi_new(dnspool, NULL);
|
||||
serverI->nsd = nsock_iod_new(dnspool, NULL);
|
||||
if (o.spoofsource) {
|
||||
struct sockaddr_storage ss;
|
||||
size_t sslen;
|
||||
o.SourceSockAddr(&ss, &sslen);
|
||||
nsi_set_localaddr(serverI->nsd, &ss, sslen);
|
||||
nsock_iod_set_localaddr(serverI->nsd, &ss, sslen);
|
||||
}
|
||||
if (o.ipoptionslen)
|
||||
nsi_set_ipoptions(serverI->nsd, o.ipoptions, o.ipoptionslen);
|
||||
nsock_iod_set_ipoptions(serverI->nsd, o.ipoptions, o.ipoptionslen);
|
||||
serverI->reqs_on_wire = 0;
|
||||
serverI->capacity = CAPACITY_MIN;
|
||||
serverI->write_busy = 0;
|
||||
|
||||
@@ -174,7 +174,7 @@ int EchoClient::start(NpingTarget *target, u16 port){
|
||||
}else{
|
||||
/* Extract the nsock pool handler and store it here */
|
||||
this->nsp=this->probe.getNsockPool();
|
||||
this->nsi=nsi_new(this->nsp, NULL);
|
||||
this->nsi=nsock_iod_new(this->nsp, NULL);
|
||||
}
|
||||
|
||||
/* Schedule a TCP connection attempt */
|
||||
@@ -241,7 +241,7 @@ int EchoClient::nep_connect(NpingTarget *target, u16 port){
|
||||
#endif
|
||||
|
||||
/* Try to bind the IOD to the IP address supplied by the user */
|
||||
nsi_set_localaddr(this->nsi, o.getSourceSockAddr(&src), sizeof(sockaddr_in6));
|
||||
nsock_iod_set_localaddr(this->nsi, o.getSourceSockAddr(&src), sizeof(sockaddr_in6));
|
||||
|
||||
/* Schedule a connect event */
|
||||
nsock_connect_tcp(this->nsp, this->nsi, connect_done_handler, ECHO_CONNECT_TIMEOUT,
|
||||
@@ -258,7 +258,7 @@ int EchoClient::nep_connect(NpingTarget *target, u16 port){
|
||||
#endif
|
||||
|
||||
/* Try to bind the IOD to the IP address supplied by the user */
|
||||
nsi_set_localaddr(this->nsi, o.getSourceSockAddr(&src), sizeof(sockaddr_in));
|
||||
nsock_iod_set_localaddr(this->nsi, o.getSourceSockAddr(&src), sizeof(sockaddr_in));
|
||||
|
||||
/* Schedule a connect event */
|
||||
nsock_connect_tcp(this->nsp, this->nsi, connect_done_handler, ECHO_CONNECT_TIMEOUT,
|
||||
|
||||
@@ -180,7 +180,7 @@ NEPContext *EchoServer::getClientContext(clientid_t clnt){
|
||||
NEPContext *EchoServer::getClientContext(nsock_iod iod){
|
||||
nping_print(DBG_4, "%s()", __func__);
|
||||
clientid_t *id=NULL;
|
||||
if( (id=(clientid_t *)nsi_getud(iod))==NULL )
|
||||
if( (id=(clientid_t *)nsock_iod_get_udata(iod))==NULL )
|
||||
return NULL;
|
||||
else
|
||||
return this->getClientContext(*id);
|
||||
@@ -1088,7 +1088,7 @@ int EchoServer::nep_session_ended_handler(nsock_pool nsp, nsock_event nse, void
|
||||
else
|
||||
nping_print(DBG_2, "Deleted client #%d context.", clnt);
|
||||
}
|
||||
nsi_delete(nsi, NSOCK_PENDING_SILENT);
|
||||
nsock_iod_delete(nsi, NSOCK_PENDING_SILENT);
|
||||
|
||||
/* Exit the server if --once has been set */
|
||||
if(o.once()){
|
||||
@@ -1456,7 +1456,7 @@ int EchoServer::start() {
|
||||
nsock_set_loglevel(nsp, NSOCK_LOG_DBG_ALL);
|
||||
|
||||
/* Create new IOD for pcap */
|
||||
if ((pcap_nsi = nsi_new(nsp, NULL)) == NULL)
|
||||
if ((pcap_nsi = nsock_iod_new(nsp, NULL)) == NULL)
|
||||
nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n");
|
||||
|
||||
/* Open pcap */
|
||||
@@ -1486,11 +1486,11 @@ int EchoServer::start() {
|
||||
return OP_FAILURE;
|
||||
}
|
||||
*idpnt=this->getNewClientID();
|
||||
if( (client_nsi=nsi_new2(nsp, client_sd, idpnt))==NULL ){
|
||||
if( (client_nsi=nsock_iod_new2(nsp, client_sd, idpnt))==NULL ){
|
||||
nping_warning(QT_2, "Not enough memory for new clients.");
|
||||
return OP_FAILURE;
|
||||
}else{
|
||||
close(client_sd); /* nsi_new2() dups the socket */
|
||||
close(client_sd); /* nsock_iod_new2() dups the socket */
|
||||
}
|
||||
|
||||
/* Stop listening if --once is enabled */
|
||||
|
||||
@@ -367,7 +367,7 @@ int ProbeMode::start(){
|
||||
/* Set up libpcap */
|
||||
if(!o.disablePacketCapture()){
|
||||
/* Create new IOD for pcap */
|
||||
if ((pcap_nsi = nsi_new(nsp, NULL)) == NULL)
|
||||
if ((pcap_nsi = nsock_iod_new(nsp, NULL)) == NULL)
|
||||
nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n");
|
||||
|
||||
/* Open pcap */
|
||||
@@ -1691,7 +1691,7 @@ void ProbeMode::probe_nping_event_handler(nsock_pool nsp, nsock_event nse, void
|
||||
|
||||
/* If we are on a Ethernet network, extract the next packet protocol
|
||||
* from the Ethernet frame. */
|
||||
if( nsi_pcap_linktype(nsi) == DLT_EN10MB ){
|
||||
if( nsock_iod_linktype(nsi) == DLT_EN10MB ){
|
||||
ethtype=(u16*)(link+12);
|
||||
*ethtype=ntohs(*ethtype);
|
||||
switch(*ethtype){
|
||||
@@ -1945,7 +1945,9 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse,
|
||||
if( mypacket==NULL )
|
||||
nping_fatal(QT_3, "tcpconnect_event_handler(): NULL value supplied.");
|
||||
/* Determine which target are we dealing with */
|
||||
nsi_getlastcommunicationinfo(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
nsock_iod_get_communication_info(nsi, NULL, &family, NULL,
|
||||
(struct sockaddr*)&peer,
|
||||
sizeof(struct sockaddr_storage) );
|
||||
if(family==AF_INET6){
|
||||
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
|
||||
peerport=ntohs(peer6->sin6_port);
|
||||
@@ -2002,17 +2004,17 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse,
|
||||
* If we don't have a response by that time we probably aren't gonna
|
||||
* get any, so it shouldn't be a big problem. */
|
||||
if( packetno>(u32)max_iods ){
|
||||
nsi_delete(fds[packetno%max_iods], NSOCK_PENDING_SILENT);
|
||||
nsock_iod_delete(fds[packetno%max_iods], NSOCK_PENDING_SILENT);
|
||||
}
|
||||
/* Create new IOD for connects */
|
||||
if ((fds[packetno%max_iods] = nsi_new(nsp, NULL)) == NULL)
|
||||
if ((fds[packetno%max_iods] = nsock_iod_new(nsp, NULL)) == NULL)
|
||||
nping_fatal(QT_3, "tcpconnect_event_handler(): Failed to create new nsock_iod.\n");
|
||||
|
||||
/* Set socket source address. This allows setting things like custom source port */
|
||||
struct sockaddr_storage ss;
|
||||
nsi_set_localaddr(fds[packetno%max_iods], o.getSourceSockAddr(&ss), sizeof(sockaddr_storage));
|
||||
nsock_iod_set_localaddr(fds[packetno%max_iods], o.getSourceSockAddr(&ss), sizeof(sockaddr_storage));
|
||||
/*Set socket options for REUSEADDR*/
|
||||
//setsockopt(nsi_getsd(fds[packetno%max_iods]),SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));
|
||||
//setsockopt(nsock_iod_get_sd(fds[packetno%max_iods]),SOL_SOCKET,SO_REUSEADDR,&optval,sizeof(optval));
|
||||
|
||||
nsock_connect_tcp(nsp, fds[packetno%max_iods], tcpconnect_event_handler, 100000, mypacket, (struct sockaddr *)&to, sslen, mypacket->dstport);
|
||||
if( o.showSentPackets() ){
|
||||
@@ -2051,7 +2053,7 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse,
|
||||
* because there may be other reasons why ge get NSE_STATUS_ERROR so that's
|
||||
* why we say "Possible TCP RST received". */
|
||||
if ( type == NSE_TYPE_CONNECT ){
|
||||
nsi_getlastcommunicationinfo(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
nsock_iod_get_communication_info(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
if(family==AF_INET6){
|
||||
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
|
||||
peerport=ntohs(peer6->sin6_port);
|
||||
@@ -2211,15 +2213,15 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v
|
||||
* If we don't have a response by that time we probably aren't gonna
|
||||
* get any, so it shouldn't be a big problem. */
|
||||
if( packetno>(u32)max_iods ){
|
||||
nsi_delete(fds[packetno%max_iods], NSOCK_PENDING_SILENT);
|
||||
nsock_iod_delete(fds[packetno%max_iods], NSOCK_PENDING_SILENT);
|
||||
}
|
||||
/* Create new IOD for connects */
|
||||
if ((fds[packetno%max_iods] = nsi_new(nsp, NULL)) == NULL)
|
||||
if ((fds[packetno%max_iods] = nsock_iod_new(nsp, NULL)) == NULL)
|
||||
nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n");
|
||||
|
||||
/* Set socket source address. This allows setting things like custom source port */
|
||||
struct sockaddr_storage ss;
|
||||
nsi_set_localaddr(fds[packetno%max_iods], o.getSourceSockAddr(&ss), sizeof(sockaddr_storage));
|
||||
nsock_iod_set_localaddr(fds[packetno%max_iods], o.getSourceSockAddr(&ss), sizeof(sockaddr_storage));
|
||||
|
||||
|
||||
/* I dunno if it's safe to schedule an nsock_write before we
|
||||
@@ -2248,7 +2250,7 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v
|
||||
*/
|
||||
case NSE_TYPE_WRITE:
|
||||
/* Determine which target are we dealing with */
|
||||
nsi_getlastcommunicationinfo(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
nsock_iod_get_communication_info(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
if(family==AF_INET6){
|
||||
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
|
||||
peerport=ntohs(peer6->sin6_port);
|
||||
@@ -2291,7 +2293,7 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v
|
||||
nping_fatal(QT_3, "Error: nse_readbuff failed to read in the from the probe");
|
||||
}
|
||||
/* Determine which target are we dealing with */
|
||||
nsi_getlastcommunicationinfo(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
nsock_iod_get_communication_info(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
if(family==AF_INET6){
|
||||
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
|
||||
peerport=ntohs(peer6->sin6_port);
|
||||
@@ -2330,7 +2332,7 @@ void ProbeMode::probe_udpunpriv_event_handler(nsock_pool nsp, nsock_event nse, v
|
||||
} else if (status == NSE_STATUS_EOF) {
|
||||
nping_print(DBG_4, "udpunpriv_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n");
|
||||
} else if (status == NSE_STATUS_ERROR) {
|
||||
nsi_getlastcommunicationinfo(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
nsock_iod_get_communication_info(nsi, NULL, &family, NULL, (struct sockaddr*)&peer, sizeof(struct sockaddr_storage) );
|
||||
if(family==AF_INET6){
|
||||
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
|
||||
peerport=ntohs(peer6->sin6_port);
|
||||
|
||||
40
nse_nsock.cc
40
nse_nsock.cc
@@ -295,7 +295,7 @@ static void trace (nsock_iod nsiod, const char *message, const char *dir)
|
||||
{
|
||||
if (o.scriptTrace())
|
||||
{
|
||||
if (!nsi_is_pcap(nsiod))
|
||||
if (!nsock_iod_is_pcap(nsiod))
|
||||
{
|
||||
int protocol;
|
||||
int af;
|
||||
@@ -304,7 +304,7 @@ static void trace (nsock_iod nsiod, const char *message, const char *dir)
|
||||
struct sockaddr_storage local;
|
||||
struct sockaddr_storage remote;
|
||||
|
||||
nsi_getlastcommunicationinfo(nsiod, &protocol, &af,
|
||||
nsock_iod_get_communication_info(nsiod, &protocol, &af,
|
||||
(sockaddr *) &local, (sockaddr *) &remote, sizeof(sockaddr_storage));
|
||||
log_write(LOG_STDOUT, "%s: %s %s:%d %s %s:%d | %s\n",
|
||||
SCRIPT_ENGINE,
|
||||
@@ -381,17 +381,17 @@ static nse_nsock_udata *check_nsock_udata (lua_State *L, int idx, bool open)
|
||||
nsock_pool nsp;
|
||||
|
||||
nsp = get_pool(L);
|
||||
nu->nsiod = nsi_new(nsp, NULL);
|
||||
nu->nsiod = nsock_iod_new(nsp, NULL);
|
||||
if (nu->source_addr.ss_family != AF_UNSPEC) {
|
||||
nsi_set_localaddr(nu->nsiod, &nu->source_addr, nu->source_addrlen);
|
||||
nsock_iod_set_localaddr(nu->nsiod, &nu->source_addr, nu->source_addrlen);
|
||||
} else if (o.spoofsource) {
|
||||
struct sockaddr_storage ss;
|
||||
size_t sslen;
|
||||
o.SourceSockAddr(&ss, &sslen);
|
||||
nsi_set_localaddr(nu->nsiod, &ss, sslen);
|
||||
nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
|
||||
}
|
||||
if (o.ipoptionslen)
|
||||
nsi_set_ipoptions(nu->nsiod, o.ipoptions, o.ipoptionslen);
|
||||
nsock_iod_set_ipoptions(nu->nsiod, o.ipoptions, o.ipoptionslen);
|
||||
|
||||
if (nsock_setup_udp(nsp, nu->nsiod, nu->af) == -1) {
|
||||
luaL_error(L, "Error in setup of iod with proto %d and af %d: %s (%d)",
|
||||
@@ -497,21 +497,21 @@ static int l_connect (lua_State *L)
|
||||
|
||||
if (nu->nsiod != NULL)
|
||||
close_internal(L, nu);
|
||||
nu->nsiod = nsi_new(nsp, NULL);
|
||||
nu->nsiod = nsock_iod_new(nsp, NULL);
|
||||
if (nu->source_addr.ss_family != AF_UNSPEC) {
|
||||
nsi_set_localaddr(nu->nsiod, &nu->source_addr, nu->source_addrlen);
|
||||
nsock_iod_set_localaddr(nu->nsiod, &nu->source_addr, nu->source_addrlen);
|
||||
} else if (o.spoofsource) {
|
||||
struct sockaddr_storage ss;
|
||||
size_t sslen;
|
||||
|
||||
o.SourceSockAddr(&ss, &sslen);
|
||||
nsi_set_localaddr(nu->nsiod, &ss, sslen);
|
||||
nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
|
||||
}
|
||||
if (o.ipoptionslen)
|
||||
nsi_set_ipoptions(nu->nsiod, o.ipoptions, o.ipoptionslen);
|
||||
nsock_iod_set_ipoptions(nu->nsiod, o.ipoptions, o.ipoptionslen);
|
||||
if (targetname != NULL) {
|
||||
if (nsi_set_hostname(nu->nsiod, targetname) == -1)
|
||||
fatal("nsi_set_hostname(\"%s\" failed in %s()", targetname, __func__);
|
||||
if (nsock_iod_set_hostname(nu->nsiod, targetname) == -1)
|
||||
fatal("nsock_iod_set_hostname(\"%s\" failed in %s()", targetname, __func__);
|
||||
}
|
||||
|
||||
nu->af = dest->ai_addr->sa_family;
|
||||
@@ -705,7 +705,7 @@ static int l_get_info (lua_State *L)
|
||||
char *ipstring_local = (char *) lua_newuserdata(L, sizeof(char) * INET6_ADDRSTRLEN);
|
||||
char *ipstring_remote = (char *) lua_newuserdata(L, sizeof(char) * INET6_ADDRSTRLEN);
|
||||
|
||||
nsi_getlastcommunicationinfo(nu->nsiod, &protocol, &af,
|
||||
nsock_iod_get_communication_info(nu->nsiod, &protocol, &af,
|
||||
(struct sockaddr*)&local, (struct sockaddr*)&remote,
|
||||
sizeof(struct sockaddr_storage));
|
||||
|
||||
@@ -774,10 +774,10 @@ SSL *nse_nsock_get_ssl (lua_State *L)
|
||||
{
|
||||
nse_nsock_udata *nu = check_nsock_udata(L, 1, false);
|
||||
|
||||
if (nu->nsiod == NULL || !nsi_checkssl(nu->nsiod))
|
||||
if (nu->nsiod == NULL || !nsock_iod_check_ssl(nu->nsiod))
|
||||
luaL_argerror(L, 1, "not a SSL socket");
|
||||
|
||||
return (SSL *) nsi_getssl(nu->nsiod);
|
||||
return (SSL *) nsock_iod_get_ssl(nu->nsiod);
|
||||
}
|
||||
#else
|
||||
/* If HAVE_OPENSSL is defined, these come from nse_ssl_cert.cc. */
|
||||
@@ -828,8 +828,8 @@ static int l_bind (lua_State *L)
|
||||
}
|
||||
|
||||
/* We ignore any results after the first. */
|
||||
/* We would just call nsi_set_localaddr here, but nu->nsiod is not created
|
||||
until connect. So store the address in the userdatum. */
|
||||
/* We would just call nsock_iod_set_localaddr here, but nu->nsiod is not
|
||||
* created until connect. So store the address in the userdatum. */
|
||||
nu->source_addrlen = results->ai_addrlen;
|
||||
memcpy(&nu->source_addr, results->ai_addr, nu->source_addrlen);
|
||||
|
||||
@@ -898,7 +898,7 @@ static void close_internal (lua_State *L, nse_nsock_udata *nu)
|
||||
SSL_SESSION_free((SSL_SESSION *) nu->ssl_session);
|
||||
#endif
|
||||
if (!nu->is_pcap) { /* pcap sockets are closed by pcap_gc */
|
||||
nsi_delete(nu->nsiod, NSOCK_PENDING_NOTIFY);
|
||||
nsock_iod_delete(nu->nsiod, NSOCK_PENDING_NOTIFY);
|
||||
nu->nsiod = NULL;
|
||||
}
|
||||
}
|
||||
@@ -947,7 +947,7 @@ static void dnet_to_pcap_device_name (lua_State *L, const char *device)
|
||||
static int pcap_gc (lua_State *L)
|
||||
{
|
||||
nsock_iod *nsiod = (nsock_iod *) lua_touserdata(L, 1);
|
||||
nsi_delete(*nsiod, NSOCK_PENDING_NOTIFY);
|
||||
nsock_iod_delete(*nsiod, NSOCK_PENDING_NOTIFY);
|
||||
*nsiod = NULL;
|
||||
return 0;
|
||||
}
|
||||
@@ -984,7 +984,7 @@ static int l_pcap_open (lua_State *L)
|
||||
nsiod = (nsock_iod *) lua_newuserdata(L, sizeof(nsock_iod));
|
||||
lua_pushvalue(L, PCAP_SOCKET);
|
||||
lua_setmetatable(L, -2);
|
||||
*nsiod = nsi_new(nsp, nu);
|
||||
*nsiod = nsock_iod_new(nsp, nu);
|
||||
lua_pushvalue(L, 7); /* the pcap socket key */
|
||||
lua_pushvalue(L, -2); /* the pcap socket nsiod */
|
||||
lua_rawset(L, KEY_PCAP); /* KEY_PCAP["dev|snap|promis|bpf"] = pcap_nsiod */
|
||||
|
||||
@@ -116,8 +116,8 @@ typedef struct npool *nsock_pool;
|
||||
* multiple event calls, but only one at a time. Also the event calls must be in
|
||||
* a "reasonable" order. For example, you might start with nsock_connect_tcp()
|
||||
* followed by a bunch of nsock_read* and nsock_write* calls. Then you either
|
||||
* destroy the iod for good with nsi_delete() and allocate a new one via nsi_new
|
||||
* for your next connection. */
|
||||
* destroy the iod for good with nsock_iod_delete() and allocate a new one via
|
||||
* nsock_iod_new for your next connection. */
|
||||
typedef struct niod *nsock_iod;
|
||||
|
||||
/* An event is created when you do various calls (for reading, writing,
|
||||
@@ -202,15 +202,14 @@ void nsock_loop_quit(nsock_pool nsp);
|
||||
* if the status is NSOCK_LOOP_ERROR was returned by nsock_loop() */
|
||||
int nsock_pool_get_errorcode(nsock_pool nsp);
|
||||
|
||||
nsock_ssl nsi_getssl(nsock_iod nsockiod);
|
||||
nsock_ssl nsock_iod_get_ssl(nsock_iod nsockiod);
|
||||
|
||||
/* Note that nsi_get1_ssl_session will increment the usage count of the
|
||||
* SSL_SESSION, since nsock does a free when the nsi is destroyed. It's up to
|
||||
* any calling function/etc to do a SSL_SESSION_free() on it.
|
||||
* nsi_get0_ssl_session doesn't increment, and is for informational purposes
|
||||
* only. */
|
||||
nsock_ssl_session nsi_get1_ssl_session(nsock_iod nsockiod);
|
||||
nsock_ssl_session nsi_get0_ssl_session(nsock_iod nsockiod);
|
||||
/* Note that nsock_iod_get_ssl_session will increment the usage count of the
|
||||
* SSL_SESSION if inc_ref is not zero, since nsock does a free when the IOD
|
||||
* is destroyed. It's up to any calling function/etc to do a SSL_SESSION_free()
|
||||
* on it. Passing in inc_ref=0 doesn't increment, and is for informational
|
||||
* purposes only. */
|
||||
nsock_ssl_session nsock_iod_get_ssl_session(nsock_iod nsockiod, int inc_ref);
|
||||
|
||||
/* Sometimes it is useful to store a pointer to information inside the NSP so
|
||||
* you can retrieve it during a callback. */
|
||||
@@ -371,23 +370,23 @@ char *nse_readbuf(nsock_event nse, int *nbytes);
|
||||
nsock_iod nse_iod(nsock_event nse);
|
||||
|
||||
/* nsock_iod is like a "file descriptor" for the nsock library. You use it to
|
||||
* request events. And here is how you create an nsock_iod. nsi_new returns
|
||||
* NULL if the iod cannot be allocated. Pass NULL as userdata if you don't want
|
||||
* to immediately associate any user data with the iod. */
|
||||
nsock_iod nsi_new(nsock_pool nsockp, void *userdata);
|
||||
* request events. And here is how you create an nsock_iod. nsock_iod_new
|
||||
* returns NULL if the iod cannot be allocated. Pass NULL as udata if you
|
||||
* don't want to immediately associate any user data with the IOD. */
|
||||
nsock_iod nsock_iod_new(nsock_pool nsockp, void *udata);
|
||||
|
||||
/* This version allows you to associate an existing sd with the msi so that you
|
||||
* can read/write it using the nsock infrastructure. For example, you may want
|
||||
* to watch for data from STDIN_FILENO at the same time as you read/write
|
||||
* various sockets. STDIN_FILENO is a special case, however. Any other sd is
|
||||
* dup()ed, so you may close or otherwise manipulate your copy. The duped copy
|
||||
* will be destroyed when the nsi is destroyed */
|
||||
nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata);
|
||||
* will be destroyed when the IOD is destroyed */
|
||||
nsock_iod nsock_iod_new2(nsock_pool nsockp, int sd, void *udata);
|
||||
|
||||
/* If msiod_new returned success, you must free the iod when you are done with
|
||||
* it to conserve memory (and in some cases, sockets). After this call,
|
||||
/* If nsock_iod_new returned success, you must free the iod when you are done
|
||||
* with it to conserve memory (and in some cases, sockets). After this call,
|
||||
* nsockiod may no longer be used -- you need to create a new one with
|
||||
* nsi_new(). pending_response tells what to do with any events that are
|
||||
* nsock_iod_new(). pending_response tells what to do with any events that are
|
||||
* pending on this nsock_iod. This can be NSOCK_PENDING_NOTIFY (send a KILL
|
||||
* notification to each event), NSOCK_PENDING_SILENT (do not send notification
|
||||
* to the killed events), or NSOCK_PENDING_ERROR (print an error message and
|
||||
@@ -398,15 +397,15 @@ enum nsock_del_mode {
|
||||
NSOCK_PENDING_ERROR,
|
||||
};
|
||||
|
||||
void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response);
|
||||
void nsock_iod_delete(nsock_iod iod, enum nsock_del_mode pending_response);
|
||||
|
||||
/* Sometimes it is useful to store a pointer to information inside
|
||||
* the nsiod so you can retrieve it during a callback. */
|
||||
void nsi_setud(nsock_iod nsiod, void *data);
|
||||
void nsock_iod_set_udata(nsock_iod iod, void *udata);
|
||||
|
||||
/* And the function above wouldn't make much sense if we didn't have a way to
|
||||
* retrieve that data ... */
|
||||
void *nsi_getud(nsock_iod nsiod);
|
||||
void *nsock_iod_get_udata(nsock_iod iod);
|
||||
|
||||
/* I didn't want to do this. Its an ugly hack, but I suspect it will be
|
||||
* necessary. I certainly can't reproduce in nsock EVERYTHING you might want
|
||||
@@ -415,33 +414,33 @@ void *nsi_getud(nsock_iod nsiod);
|
||||
* "reasonable" things with it, like setting socket receive buffers. But don't
|
||||
* create havok by closing the descriptor! If the descriptor you get back is
|
||||
* -1, the iod does not currently possess a valid descriptor */
|
||||
int nsi_getsd(nsock_iod nsiod);
|
||||
int nsock_iod_get_sd(nsock_iod iod);
|
||||
|
||||
/* Returns the ID of an nsock_iod . This ID is always unique amongst ids for a
|
||||
* given nspool (unless you blow through billions of them). */
|
||||
unsigned long nsi_id(nsock_iod nsockiod);
|
||||
unsigned long nsock_iod_id(nsock_iod iod);
|
||||
|
||||
/* Returns Packets received in bytes */
|
||||
unsigned long nsi_get_read_count(nsock_iod nsockiod);
|
||||
unsigned long nsock_iod_get_read_count(nsock_iod iod);
|
||||
|
||||
/* Returns Packets sent in bytes */
|
||||
unsigned long nsi_get_write_count(nsock_iod nsockiod);
|
||||
unsigned long nsock_iod_get_write_count(nsock_iod iod);
|
||||
|
||||
/* Returns 1 if an NSI is communicating via SSL, 0 otherwise */
|
||||
int nsi_checkssl(nsock_iod nsockiod);
|
||||
int nsock_iod_check_ssl(nsock_iod iod);
|
||||
|
||||
/* Returns the remote peer port (or -1 if unavailable). Note the return value
|
||||
* is a whole int so that -1 can be distinguished from 65535. Port is returned
|
||||
* in host byte order. */
|
||||
int nsi_peerport(nsock_iod nsiod);
|
||||
int nsock_iod_get_peerport(nsock_iod iod);
|
||||
|
||||
/* Sets the local address to bind to before connect() */
|
||||
int nsi_set_localaddr(nsock_iod nsi, struct sockaddr_storage *ss, size_t sslen);
|
||||
int nsock_iod_set_localaddr(nsock_iod iod, struct sockaddr_storage *ss, size_t sslen);
|
||||
|
||||
/* Sets IPv4 options to apply before connect(). It makes a copy of the options,
|
||||
* so you can free() yours if necessary. This copy is freed when the iod is
|
||||
* destroyed */
|
||||
int nsi_set_ipoptions(nsock_iod nsi, void *ipopts, size_t ipoptslen);
|
||||
int nsock_iod_set_ipoptions(nsock_iod iod, void *ipopts, size_t ipoptslen);
|
||||
|
||||
/* Returns that host/port/protocol information for the last communication (or
|
||||
* comm. attempt) this nsi has been involved with. By "involved" with I mean
|
||||
@@ -455,11 +454,13 @@ int nsi_set_ipoptions(nsock_iod nsi, void *ipopts, size_t ipoptslen);
|
||||
* address space. The sockaddr members should actually be sockaddr_storage,
|
||||
* sockaddr_in6, or sockaddr_in with the socklen of them set appropriately (eg
|
||||
* sizeof(sockaddr_storage) if that is what you are passing). */
|
||||
int nsi_getlastcommunicationinfo(nsock_iod ms_iod, int *protocol, int *af, struct sockaddr *local, struct sockaddr *remote, size_t socklen);
|
||||
int nsock_iod_get_communication_info(nsock_iod iod, int *protocol, int *af,
|
||||
struct sockaddr *local,
|
||||
struct sockaddr *remote, size_t socklen);
|
||||
|
||||
/* Set the hostname of the remote host, for when that matters. This is currently
|
||||
* only used for Server Name Indication in SSL connections. */
|
||||
int nsi_set_hostname(nsock_iod nsi, const char *hostname);
|
||||
int nsock_iod_set_hostname(nsock_iod iod, const char *hostname);
|
||||
|
||||
/* EVENT CREATION FUNCTIONS
|
||||
* ---
|
||||
@@ -661,11 +662,12 @@ void nse_readpcap(nsock_event nsee, const unsigned char **l2_data,
|
||||
size_t *l2_len, const unsigned char **l3_data, size_t *l3_len,
|
||||
size_t *packet_len, struct timeval *ts);
|
||||
|
||||
/* Well. Just pcap-style datalink. Like DLT_EN10MB or DLT_SLIP. Check in pcap(3) manpage. */
|
||||
int nsi_pcap_linktype(nsock_iod nsiod);
|
||||
/* Well. Just pcap-style datalink.
|
||||
* Like DLT_EN10MB or DLT_SLIP. Check in pcap(3) manpage. */
|
||||
int nsock_iod_linktype(nsock_iod iod);
|
||||
|
||||
/* Is this nsiod a pcap descriptor? */
|
||||
int nsi_is_pcap(nsock_iod nsiod);
|
||||
int nsock_iod_is_pcap(nsock_iod iod);
|
||||
|
||||
#endif /* HAVE_PCAP */
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ int epoll_iod_register(struct npool *nsp, struct niod *iod, int ev) {
|
||||
if (ev & EV_EXCEPT)
|
||||
epev.events |= EPOLL_X_FLAGS;
|
||||
|
||||
sd = nsi_getsd(iod);
|
||||
sd = nsock_iod_get_sd(iod);
|
||||
if (epoll_ctl(einfo->epfd, EPOLL_CTL_ADD, sd, &epev) < 0)
|
||||
fatal("Unable to register IOD #%lu: %s", iod->id, strerror(errno));
|
||||
|
||||
@@ -196,7 +196,7 @@ int epoll_iod_unregister(struct npool *nsp, struct niod *iod) {
|
||||
struct epoll_engine_info *einfo = (struct epoll_engine_info *)nsp->engine_data;
|
||||
int sd;
|
||||
|
||||
sd = nsi_getsd(iod);
|
||||
sd = nsock_iod_get_sd(iod);
|
||||
epoll_ctl(einfo->epfd, EPOLL_CTL_DEL, sd, NULL);
|
||||
|
||||
IOD_PROPCLR(iod, IOD_REGISTERED);
|
||||
@@ -234,7 +234,7 @@ int epoll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr
|
||||
if (iod->watched_events & EV_EXCEPT)
|
||||
epev.events |= EPOLL_X_FLAGS;
|
||||
|
||||
sd = nsi_getsd(iod);
|
||||
sd = nsock_iod_get_sd(iod);
|
||||
|
||||
if (epoll_ctl(einfo->epfd, EPOLL_CTL_MOD, sd, &epev) < 0)
|
||||
fatal("Unable to update events for IOD #%lu: %s", iod->id, strerror(errno));
|
||||
|
||||
@@ -161,8 +161,8 @@ int kqueue_iod_register(struct npool *nsp, struct niod *iod, int ev) {
|
||||
|
||||
kqueue_iod_modify(nsp, iod, ev, EV_NONE);
|
||||
|
||||
if (nsi_getsd(iod) > kinfo->maxfd)
|
||||
kinfo->maxfd = nsi_getsd(iod);
|
||||
if (nsock_iod_get_sd(iod) > kinfo->maxfd)
|
||||
kinfo->maxfd = nsock_iod_get_sd(iod);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ int kqueue_iod_unregister(struct npool *nsp, struct niod *iod) {
|
||||
kqueue_iod_modify(nsp, iod, EV_NONE, EV_READ|EV_WRITE);
|
||||
IOD_PROPCLR(iod, IOD_REGISTERED);
|
||||
|
||||
if (nsi_getsd(iod) == kinfo->maxfd)
|
||||
if (nsock_iod_get_sd(iod) == kinfo->maxfd)
|
||||
kinfo->maxfd--;
|
||||
}
|
||||
iod->watched_events = EV_NONE;
|
||||
@@ -202,11 +202,11 @@ int kqueue_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_cl
|
||||
|
||||
i = 0;
|
||||
if ((ev_set ^ ev_clr) & EV_READ) {
|
||||
EV_SET(&kev[i], nsi_getsd(iod), EVFILT_READ, EV_SETFLAG(ev_set, EV_READ), 0, 0, (void *)iod);
|
||||
EV_SET(&kev[i], nsock_iod_get_sd(iod), EVFILT_READ, EV_SETFLAG(ev_set, EV_READ), 0, 0, (void *)iod);
|
||||
i++;
|
||||
}
|
||||
if ((ev_set ^ ev_clr) & EV_WRITE) {
|
||||
EV_SET(&kev[i], nsi_getsd(iod), EVFILT_WRITE, EV_SETFLAG(ev_set, EV_WRITE), 0, 0, (void *)iod);
|
||||
EV_SET(&kev[i], nsock_iod_get_sd(iod), EVFILT_WRITE, EV_SETFLAG(ev_set, EV_WRITE), 0, 0, (void *)iod);
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ int poll_iod_register(struct npool *nsp, struct niod *iod, int ev) {
|
||||
|
||||
iod->watched_events = ev;
|
||||
|
||||
sd = nsi_getsd(iod);
|
||||
sd = nsock_iod_get_sd(iod);
|
||||
while (pinfo->capacity < sd + 1)
|
||||
evlist_grow(pinfo);
|
||||
|
||||
@@ -252,7 +252,7 @@ int poll_iod_unregister(struct npool *nsp, struct niod *iod) {
|
||||
struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data;
|
||||
int sd;
|
||||
|
||||
sd = nsi_getsd(iod);
|
||||
sd = nsock_iod_get_sd(iod);
|
||||
pinfo->events[sd].fd = -1;
|
||||
pinfo->events[sd].events = 0;
|
||||
pinfo->events[sd].revents = 0;
|
||||
@@ -282,7 +282,7 @@ int poll_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_clr)
|
||||
|
||||
iod->watched_events = new_events;
|
||||
|
||||
sd = nsi_getsd(iod);
|
||||
sd = nsock_iod_get_sd(iod);
|
||||
|
||||
pinfo->events[sd].fd = sd;
|
||||
pinfo->events[sd].events = 0;
|
||||
|
||||
@@ -205,7 +205,7 @@ int select_iod_modify(struct npool *nsp, struct niod *iod, int ev_set, int ev_cl
|
||||
iod->watched_events |= ev_set;
|
||||
iod->watched_events &= ~ev_clr;
|
||||
|
||||
sd = nsi_getsd(iod);
|
||||
sd = nsock_iod_get_sd(iod);
|
||||
|
||||
/* -- set events -- */
|
||||
if (ev_set & EV_READ)
|
||||
|
||||
@@ -503,12 +503,13 @@ nsock_event_id nsock_connect_udp(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handl
|
||||
* address space. The sockaddr members should actually be sockaddr_storage,
|
||||
* sockaddr_in6, or sockaddr_in with the socklen of them set appropriately (eg
|
||||
* sizeof(sockaddr_storage) if that is what you are passing). */
|
||||
int nsi_getlastcommunicationinfo(nsock_iod ms_iod, int *protocol, int *af, struct sockaddr *local,
|
||||
int nsock_iod_get_communication_info(nsock_iod iod, int *protocol, int *af,
|
||||
struct sockaddr *local,
|
||||
struct sockaddr *remote, size_t socklen) {
|
||||
struct niod *nsi = (struct niod *)ms_iod;
|
||||
struct niod *nsi = (struct niod *)iod;
|
||||
int ret = 1;
|
||||
struct sockaddr_storage sock;
|
||||
socklen_t slen = sizeof(struct sockaddr_storage);
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t slen = sizeof(ss);
|
||||
int res;
|
||||
|
||||
assert(socklen > 0);
|
||||
@@ -525,13 +526,13 @@ int nsi_getlastcommunicationinfo(nsock_iod ms_iod, int *protocol, int *af, struc
|
||||
}
|
||||
if (local) {
|
||||
if (nsi->sd >= 0) {
|
||||
res = getsockname(nsi->sd, (struct sockaddr *)&sock, &slen);
|
||||
res = getsockname(nsi->sd, (struct sockaddr *)&ss, &slen);
|
||||
if (res == -1) {
|
||||
memset(local, 0, socklen);
|
||||
ret = 0;
|
||||
} else {
|
||||
assert(slen > 0);
|
||||
memcpy(local, &sock, MIN((unsigned)slen, socklen));
|
||||
memcpy(local, &ss, MIN((unsigned)slen, socklen));
|
||||
}
|
||||
} else {
|
||||
memset(local, 0, socklen);
|
||||
|
||||
@@ -477,16 +477,16 @@ void handle_connect_result(struct npool *ms, struct nevent *nse, enum nse_status
|
||||
|
||||
/* SSLv3-only and TLSv1-only servers can't be connected to when the
|
||||
* SSL_OP_NO_SSLv2 option is not set, which is the case when the pool
|
||||
* was initialized with nsock_pool_ssl_init_max_speed. Try reconnecting with
|
||||
* SSL_OP_NO_SSLv2. Never downgrade a NO_SSLv2 connection to one that
|
||||
* might use SSLv2. */
|
||||
* was initialized with nsock_pool_ssl_init_max_speed. Try reconnecting
|
||||
* with SSL_OP_NO_SSLv2. Never downgrade a NO_SSLv2 connection to one
|
||||
* that might use SSLv2. */
|
||||
nsock_log_info(ms, "EID %li reconnecting with SSL_OP_NO_SSLv2", nse->id);
|
||||
|
||||
saved_ev = iod->watched_events;
|
||||
nsock_engine_iod_unregister(ms, iod);
|
||||
close(iod->sd);
|
||||
nsock_connect_internal(ms, nse, SOCK_STREAM, iod->lastproto, &iod->peer,
|
||||
iod->peerlen, nsi_peerport(iod));
|
||||
iod->peerlen, nsock_iod_get_peerport(iod));
|
||||
nsock_engine_iod_register(ms, iod, saved_ev);
|
||||
|
||||
SSL_clear(iod->ssl);
|
||||
|
||||
@@ -120,7 +120,7 @@ enum iod_state {
|
||||
NSIOD_STATE_DELETED,
|
||||
NSIOD_STATE_INITIAL,
|
||||
|
||||
/* sd was provided to us in nsi_new2 (see nsock_pool.c) */
|
||||
/* sd was provided to us in nsock_iod_new2 (see nsock_iod.c) */
|
||||
NSIOD_STATE_UNKNOWN,
|
||||
|
||||
NSIOD_STATE_CONNECTED_TCP,
|
||||
|
||||
@@ -71,11 +71,11 @@
|
||||
|
||||
|
||||
/* nsock_iod is like a "file descriptor" for the nsock library. You use it to
|
||||
* request events. And here is how you create an nsock_iod. nsi_new returns
|
||||
* request events. And here is how you create an nsock_iod. nsock_iod_new returns
|
||||
* NULL if the iod cannot be allocated. Pass NULL as userdata if you don't want
|
||||
* to immediately associate any user data with the iod. */
|
||||
nsock_iod nsi_new(nsock_pool nsockp, void *userdata) {
|
||||
return nsi_new2(nsockp, -1, userdata);
|
||||
nsock_iod nsock_iod_new(nsock_pool nsockp, void *userdata) {
|
||||
return nsock_iod_new2(nsockp, -1, userdata);
|
||||
}
|
||||
|
||||
/* This version allows you to associate an existing sd with the msi so that you
|
||||
@@ -84,7 +84,7 @@ nsock_iod nsi_new(nsock_pool nsockp, void *userdata) {
|
||||
* various sockets. STDIN_FILENO is a special case, however. Any other sd is
|
||||
* dup()ed, so you may close or otherwise manipulate your copy. The duped copy
|
||||
* will be destroyed when the nsi is destroyed. */
|
||||
nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {
|
||||
nsock_iod nsock_iod_new2(nsock_pool nsockp, int sd, void *userdata) {
|
||||
struct npool *nsp = (struct npool *)nsockp;
|
||||
gh_lnode_t *lnode;
|
||||
struct niod *nsi;
|
||||
@@ -153,7 +153,7 @@ nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {
|
||||
/* The nsp keeps track of active iods so it can delete them if it is deleted */
|
||||
gh_list_append(&nsp->active_iods, &nsi->nodeq);
|
||||
|
||||
nsock_log_info(nsp, "nsi_new (IOD #%lu)", nsi->id);
|
||||
nsock_log_info(nsp, "nsock_iod_new (IOD #%lu)", nsi->id);
|
||||
|
||||
return (nsock_iod)nsi;
|
||||
}
|
||||
@@ -161,15 +161,15 @@ nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {
|
||||
/* Defined in nsock_core.c. */
|
||||
int socket_count_zero(struct niod *iod, struct npool *ms);
|
||||
|
||||
/* If nsi_new returned success, you must free the iod when you are done with
|
||||
/* If nsock_iod_new returned success, you must free the iod when you are done with
|
||||
* it to conserve memory (and in some cases, sockets). After this call,
|
||||
* nsockiod may no longer be used -- you need to create a new one with
|
||||
* nsi_new(). pending_response tells what to do with any events that are
|
||||
* nsock_iod_new(). pending_response tells what to do with any events that are
|
||||
* pending on this nsock_iod. This can be NSOCK_PENDING_NOTIFY (send a KILL
|
||||
* notification to each event), NSOCK_PENDING_SILENT (do not send notification
|
||||
* to the killed events), or NSOCK_PENDING_ERROR (print an error message and
|
||||
* quit the program) */
|
||||
void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
void nsock_iod_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
struct niod *nsi = (struct niod *)nsockiod;
|
||||
gh_lnode_t *evlist_ar[3];
|
||||
gh_list_t *corresp_list[3];
|
||||
@@ -184,7 +184,7 @@ void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsock_log_info(nsi->nsp, "nsi_delete (IOD #%lu)", nsi->id);
|
||||
nsock_log_info(nsi->nsp, "nsock_iod_delete (IOD #%lu)", nsi->id);
|
||||
|
||||
if (nsi->events_pending > 0) {
|
||||
/* shit -- they killed the struct niod while an event was still pending on it.
|
||||
@@ -193,7 +193,7 @@ void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
* by just locating the events here by searching through the active events
|
||||
* list */
|
||||
if (pending_response == NSOCK_PENDING_ERROR)
|
||||
fatal("nsi_delete called with argument NSOCK_PENDING_ERROR on a nsock_iod that has %d pending event(s) associated with it", nsi->events_pending);
|
||||
fatal("nsock_iod_delete called with argument NSOCK_PENDING_ERROR on a nsock_iod that has %d pending event(s) associated with it", nsi->events_pending);
|
||||
|
||||
assert(pending_response == NSOCK_PENDING_NOTIFY || pending_response == NSOCK_PENDING_SILENT);
|
||||
|
||||
@@ -242,7 +242,7 @@ void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
#endif
|
||||
|
||||
if (SSL_shutdown(nsi->ssl) == -1) {
|
||||
nsock_log_info(nsi->nsp, "nsi_delete: SSL shutdown failed (%s) on NSI %li",
|
||||
nsock_log_info(nsi->nsp, "nsock_iod_delete: SSL shutdown failed (%s) on NSI %li",
|
||||
ERR_reason_error_string(SSL_get_error(nsi->ssl, -1)), nsi->id);
|
||||
}
|
||||
|
||||
@@ -292,33 +292,28 @@ void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
|
||||
|
||||
/* Returns the ID of an nsock_iod . This ID is always unique amongst ids for a
|
||||
* given nspool (unless you blow through billions of them). */
|
||||
unsigned long nsi_id(nsock_iod nsockiod) {
|
||||
unsigned long nsock_iod_id(nsock_iod nsockiod) {
|
||||
assert(nsockiod);
|
||||
return ((struct niod *)nsockiod)->id;
|
||||
}
|
||||
|
||||
/* Returns the SSL object inside an nsock_iod, or NULL if unset. */
|
||||
nsock_ssl nsi_getssl(nsock_iod nsockiod) {
|
||||
nsock_ssl nsock_iod_get_ssl(nsock_iod iod) {
|
||||
#if HAVE_OPENSSL
|
||||
return ((struct niod *)nsockiod)->ssl;
|
||||
return ((struct niod *)iod)->ssl;
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Returns the SSL_SESSION of an nsock_iod, and increments its usage count. */
|
||||
nsock_ssl_session nsi_get1_ssl_session(nsock_iod nsockiod) {
|
||||
/* Returns the SSL_SESSION of an nsock_iod.
|
||||
* Increments its usage count if inc_ref is not zero. */
|
||||
nsock_ssl_session nsock_iod_get_ssl_session(nsock_iod iod, int inc_ref) {
|
||||
#if HAVE_OPENSSL
|
||||
return SSL_get1_session(((struct niod *)nsockiod)->ssl);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Returns the SSL_SESSION without incrementing usage count. */
|
||||
nsock_ssl_session nsi_get0_ssl_session(nsock_iod nsockiod) {
|
||||
#if HAVE_OPENSSL
|
||||
return SSL_get0_session(((struct niod *)nsockiod)->ssl);
|
||||
if (inc_ref)
|
||||
return SSL_get1_session(((struct niod *)iod)->ssl);
|
||||
else
|
||||
return SSL_get0_session(((struct niod *)iod)->ssl);
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
@@ -337,28 +332,28 @@ void nsi_set_ssl_session(struct niod *iod, SSL_SESSION *sessid) {
|
||||
|
||||
/* Sometimes it is useful to store a pointer to information inside the struct niod so
|
||||
* you can retrieve it during a callback. */
|
||||
void nsi_setud(nsock_iod nsockiod, void *data) {
|
||||
assert(nsockiod);
|
||||
((struct niod *)nsockiod)->userdata = data;
|
||||
void nsock_iod_set_udata(nsock_iod iod, void *udata) {
|
||||
assert(iod);
|
||||
((struct niod *)iod)->userdata = udata;
|
||||
}
|
||||
|
||||
/* And the function above wouldn't make much sense if we didn't have a way to
|
||||
* retrieve that data... */
|
||||
void *nsi_getud(nsock_iod nsockiod) {
|
||||
assert(nsockiod);
|
||||
return ((struct niod *)nsockiod)->userdata;
|
||||
void *nsock_iod_get_udata(nsock_iod iod) {
|
||||
assert(iod);
|
||||
return ((struct niod *)iod)->userdata;
|
||||
}
|
||||
|
||||
/* Returns 1 if an NSI is communicating via SSL, 0 otherwise. */
|
||||
int nsi_checkssl(nsock_iod nsockiod) {
|
||||
return (((struct niod *)nsockiod)->ssl) ? 1 : 0;
|
||||
int nsock_iod_check_ssl(nsock_iod iod) {
|
||||
return (((struct niod *)iod)->ssl) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* Returns the remote peer port (or -1 if unavailable). Note the return value
|
||||
* is a whole int so that -1 can be distinguished from 65535. Port is returned
|
||||
* in host byte order. */
|
||||
int nsi_peerport(nsock_iod nsockiod) {
|
||||
struct niod *nsi = (struct niod *)nsockiod;
|
||||
int nsock_iod_get_peerport(nsock_iod iod) {
|
||||
struct niod *nsi = (struct niod *)iod;
|
||||
int fam;
|
||||
|
||||
if (nsi->peerlen <= 0)
|
||||
@@ -377,33 +372,34 @@ int nsi_peerport(nsock_iod nsockiod) {
|
||||
}
|
||||
|
||||
/* Sets the local address to bind to before connect() */
|
||||
int nsi_set_localaddr(nsock_iod nsi, struct sockaddr_storage *ss, size_t sslen) {
|
||||
struct niod *iod = (struct niod *)nsi;
|
||||
int nsock_iod_set_localaddr(nsock_iod iod, struct sockaddr_storage *ss,
|
||||
size_t sslen) {
|
||||
struct niod *nsi = (struct niod *)iod;
|
||||
|
||||
assert(iod);
|
||||
assert(nsi);
|
||||
|
||||
if (sslen > sizeof(iod->local))
|
||||
if (sslen > sizeof(nsi->local))
|
||||
return -1;
|
||||
|
||||
memcpy(&iod->local, ss, sslen);
|
||||
iod->locallen = sslen;
|
||||
memcpy(&nsi->local, ss, sslen);
|
||||
nsi->locallen = sslen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Sets IPv4 options to apply before connect(). It makes a copy of the options,
|
||||
* so you can free() yours if necessary. This copy is freed when the iod is
|
||||
* destroyed. */
|
||||
int nsi_set_ipoptions(nsock_iod nsi, void *opts, size_t optslen) {
|
||||
struct niod *iod = (struct niod *)nsi;
|
||||
int nsock_iod_set_ipoptions(nsock_iod iod, void *opts, size_t optslen) {
|
||||
struct niod *nsi = (struct niod *)iod;
|
||||
|
||||
assert(iod);
|
||||
assert(nsi);
|
||||
|
||||
if (optslen > 44)
|
||||
return -1;
|
||||
|
||||
iod->ipopts = safe_malloc(optslen);
|
||||
memcpy(iod->ipopts, opts, optslen);
|
||||
iod->ipoptslen = optslen;
|
||||
nsi->ipopts = safe_malloc(optslen);
|
||||
memcpy(nsi->ipopts, opts, optslen);
|
||||
nsi->ipoptslen = optslen;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -414,37 +410,37 @@ int nsi_set_ipoptions(nsock_iod nsi, void *opts, size_t optslen) {
|
||||
* "reasonable" things with it, like setting socket receive buffers. But don't
|
||||
* create havok by closing the descriptor! If the descriptor you get back is
|
||||
* -1, the iod does not currently possess a valid descriptor */
|
||||
int nsi_getsd(nsock_iod nsockiod) {
|
||||
struct niod *iod = (struct niod *)nsockiod;
|
||||
int nsock_iod_get_sd(nsock_iod iod) {
|
||||
struct niod *nsi = (struct niod *)iod;
|
||||
|
||||
assert(nsockiod);
|
||||
assert(nsi);
|
||||
|
||||
#if HAVE_PCAP
|
||||
if (iod->pcap)
|
||||
return ((mspcap *)iod->pcap)->pcap_desc;
|
||||
if (nsi->pcap)
|
||||
return ((mspcap *)nsi->pcap)->pcap_desc;
|
||||
else
|
||||
#endif
|
||||
return iod->sd;
|
||||
return nsi->sd;
|
||||
}
|
||||
|
||||
unsigned long nsi_get_read_count(nsock_iod nsockiod){
|
||||
assert(nsockiod);
|
||||
return ((struct niod *)nsockiod)->read_count;
|
||||
unsigned long nsock_iod_get_read_count(nsock_iod iod){
|
||||
assert(iod);
|
||||
return ((struct niod *)iod)->read_count;
|
||||
}
|
||||
|
||||
unsigned long nsi_get_write_count(nsock_iod nsockiod){
|
||||
assert(nsockiod);
|
||||
return ((struct niod *)nsockiod)->write_count;
|
||||
unsigned long nsock_iod_get_write_count(nsock_iod iod){
|
||||
assert(iod);
|
||||
return ((struct niod *)iod)->write_count;
|
||||
}
|
||||
|
||||
int nsi_set_hostname(nsock_iod nsi, const char *hostname) {
|
||||
struct niod *iod = (struct niod *)nsi;
|
||||
int nsock_iod_set_hostname(nsock_iod iod, const char *hostname) {
|
||||
struct niod *nsi = (struct niod *)iod;
|
||||
|
||||
if (iod->hostname != NULL)
|
||||
free(iod->hostname);
|
||||
if (nsi->hostname != NULL)
|
||||
free(nsi->hostname);
|
||||
|
||||
iod->hostname = strdup(hostname);
|
||||
if (iod->hostname == NULL)
|
||||
nsi->hostname = strdup(hostname);
|
||||
if (nsi->hostname == NULL)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -476,16 +476,16 @@ void nse_readpcap(nsock_event nsev, const unsigned char **l2_data, size_t *l2_le
|
||||
return;
|
||||
}
|
||||
|
||||
int nsi_pcap_linktype(nsock_iod nsiod) {
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
int nsock_iod_linktype(nsock_iod iod) {
|
||||
struct niod *nsi = (struct niod *)iod;
|
||||
mspcap *mp = (mspcap *)nsi->pcap;
|
||||
|
||||
assert(mp);
|
||||
return (mp->datalink);
|
||||
}
|
||||
|
||||
int nsi_is_pcap(nsock_iod nsiod) {
|
||||
struct niod *nsi = (struct niod *)nsiod;
|
||||
int nsock_iod_is_pcap(nsock_iod iod) {
|
||||
struct niod *nsi = (struct niod *)iod;
|
||||
mspcap *mp = (mspcap *)nsi->pcap;
|
||||
|
||||
return (mp != NULL);
|
||||
|
||||
@@ -265,7 +265,7 @@ void nsock_pool_delete(nsock_pool ms_pool) {
|
||||
next = gh_lnode_next(current);
|
||||
nsi = container_of(current, struct niod, nodeq);
|
||||
|
||||
nsi_delete(nsi, NSOCK_PENDING_ERROR);
|
||||
nsock_iod_delete(nsi, NSOCK_PENDING_ERROR);
|
||||
|
||||
gh_list_remove(&nsp->active_iods, current);
|
||||
gh_list_prepend(&nsp->free_iods, &nsi->nodeq);
|
||||
|
||||
@@ -2025,19 +2025,20 @@ static void startNextProbe(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
|
||||
if (probe) {
|
||||
// For a TCP probe, we start by requesting a new connection to the target
|
||||
if (svc->proto == IPPROTO_TCP) {
|
||||
nsi_delete(nsi, NSOCK_PENDING_SILENT);
|
||||
if ((svc->niod = nsi_new(nsp, svc)) == NULL) {
|
||||
nsock_iod_delete(nsi, NSOCK_PENDING_SILENT);
|
||||
if ((svc->niod = nsock_iod_new(nsp, svc)) == NULL) {
|
||||
fatal("Failed to allocate Nsock I/O descriptor in %s()", __func__);
|
||||
}
|
||||
if (o.spoofsource) {
|
||||
o.SourceSockAddr(&ss, &ss_len);
|
||||
nsi_set_localaddr(svc->niod, &ss, ss_len);
|
||||
nsock_iod_set_localaddr(svc->niod, &ss, ss_len);
|
||||
}
|
||||
if (o.ipoptionslen)
|
||||
nsi_set_ipoptions(svc->niod, o.ipoptions, o.ipoptionslen);
|
||||
nsock_iod_set_ipoptions(svc->niod, o.ipoptions, o.ipoptionslen);
|
||||
if (svc->target->TargetName()) {
|
||||
if (nsi_set_hostname(svc->niod, svc->target->TargetName()) == -1)
|
||||
fatal("nsi_set_hostname(\"%s\" failed in %s()", svc->target->TargetName(), __func__);
|
||||
if (nsock_iod_set_hostname(svc->niod, svc->target->TargetName()) == -1)
|
||||
fatal("nsock_iod_set_hostname(\"%s\" failed in %s()",
|
||||
svc->target->TargetName(), __func__);
|
||||
}
|
||||
svc->target->TargetSockAddr(&ss, &ss_len);
|
||||
if (svc->tunnel == SERVICE_TUNNEL_NONE) {
|
||||
@@ -2063,8 +2064,10 @@ static void startNextProbe(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
|
||||
}
|
||||
} else {
|
||||
// No more probes remaining! Failed to match
|
||||
nsi_delete(nsi, NSOCK_PENDING_SILENT);
|
||||
end_svcprobe(nsp, (svc->softMatchFound)? PROBESTATE_FINISHED_SOFTMATCHED : PROBESTATE_FINISHED_NOMATCH, SG, svc, NULL);
|
||||
nsock_iod_delete(nsi, NSOCK_PENDING_SILENT);
|
||||
end_svcprobe(nsp, (svc->softMatchFound)? PROBESTATE_FINISHED_SOFTMATCHED :
|
||||
PROBESTATE_FINISHED_NOMATCH,
|
||||
SG, svc, NULL);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -2195,9 +2198,8 @@ static void end_svcprobe(nsock_pool nsp, enum serviceprobestate probe_state, Ser
|
||||
|
||||
considerPrintingStats(nsp, SG);
|
||||
|
||||
if (nsi) {
|
||||
nsi_delete(nsi, NSOCK_PENDING_SILENT);
|
||||
}
|
||||
if (nsi)
|
||||
nsock_iod_delete(nsi, NSOCK_PENDING_SILENT);
|
||||
|
||||
handleHostIfDone(SG, target);
|
||||
return;
|
||||
@@ -2233,7 +2235,7 @@ static int launchSomeServiceProbes(nsock_pool nsp, ServiceGroup *SG) {
|
||||
}
|
||||
|
||||
// We start by requesting a connection to the target
|
||||
if ((svc->niod = nsi_new(nsp, svc)) == NULL) {
|
||||
if ((svc->niod = nsock_iod_new(nsp, svc)) == NULL) {
|
||||
fatal("Failed to allocate Nsock I/O descriptor in %s()", __func__);
|
||||
}
|
||||
if (o.debugging > 1) {
|
||||
@@ -2241,10 +2243,10 @@ static int launchSomeServiceProbes(nsock_pool nsp, ServiceGroup *SG) {
|
||||
}
|
||||
if (o.spoofsource) {
|
||||
o.SourceSockAddr(&ss, &ss_len);
|
||||
nsi_set_localaddr(svc->niod, &ss, ss_len);
|
||||
nsock_iod_set_localaddr(svc->niod, &ss, ss_len);
|
||||
}
|
||||
if (o.ipoptionslen)
|
||||
nsi_set_ipoptions(svc->niod, o.ipoptions, o.ipoptionslen);
|
||||
nsock_iod_set_ipoptions(svc->niod, o.ipoptions, o.ipoptionslen);
|
||||
svc->target->TargetSockAddr(&ss, &ss_len);
|
||||
if (svc->proto == IPPROTO_TCP)
|
||||
nsock_connect_tcp(nsp, svc->niod, servicescan_connect_handler,
|
||||
@@ -2282,16 +2284,16 @@ static void servicescan_connect_handler(nsock_pool nsp, nsock_event nse, void *m
|
||||
|
||||
#if HAVE_OPENSSL
|
||||
// Snag our SSL_SESSION from the nsi for use in subsequent connections.
|
||||
if (nsi_checkssl(nsi)) {
|
||||
if (svc->ssl_session ) {
|
||||
if (svc->ssl_session == (SSL_SESSION *)(nsi_get0_ssl_session(nsi))) {
|
||||
if (nsock_iod_check_ssl(nsi)) {
|
||||
if (svc->ssl_session) {
|
||||
if (svc->ssl_session == (SSL_SESSION *)(nsock_iod_get_ssl_session(nsi, 0))) {
|
||||
//nada
|
||||
} else {
|
||||
SSL_SESSION_free((SSL_SESSION*)svc->ssl_session);
|
||||
svc->ssl_session = (SSL_SESSION *)(nsi_get1_ssl_session(nsi));
|
||||
svc->ssl_session = (SSL_SESSION *)(nsock_iod_get_ssl_session(nsi, 1));
|
||||
}
|
||||
} else {
|
||||
svc->ssl_session = (SSL_SESSION *)(nsi_get1_ssl_session(nsi));
|
||||
svc->ssl_session = (SSL_SESSION *)(nsock_iod_get_ssl_session(nsi, 1));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user