1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-14 03:39:02 +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:
henri
2015-06-27 08:21:33 +00:00
parent fd40b8df08
commit b75233ce98
19 changed files with 234 additions and 224 deletions

View File

@@ -180,7 +180,7 @@ void FPNetworkControl::init(const char *ifname, devtype iftype) {
/* If there was a previous nsock pool, delete it */ /* If there was a previous nsock pool, delete it */
if (this->pcap_nsi) { 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) { if (this->nsock_init) {
nsock_event_cancel(this->nsp, this->pcap_ev_id, 0); 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); nsock_pool_set_broadcast(this->nsp, 1);
/* Allocate an NSI for packet capture */ /* 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; this->first_pcap_scheduled = false;
/* Flag it as already initialized so we free this nsp next time */ /* Flag it as already initialized so we free this nsp next time */

View File

@@ -248,20 +248,20 @@ static void connect_report(nsock_iod nsi)
union sockaddr_u peer; union sockaddr_u peer;
zmem(&peer, sizeof(peer.storage)); zmem(&peer, sizeof(peer.storage));
nsi_getlastcommunicationinfo(nsi, NULL, NULL, NULL, nsock_iod_get_communication_info(nsi, NULL, NULL, NULL, &peer.sockaddr,
&peer.sockaddr, sizeof(peer.storage)); sizeof(peer.storage));
if (o.verbose) { if (o.verbose) {
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
if (nsi_checkssl(nsi)) { if (nsock_iod_check_ssl(nsi)) {
X509 *cert; X509 *cert;
X509_NAME *subject; X509_NAME *subject;
char digest_buf[SHA1_STRING_LENGTH + 1]; char digest_buf[SHA1_STRING_LENGTH + 1];
char *fp; 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); ncat_assert(cert != NULL);
subject = X509_get_subject_name(cert); 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); loguser("Connected to %s.\n", peer.un.sun_path);
else else
#endif #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 #else
#if HAVE_SYS_UN_H #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); loguser("Connected to %s.\n", peer.un.sun_path);
else else
#endif #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 #endif
} }
} }
@@ -894,11 +896,11 @@ int ncat_connect(void)
if (!o.proxytype) { if (!o.proxytype) {
/* A non-proxy connection. Create an iod for a new socket. */ /* 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) if (cs.sock_nsi == NULL)
bye("Failed to create nsock_iod."); 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."); bye("Failed to set hostname on iod.");
#if HAVE_SYS_UN_H #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)); strncpy(srcaddr.un.sun_path, tmp_name, sizeof(srcaddr.un.sun_path));
free (tmp_name); 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) if (o.verbose)
loguser("[%s] used as source DGRAM Unix domain socket.\n", srcaddr.un.sun_path); 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: case AF_UNSPEC:
break; break;
case AF_INET: 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; break;
#ifdef AF_INET6 #ifdef AF_INET6
case 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; break;
#endif #endif
#if HAVE_SYS_UN_H #if HAVE_SYS_UN_H
case AF_UNIX: 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; break;
#endif #endif
default: 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; break;
} }
@@ -951,7 +958,7 @@ int ncat_connect(void)
bye("Sorry, -g can only currently be used with IPv4."); bye("Sorry, -g can only currently be used with IPv4.");
ipopts = buildsrcrte(targetss.in.sin_addr, o.srcrtes, o.numsrcrtes, o.srcrteptr, &ipoptslen); 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 */ 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 /* Once the proxy negotiation is done, Nsock takes control of the
socket. */ 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 */ /* 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."); bye("Failed to create stdin nsiod.");
post_connect(mypool, cs.sock_nsi); post_connect(mypool, cs.sock_nsi);
@@ -1043,8 +1050,8 @@ int ncat_connect(void)
gettimeofday(&end_time, NULL); gettimeofday(&end_time, NULL);
time = TIMEVAL_MSEC_SUBTRACT(end_time, start_time) / 1000.0; time = TIMEVAL_MSEC_SUBTRACT(end_time, start_time) / 1000.0;
loguser("%lu bytes sent, %lu bytes received in %.2f seconds.\n", loguser("%lu bytes sent, %lu bytes received in %.2f seconds.\n",
nsi_get_write_count(cs.sock_nsi), nsock_iod_get_write_count(cs.sock_nsi),
nsi_get_read_count(cs.sock_nsi), time); nsock_iod_get_read_count(cs.sock_nsi), time);
} }
#if HAVE_SYS_UN_H #if HAVE_SYS_UN_H
@@ -1078,10 +1085,10 @@ static void connect_handler(nsock_pool nsp, nsock_event evt, void *data)
} }
#ifdef HAVE_OPENSSL #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 /* Check the domain name. ssl_post_connect_check prints an
error message if appropriate. */ 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."); bye("Certificate verification error.");
} }
#endif #endif
@@ -1089,7 +1096,7 @@ static void connect_handler(nsock_pool nsp, nsock_event evt, void *data)
connect_report(cs.sock_nsi); connect_report(cs.sock_nsi);
/* Create IOD for nsp->stdin */ /* 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."); bye("Failed to create stdin nsiod.");
post_connect(nsp, nse_iod(evt)); post_connect(nsp, nse_iod(evt));
@@ -1103,9 +1110,9 @@ static void post_connect(nsock_pool nsp, nsock_iod iod)
if (o.cmdexec) { if (o.cmdexec) {
struct fdinfo info; struct fdinfo info;
info.fd = nsi_getsd(iod); info.fd = nsock_iod_get_sd(iod);
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
info.ssl = (SSL *) nsi_getssl(iod); info.ssl = (SSL *)nsock_iod_get_ssl(iod);
#endif #endif
/* Convert Nsock's non-blocking socket to an ordinary blocking one. It's /* 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 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); ncat_assert(type == NSE_TYPE_READ);
if (status == NSE_STATUS_EOF) { 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. */ /* In --send-only mode or non-TCP mode, exit after EOF on stdin. */
if (o.proto != IPPROTO_TCP || (o.proto == IPPROTO_TCP && o.sendonly)) if (o.proto != IPPROTO_TCP || (o.proto == IPPROTO_TCP && o.sendonly))
nsock_loop_quit(nsp); 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); ncat_delay_timer(o.linedelay);
if (o.telnet) 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 socket data to stdout */
Write(STDOUT_FILENO, buf, nbytes); Write(STDOUT_FILENO, buf, nbytes);

View File

@@ -361,7 +361,7 @@ static void close_dns_servers() {
for(serverI = servs.begin(); serverI != servs.end(); serverI++) { for(serverI = servs.begin(); serverI != servs.end(); serverI++) {
if (serverI->connected) { if (serverI->connected) {
nsi_delete(serverI->nsd, NSOCK_PENDING_SILENT); nsock_iod_delete(serverI->nsd, NSOCK_PENDING_SILENT);
serverI->connected = 0; serverI->connected = 0;
serverI->to_process.clear(); serverI->to_process.clear();
serverI->in_process.clear(); serverI->in_process.clear();
@@ -870,15 +870,15 @@ static void add_dns_server(char *ipaddrs) {
static void connect_dns_servers() { static void connect_dns_servers() {
std::list<dns_server>::iterator serverI; std::list<dns_server>::iterator serverI;
for(serverI = servs.begin(); serverI != servs.end(); 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) { if (o.spoofsource) {
struct sockaddr_storage ss; struct sockaddr_storage ss;
size_t sslen; size_t sslen;
o.SourceSockAddr(&ss, &sslen); o.SourceSockAddr(&ss, &sslen);
nsi_set_localaddr(serverI->nsd, &ss, sslen); nsock_iod_set_localaddr(serverI->nsd, &ss, sslen);
} }
if (o.ipoptionslen) 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->reqs_on_wire = 0;
serverI->capacity = CAPACITY_MIN; serverI->capacity = CAPACITY_MIN;
serverI->write_busy = 0; serverI->write_busy = 0;

View File

@@ -174,7 +174,7 @@ int EchoClient::start(NpingTarget *target, u16 port){
}else{ }else{
/* Extract the nsock pool handler and store it here */ /* Extract the nsock pool handler and store it here */
this->nsp=this->probe.getNsockPool(); 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 */ /* Schedule a TCP connection attempt */
@@ -241,7 +241,7 @@ int EchoClient::nep_connect(NpingTarget *target, u16 port){
#endif #endif
/* Try to bind the IOD to the IP address supplied by the user */ /* 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 */ /* Schedule a connect event */
nsock_connect_tcp(this->nsp, this->nsi, connect_done_handler, ECHO_CONNECT_TIMEOUT, 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 #endif
/* Try to bind the IOD to the IP address supplied by the user */ /* 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 */ /* Schedule a connect event */
nsock_connect_tcp(this->nsp, this->nsi, connect_done_handler, ECHO_CONNECT_TIMEOUT, nsock_connect_tcp(this->nsp, this->nsi, connect_done_handler, ECHO_CONNECT_TIMEOUT,

View File

@@ -180,7 +180,7 @@ NEPContext *EchoServer::getClientContext(clientid_t clnt){
NEPContext *EchoServer::getClientContext(nsock_iod iod){ NEPContext *EchoServer::getClientContext(nsock_iod iod){
nping_print(DBG_4, "%s()", __func__); nping_print(DBG_4, "%s()", __func__);
clientid_t *id=NULL; clientid_t *id=NULL;
if( (id=(clientid_t *)nsi_getud(iod))==NULL ) if( (id=(clientid_t *)nsock_iod_get_udata(iod))==NULL )
return NULL; return NULL;
else else
return this->getClientContext(*id); return this->getClientContext(*id);
@@ -1088,7 +1088,7 @@ int EchoServer::nep_session_ended_handler(nsock_pool nsp, nsock_event nse, void
else else
nping_print(DBG_2, "Deleted client #%d context.", clnt); 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 */ /* Exit the server if --once has been set */
if(o.once()){ if(o.once()){
@@ -1456,7 +1456,7 @@ int EchoServer::start() {
nsock_set_loglevel(nsp, NSOCK_LOG_DBG_ALL); nsock_set_loglevel(nsp, NSOCK_LOG_DBG_ALL);
/* Create new IOD for pcap */ /* 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"); nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n");
/* Open pcap */ /* Open pcap */
@@ -1486,11 +1486,11 @@ int EchoServer::start() {
return OP_FAILURE; return OP_FAILURE;
} }
*idpnt=this->getNewClientID(); *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."); nping_warning(QT_2, "Not enough memory for new clients.");
return OP_FAILURE; return OP_FAILURE;
}else{ }else{
close(client_sd); /* nsi_new2() dups the socket */ close(client_sd); /* nsock_iod_new2() dups the socket */
} }
/* Stop listening if --once is enabled */ /* Stop listening if --once is enabled */

View File

@@ -367,7 +367,7 @@ int ProbeMode::start(){
/* Set up libpcap */ /* Set up libpcap */
if(!o.disablePacketCapture()){ if(!o.disablePacketCapture()){
/* Create new IOD for pcap */ /* 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"); nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n");
/* Open pcap */ /* 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 /* If we are on a Ethernet network, extract the next packet protocol
* from the Ethernet frame. */ * from the Ethernet frame. */
if( nsi_pcap_linktype(nsi) == DLT_EN10MB ){ if( nsock_iod_linktype(nsi) == DLT_EN10MB ){
ethtype=(u16*)(link+12); ethtype=(u16*)(link+12);
*ethtype=ntohs(*ethtype); *ethtype=ntohs(*ethtype);
switch(*ethtype){ switch(*ethtype){
@@ -1945,7 +1945,9 @@ void ProbeMode::probe_tcpconnect_event_handler(nsock_pool nsp, nsock_event nse,
if( mypacket==NULL ) if( mypacket==NULL )
nping_fatal(QT_3, "tcpconnect_event_handler(): NULL value supplied."); nping_fatal(QT_3, "tcpconnect_event_handler(): NULL value supplied.");
/* Determine which target are we dealing with */ /* 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){ if(family==AF_INET6){
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring)); inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
peerport=ntohs(peer6->sin6_port); 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 * 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. */ * get any, so it shouldn't be a big problem. */
if( packetno>(u32)max_iods ){ 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 */ /* 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"); 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 */ /* Set socket source address. This allows setting things like custom source port */
struct sockaddr_storage ss; 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*/ /*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); nsock_connect_tcp(nsp, fds[packetno%max_iods], tcpconnect_event_handler, 100000, mypacket, (struct sockaddr *)&to, sslen, mypacket->dstport);
if( o.showSentPackets() ){ 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 * because there may be other reasons why ge get NSE_STATUS_ERROR so that's
* why we say "Possible TCP RST received". */ * why we say "Possible TCP RST received". */
if ( type == NSE_TYPE_CONNECT ){ 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){ if(family==AF_INET6){
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring)); inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
peerport=ntohs(peer6->sin6_port); 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 * 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. */ * get any, so it shouldn't be a big problem. */
if( packetno>(u32)max_iods ){ 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 */ /* 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"); nping_fatal(QT_3, "Failed to create new nsock_iod. QUITTING.\n");
/* Set socket source address. This allows setting things like custom source port */ /* Set socket source address. This allows setting things like custom source port */
struct sockaddr_storage ss; 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 /* 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: case NSE_TYPE_WRITE:
/* Determine which target are we dealing with */ /* 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){ if(family==AF_INET6){
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring)); inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
peerport=ntohs(peer6->sin6_port); 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"); nping_fatal(QT_3, "Error: nse_readbuff failed to read in the from the probe");
} }
/* Determine which target are we dealing with */ /* 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){ if(family==AF_INET6){
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring)); inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
peerport=ntohs(peer6->sin6_port); 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) { } else if (status == NSE_STATUS_EOF) {
nping_print(DBG_4, "udpunpriv_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n"); nping_print(DBG_4, "udpunpriv_event_handler(): Unexpected behaviour: Got EOF. Please report this bug.\n");
} else if (status == NSE_STATUS_ERROR) { } 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){ if(family==AF_INET6){
inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring)); inet_ntop(AF_INET6, &peer6->sin6_addr, ipstring, sizeof(ipstring));
peerport=ntohs(peer6->sin6_port); peerport=ntohs(peer6->sin6_port);

View File

@@ -295,7 +295,7 @@ static void trace (nsock_iod nsiod, const char *message, const char *dir)
{ {
if (o.scriptTrace()) if (o.scriptTrace())
{ {
if (!nsi_is_pcap(nsiod)) if (!nsock_iod_is_pcap(nsiod))
{ {
int protocol; int protocol;
int af; 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 local;
struct sockaddr_storage remote; struct sockaddr_storage remote;
nsi_getlastcommunicationinfo(nsiod, &protocol, &af, nsock_iod_get_communication_info(nsiod, &protocol, &af,
(sockaddr *) &local, (sockaddr *) &remote, sizeof(sockaddr_storage)); (sockaddr *) &local, (sockaddr *) &remote, sizeof(sockaddr_storage));
log_write(LOG_STDOUT, "%s: %s %s:%d %s %s:%d | %s\n", log_write(LOG_STDOUT, "%s: %s %s:%d %s %s:%d | %s\n",
SCRIPT_ENGINE, SCRIPT_ENGINE,
@@ -381,17 +381,17 @@ static nse_nsock_udata *check_nsock_udata (lua_State *L, int idx, bool open)
nsock_pool nsp; nsock_pool nsp;
nsp = get_pool(L); 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) { 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) { } else if (o.spoofsource) {
struct sockaddr_storage ss; struct sockaddr_storage ss;
size_t sslen; size_t sslen;
o.SourceSockAddr(&ss, &sslen); o.SourceSockAddr(&ss, &sslen);
nsi_set_localaddr(nu->nsiod, &ss, sslen); nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
} }
if (o.ipoptionslen) 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) { 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)", 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) if (nu->nsiod != NULL)
close_internal(L, nu); 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) { 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) { } else if (o.spoofsource) {
struct sockaddr_storage ss; struct sockaddr_storage ss;
size_t sslen; size_t sslen;
o.SourceSockAddr(&ss, &sslen); o.SourceSockAddr(&ss, &sslen);
nsi_set_localaddr(nu->nsiod, &ss, sslen); nsock_iod_set_localaddr(nu->nsiod, &ss, sslen);
} }
if (o.ipoptionslen) 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 (targetname != NULL) {
if (nsi_set_hostname(nu->nsiod, targetname) == -1) if (nsock_iod_set_hostname(nu->nsiod, targetname) == -1)
fatal("nsi_set_hostname(\"%s\" failed in %s()", targetname, __func__); fatal("nsock_iod_set_hostname(\"%s\" failed in %s()", targetname, __func__);
} }
nu->af = dest->ai_addr->sa_family; 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_local = (char *) lua_newuserdata(L, sizeof(char) * INET6_ADDRSTRLEN);
char *ipstring_remote = (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, (struct sockaddr*)&local, (struct sockaddr*)&remote,
sizeof(struct sockaddr_storage)); 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); 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"); luaL_argerror(L, 1, "not a SSL socket");
return (SSL *) nsi_getssl(nu->nsiod); return (SSL *) nsock_iod_get_ssl(nu->nsiod);
} }
#else #else
/* If HAVE_OPENSSL is defined, these come from nse_ssl_cert.cc. */ /* 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 ignore any results after the first. */
/* We would just call nsi_set_localaddr here, but nu->nsiod is not created /* We would just call nsock_iod_set_localaddr here, but nu->nsiod is not
until connect. So store the address in the userdatum. */ * created until connect. So store the address in the userdatum. */
nu->source_addrlen = results->ai_addrlen; nu->source_addrlen = results->ai_addrlen;
memcpy(&nu->source_addr, results->ai_addr, nu->source_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); SSL_SESSION_free((SSL_SESSION *) nu->ssl_session);
#endif #endif
if (!nu->is_pcap) { /* pcap sockets are closed by pcap_gc */ 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; 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) static int pcap_gc (lua_State *L)
{ {
nsock_iod *nsiod = (nsock_iod *) lua_touserdata(L, 1); nsock_iod *nsiod = (nsock_iod *) lua_touserdata(L, 1);
nsi_delete(*nsiod, NSOCK_PENDING_NOTIFY); nsock_iod_delete(*nsiod, NSOCK_PENDING_NOTIFY);
*nsiod = NULL; *nsiod = NULL;
return 0; return 0;
} }
@@ -984,7 +984,7 @@ static int l_pcap_open (lua_State *L)
nsiod = (nsock_iod *) lua_newuserdata(L, sizeof(nsock_iod)); nsiod = (nsock_iod *) lua_newuserdata(L, sizeof(nsock_iod));
lua_pushvalue(L, PCAP_SOCKET); lua_pushvalue(L, PCAP_SOCKET);
lua_setmetatable(L, -2); 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, 7); /* the pcap socket key */
lua_pushvalue(L, -2); /* the pcap socket nsiod */ lua_pushvalue(L, -2); /* the pcap socket nsiod */
lua_rawset(L, KEY_PCAP); /* KEY_PCAP["dev|snap|promis|bpf"] = pcap_nsiod */ lua_rawset(L, KEY_PCAP); /* KEY_PCAP["dev|snap|promis|bpf"] = pcap_nsiod */

View File

@@ -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 * 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() * 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 * 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 * destroy the iod for good with nsock_iod_delete() and allocate a new one via
* for your next connection. */ * nsock_iod_new for your next connection. */
typedef struct niod *nsock_iod; typedef struct niod *nsock_iod;
/* An event is created when you do various calls (for reading, writing, /* 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() */ * if the status is NSOCK_LOOP_ERROR was returned by nsock_loop() */
int nsock_pool_get_errorcode(nsock_pool nsp); 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 /* Note that nsock_iod_get_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 * SSL_SESSION if inc_ref is not zero, since nsock does a free when the IOD
* any calling function/etc to do a SSL_SESSION_free() on it. * is destroyed. It's up to any calling function/etc to do a SSL_SESSION_free()
* nsi_get0_ssl_session doesn't increment, and is for informational purposes * on it. Passing in inc_ref=0 doesn't increment, and is for informational
* only. */ * purposes only. */
nsock_ssl_session nsi_get1_ssl_session(nsock_iod nsockiod); nsock_ssl_session nsock_iod_get_ssl_session(nsock_iod nsockiod, int inc_ref);
nsock_ssl_session nsi_get0_ssl_session(nsock_iod nsockiod);
/* Sometimes it is useful to store a pointer to information inside the NSP so /* Sometimes it is useful to store a pointer to information inside the NSP so
* you can retrieve it during a callback. */ * 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 nse_iod(nsock_event nse);
/* nsock_iod is like a "file descriptor" for the nsock library. You use it to /* 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
* NULL if the iod cannot be allocated. Pass NULL as userdata if you don't want * returns NULL if the iod cannot be allocated. Pass NULL as udata if you
* to immediately associate any user data with the iod. */ * don't want to immediately associate any user data with the IOD. */
nsock_iod nsi_new(nsock_pool nsockp, void *userdata); 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 /* 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 * 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 * 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 * 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 * dup()ed, so you may close or otherwise manipulate your copy. The duped copy
* will be destroyed when the nsi is destroyed */ * will be destroyed when the IOD is destroyed */
nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata); 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 /* If nsock_iod_new returned success, you must free the iod when you are done
* it to conserve memory (and in some cases, sockets). After this call, * 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 * 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 * 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 * notification to each event), NSOCK_PENDING_SILENT (do not send notification
* to the killed events), or NSOCK_PENDING_ERROR (print an error message and * to the killed events), or NSOCK_PENDING_ERROR (print an error message and
@@ -398,15 +397,15 @@ enum nsock_del_mode {
NSOCK_PENDING_ERROR, 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 /* Sometimes it is useful to store a pointer to information inside
* the nsiod so you can retrieve it during a callback. */ * 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 /* And the function above wouldn't make much sense if we didn't have a way to
* retrieve that data ... */ * 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 /* 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 * 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 * "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 * create havok by closing the descriptor! If the descriptor you get back is
* -1, the iod does not currently possess a valid descriptor */ * -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 /* 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). */ * 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 */ /* 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 */ /* 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 */ /* 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 /* 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 * is a whole int so that -1 can be distinguished from 65535. Port is returned
* in host byte order. */ * 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() */ /* 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, /* 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 * so you can free() yours if necessary. This copy is freed when the iod is
* destroyed */ * 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 /* Returns that host/port/protocol information for the last communication (or
* comm. attempt) this nsi has been involved with. By "involved" with I mean * 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, * address space. The sockaddr members should actually be sockaddr_storage,
* sockaddr_in6, or sockaddr_in with the socklen of them set appropriately (eg * sockaddr_in6, or sockaddr_in with the socklen of them set appropriately (eg
* sizeof(sockaddr_storage) if that is what you are passing). */ * 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 /* Set the hostname of the remote host, for when that matters. This is currently
* only used for Server Name Indication in SSL connections. */ * 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 /* 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 *l2_len, const unsigned char **l3_data, size_t *l3_len,
size_t *packet_len, struct timeval *ts); size_t *packet_len, struct timeval *ts);
/* Well. Just pcap-style datalink. Like DLT_EN10MB or DLT_SLIP. Check in pcap(3) manpage. */ /* Well. Just pcap-style datalink.
int nsi_pcap_linktype(nsock_iod nsiod); * Like DLT_EN10MB or DLT_SLIP. Check in pcap(3) manpage. */
int nsock_iod_linktype(nsock_iod iod);
/* Is this nsiod a pcap descriptor? */ /* Is this nsiod a pcap descriptor? */
int nsi_is_pcap(nsock_iod nsiod); int nsock_iod_is_pcap(nsock_iod iod);
#endif /* HAVE_PCAP */ #endif /* HAVE_PCAP */

View File

@@ -179,7 +179,7 @@ int epoll_iod_register(struct npool *nsp, struct niod *iod, int ev) {
if (ev & EV_EXCEPT) if (ev & EV_EXCEPT)
epev.events |= EPOLL_X_FLAGS; 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) if (epoll_ctl(einfo->epfd, EPOLL_CTL_ADD, sd, &epev) < 0)
fatal("Unable to register IOD #%lu: %s", iod->id, strerror(errno)); 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; struct epoll_engine_info *einfo = (struct epoll_engine_info *)nsp->engine_data;
int sd; int sd;
sd = nsi_getsd(iod); sd = nsock_iod_get_sd(iod);
epoll_ctl(einfo->epfd, EPOLL_CTL_DEL, sd, NULL); epoll_ctl(einfo->epfd, EPOLL_CTL_DEL, sd, NULL);
IOD_PROPCLR(iod, IOD_REGISTERED); 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) if (iod->watched_events & EV_EXCEPT)
epev.events |= EPOLL_X_FLAGS; 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) if (epoll_ctl(einfo->epfd, EPOLL_CTL_MOD, sd, &epev) < 0)
fatal("Unable to update events for IOD #%lu: %s", iod->id, strerror(errno)); fatal("Unable to update events for IOD #%lu: %s", iod->id, strerror(errno));

View File

@@ -161,8 +161,8 @@ int kqueue_iod_register(struct npool *nsp, struct niod *iod, int ev) {
kqueue_iod_modify(nsp, iod, ev, EV_NONE); kqueue_iod_modify(nsp, iod, ev, EV_NONE);
if (nsi_getsd(iod) > kinfo->maxfd) if (nsock_iod_get_sd(iod) > kinfo->maxfd)
kinfo->maxfd = nsi_getsd(iod); kinfo->maxfd = nsock_iod_get_sd(iod);
return 1; 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); kqueue_iod_modify(nsp, iod, EV_NONE, EV_READ|EV_WRITE);
IOD_PROPCLR(iod, IOD_REGISTERED); IOD_PROPCLR(iod, IOD_REGISTERED);
if (nsi_getsd(iod) == kinfo->maxfd) if (nsock_iod_get_sd(iod) == kinfo->maxfd)
kinfo->maxfd--; kinfo->maxfd--;
} }
iod->watched_events = EV_NONE; 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; i = 0;
if ((ev_set ^ ev_clr) & EV_READ) { 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++; i++;
} }
if ((ev_set ^ ev_clr) & EV_WRITE) { 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++; i++;
} }

View File

@@ -220,7 +220,7 @@ int poll_iod_register(struct npool *nsp, struct niod *iod, int ev) {
iod->watched_events = ev; iod->watched_events = ev;
sd = nsi_getsd(iod); sd = nsock_iod_get_sd(iod);
while (pinfo->capacity < sd + 1) while (pinfo->capacity < sd + 1)
evlist_grow(pinfo); 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; struct poll_engine_info *pinfo = (struct poll_engine_info *)nsp->engine_data;
int sd; int sd;
sd = nsi_getsd(iod); sd = nsock_iod_get_sd(iod);
pinfo->events[sd].fd = -1; pinfo->events[sd].fd = -1;
pinfo->events[sd].events = 0; pinfo->events[sd].events = 0;
pinfo->events[sd].revents = 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; iod->watched_events = new_events;
sd = nsi_getsd(iod); sd = nsock_iod_get_sd(iod);
pinfo->events[sd].fd = sd; pinfo->events[sd].fd = sd;
pinfo->events[sd].events = 0; pinfo->events[sd].events = 0;

View File

@@ -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_set;
iod->watched_events &= ~ev_clr; iod->watched_events &= ~ev_clr;
sd = nsi_getsd(iod); sd = nsock_iod_get_sd(iod);
/* -- set events -- */ /* -- set events -- */
if (ev_set & EV_READ) if (ev_set & EV_READ)

View File

@@ -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, * address space. The sockaddr members should actually be sockaddr_storage,
* sockaddr_in6, or sockaddr_in with the socklen of them set appropriately (eg * sockaddr_in6, or sockaddr_in with the socklen of them set appropriately (eg
* sizeof(sockaddr_storage) if that is what you are passing). */ * 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 sockaddr *remote, size_t socklen) {
struct niod *nsi = (struct niod *)ms_iod; struct niod *nsi = (struct niod *)iod;
int ret = 1; int ret = 1;
struct sockaddr_storage sock; struct sockaddr_storage ss;
socklen_t slen = sizeof(struct sockaddr_storage); socklen_t slen = sizeof(ss);
int res; int res;
assert(socklen > 0); assert(socklen > 0);
@@ -525,13 +526,13 @@ int nsi_getlastcommunicationinfo(nsock_iod ms_iod, int *protocol, int *af, struc
} }
if (local) { if (local) {
if (nsi->sd >= 0) { if (nsi->sd >= 0) {
res = getsockname(nsi->sd, (struct sockaddr *)&sock, &slen); res = getsockname(nsi->sd, (struct sockaddr *)&ss, &slen);
if (res == -1) { if (res == -1) {
memset(local, 0, socklen); memset(local, 0, socklen);
ret = 0; ret = 0;
} else { } else {
assert(slen > 0); assert(slen > 0);
memcpy(local, &sock, MIN((unsigned)slen, socklen)); memcpy(local, &ss, MIN((unsigned)slen, socklen));
} }
} else { } else {
memset(local, 0, socklen); memset(local, 0, socklen);

View File

@@ -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 /* 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 * 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 * was initialized with nsock_pool_ssl_init_max_speed. Try reconnecting
* SSL_OP_NO_SSLv2. Never downgrade a NO_SSLv2 connection to one that * with SSL_OP_NO_SSLv2. Never downgrade a NO_SSLv2 connection to one
* might use SSLv2. */ * that might use SSLv2. */
nsock_log_info(ms, "EID %li reconnecting with SSL_OP_NO_SSLv2", nse->id); nsock_log_info(ms, "EID %li reconnecting with SSL_OP_NO_SSLv2", nse->id);
saved_ev = iod->watched_events; saved_ev = iod->watched_events;
nsock_engine_iod_unregister(ms, iod); nsock_engine_iod_unregister(ms, iod);
close(iod->sd); close(iod->sd);
nsock_connect_internal(ms, nse, SOCK_STREAM, iod->lastproto, &iod->peer, 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); nsock_engine_iod_register(ms, iod, saved_ev);
SSL_clear(iod->ssl); SSL_clear(iod->ssl);

View File

@@ -120,7 +120,7 @@ enum iod_state {
NSIOD_STATE_DELETED, NSIOD_STATE_DELETED,
NSIOD_STATE_INITIAL, 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_UNKNOWN,
NSIOD_STATE_CONNECTED_TCP, NSIOD_STATE_CONNECTED_TCP,

View File

@@ -71,11 +71,11 @@
/* nsock_iod is like a "file descriptor" for the nsock library. You use it to /* 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 * 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. */ * to immediately associate any user data with the iod. */
nsock_iod nsi_new(nsock_pool nsockp, void *userdata) { nsock_iod nsock_iod_new(nsock_pool nsockp, void *userdata) {
return nsi_new2(nsockp, -1, userdata); return nsock_iod_new2(nsockp, -1, userdata);
} }
/* This version allows you to associate an existing sd with the msi so that you /* 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 * 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 * dup()ed, so you may close or otherwise manipulate your copy. The duped copy
* will be destroyed when the nsi is destroyed. */ * 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; struct npool *nsp = (struct npool *)nsockp;
gh_lnode_t *lnode; gh_lnode_t *lnode;
struct niod *nsi; 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 */ /* The nsp keeps track of active iods so it can delete them if it is deleted */
gh_list_append(&nsp->active_iods, &nsi->nodeq); 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; return (nsock_iod)nsi;
} }
@@ -161,15 +161,15 @@ nsock_iod nsi_new2(nsock_pool nsockp, int sd, void *userdata) {
/* Defined in nsock_core.c. */ /* Defined in nsock_core.c. */
int socket_count_zero(struct niod *iod, struct npool *ms); 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, * 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 * 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 * 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 * notification to each event), NSOCK_PENDING_SILENT (do not send notification
* to the killed events), or NSOCK_PENDING_ERROR (print an error message and * to the killed events), or NSOCK_PENDING_ERROR (print an error message and
* quit the program) */ * 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; struct niod *nsi = (struct niod *)nsockiod;
gh_lnode_t *evlist_ar[3]; gh_lnode_t *evlist_ar[3];
gh_list_t *corresp_list[3]; gh_list_t *corresp_list[3];
@@ -184,7 +184,7 @@ void nsi_delete(nsock_iod nsockiod, enum nsock_del_mode pending_response) {
return; 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) { if (nsi->events_pending > 0) {
/* shit -- they killed the struct niod while an event was still pending on it. /* 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 * by just locating the events here by searching through the active events
* list */ * list */
if (pending_response == NSOCK_PENDING_ERROR) 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); 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 #endif
if (SSL_shutdown(nsi->ssl) == -1) { 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); 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 /* 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). */ * 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); assert(nsockiod);
return ((struct niod *)nsockiod)->id; return ((struct niod *)nsockiod)->id;
} }
/* Returns the SSL object inside an nsock_iod, or NULL if unset. */ /* 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 #if HAVE_OPENSSL
return ((struct niod *)nsockiod)->ssl; return ((struct niod *)iod)->ssl;
#else #else
return NULL; return NULL;
#endif #endif
} }
/* Returns the SSL_SESSION of an nsock_iod, and increments its usage count. */ /* Returns the SSL_SESSION of an nsock_iod.
nsock_ssl_session nsi_get1_ssl_session(nsock_iod nsockiod) { * 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 #if HAVE_OPENSSL
return SSL_get1_session(((struct niod *)nsockiod)->ssl); if (inc_ref)
#else return SSL_get1_session(((struct niod *)iod)->ssl);
return NULL; else
#endif return SSL_get0_session(((struct niod *)iod)->ssl);
}
/* 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);
#else #else
return NULL; return NULL;
#endif #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 /* Sometimes it is useful to store a pointer to information inside the struct niod so
* you can retrieve it during a callback. */ * you can retrieve it during a callback. */
void nsi_setud(nsock_iod nsockiod, void *data) { void nsock_iod_set_udata(nsock_iod iod, void *udata) {
assert(nsockiod); assert(iod);
((struct niod *)nsockiod)->userdata = data; ((struct niod *)iod)->userdata = udata;
} }
/* And the function above wouldn't make much sense if we didn't have a way to /* And the function above wouldn't make much sense if we didn't have a way to
* retrieve that data... */ * retrieve that data... */
void *nsi_getud(nsock_iod nsockiod) { void *nsock_iod_get_udata(nsock_iod iod) {
assert(nsockiod); assert(iod);
return ((struct niod *)nsockiod)->userdata; return ((struct niod *)iod)->userdata;
} }
/* Returns 1 if an NSI is communicating via SSL, 0 otherwise. */ /* 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) {
return (((struct niod *)nsockiod)->ssl) ? 1 : 0; return (((struct niod *)iod)->ssl) ? 1 : 0;
} }
/* Returns the remote peer port (or -1 if unavailable). Note the return value /* 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 * is a whole int so that -1 can be distinguished from 65535. Port is returned
* in host byte order. */ * in host byte order. */
int nsi_peerport(nsock_iod nsockiod) { int nsock_iod_get_peerport(nsock_iod iod) {
struct niod *nsi = (struct niod *)nsockiod; struct niod *nsi = (struct niod *)iod;
int fam; int fam;
if (nsi->peerlen <= 0) if (nsi->peerlen <= 0)
@@ -377,33 +372,34 @@ int nsi_peerport(nsock_iod nsockiod) {
} }
/* Sets the local address to bind to before connect() */ /* 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,
struct niod *iod = (struct niod *)nsi; 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; return -1;
memcpy(&iod->local, ss, sslen); memcpy(&nsi->local, ss, sslen);
iod->locallen = sslen; nsi->locallen = sslen;
return 0; return 0;
} }
/* Sets IPv4 options to apply before connect(). It makes a copy of the options, /* 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 * so you can free() yours if necessary. This copy is freed when the iod is
* destroyed. */ * destroyed. */
int nsi_set_ipoptions(nsock_iod nsi, void *opts, size_t optslen) { int nsock_iod_set_ipoptions(nsock_iod iod, void *opts, size_t optslen) {
struct niod *iod = (struct niod *)nsi; struct niod *nsi = (struct niod *)iod;
assert(iod); assert(nsi);
if (optslen > 44) if (optslen > 44)
return -1; return -1;
iod->ipopts = safe_malloc(optslen); nsi->ipopts = safe_malloc(optslen);
memcpy(iod->ipopts, opts, optslen); memcpy(nsi->ipopts, opts, optslen);
iod->ipoptslen = optslen; nsi->ipoptslen = optslen;
return 0; 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 * "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 * create havok by closing the descriptor! If the descriptor you get back is
* -1, the iod does not currently possess a valid descriptor */ * -1, the iod does not currently possess a valid descriptor */
int nsi_getsd(nsock_iod nsockiod) { int nsock_iod_get_sd(nsock_iod iod) {
struct niod *iod = (struct niod *)nsockiod; struct niod *nsi = (struct niod *)iod;
assert(nsockiod); assert(nsi);
#if HAVE_PCAP #if HAVE_PCAP
if (iod->pcap) if (nsi->pcap)
return ((mspcap *)iod->pcap)->pcap_desc; return ((mspcap *)nsi->pcap)->pcap_desc;
else else
#endif #endif
return iod->sd; return nsi->sd;
} }
unsigned long nsi_get_read_count(nsock_iod nsockiod){ unsigned long nsock_iod_get_read_count(nsock_iod iod){
assert(nsockiod); assert(iod);
return ((struct niod *)nsockiod)->read_count; return ((struct niod *)iod)->read_count;
} }
unsigned long nsi_get_write_count(nsock_iod nsockiod){ unsigned long nsock_iod_get_write_count(nsock_iod iod){
assert(nsockiod); assert(iod);
return ((struct niod *)nsockiod)->write_count; return ((struct niod *)iod)->write_count;
} }
int nsi_set_hostname(nsock_iod nsi, const char *hostname) { int nsock_iod_set_hostname(nsock_iod iod, const char *hostname) {
struct niod *iod = (struct niod *)nsi; struct niod *nsi = (struct niod *)iod;
if (iod->hostname != NULL) if (nsi->hostname != NULL)
free(iod->hostname); free(nsi->hostname);
iod->hostname = strdup(hostname); nsi->hostname = strdup(hostname);
if (iod->hostname == NULL) if (nsi->hostname == NULL)
return -1; return -1;
return 0; return 0;

View File

@@ -476,16 +476,16 @@ void nse_readpcap(nsock_event nsev, const unsigned char **l2_data, size_t *l2_le
return; return;
} }
int nsi_pcap_linktype(nsock_iod nsiod) { int nsock_iod_linktype(nsock_iod iod) {
struct niod *nsi = (struct niod *)nsiod; struct niod *nsi = (struct niod *)iod;
mspcap *mp = (mspcap *)nsi->pcap; mspcap *mp = (mspcap *)nsi->pcap;
assert(mp); assert(mp);
return (mp->datalink); return (mp->datalink);
} }
int nsi_is_pcap(nsock_iod nsiod) { int nsock_iod_is_pcap(nsock_iod iod) {
struct niod *nsi = (struct niod *)nsiod; struct niod *nsi = (struct niod *)iod;
mspcap *mp = (mspcap *)nsi->pcap; mspcap *mp = (mspcap *)nsi->pcap;
return (mp != NULL); return (mp != NULL);

View File

@@ -265,7 +265,7 @@ void nsock_pool_delete(nsock_pool ms_pool) {
next = gh_lnode_next(current); next = gh_lnode_next(current);
nsi = container_of(current, struct niod, nodeq); 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_remove(&nsp->active_iods, current);
gh_list_prepend(&nsp->free_iods, &nsi->nodeq); gh_list_prepend(&nsp->free_iods, &nsi->nodeq);

View File

@@ -2025,19 +2025,20 @@ static void startNextProbe(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
if (probe) { if (probe) {
// For a TCP probe, we start by requesting a new connection to the target // For a TCP probe, we start by requesting a new connection to the target
if (svc->proto == IPPROTO_TCP) { if (svc->proto == IPPROTO_TCP) {
nsi_delete(nsi, NSOCK_PENDING_SILENT); nsock_iod_delete(nsi, NSOCK_PENDING_SILENT);
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__); fatal("Failed to allocate Nsock I/O descriptor in %s()", __func__);
} }
if (o.spoofsource) { if (o.spoofsource) {
o.SourceSockAddr(&ss, &ss_len); 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) 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 (svc->target->TargetName()) {
if (nsi_set_hostname(svc->niod, svc->target->TargetName()) == -1) if (nsock_iod_set_hostname(svc->niod, svc->target->TargetName()) == -1)
fatal("nsi_set_hostname(\"%s\" failed in %s()", svc->target->TargetName(), __func__); fatal("nsock_iod_set_hostname(\"%s\" failed in %s()",
svc->target->TargetName(), __func__);
} }
svc->target->TargetSockAddr(&ss, &ss_len); svc->target->TargetSockAddr(&ss, &ss_len);
if (svc->tunnel == SERVICE_TUNNEL_NONE) { if (svc->tunnel == SERVICE_TUNNEL_NONE) {
@@ -2063,8 +2064,10 @@ static void startNextProbe(nsock_pool nsp, nsock_iod nsi, ServiceGroup *SG,
} }
} else { } else {
// No more probes remaining! Failed to match // No more probes remaining! Failed to match
nsi_delete(nsi, NSOCK_PENDING_SILENT); nsock_iod_delete(nsi, NSOCK_PENDING_SILENT);
end_svcprobe(nsp, (svc->softMatchFound)? PROBESTATE_FINISHED_SOFTMATCHED : PROBESTATE_FINISHED_NOMATCH, SG, svc, NULL); end_svcprobe(nsp, (svc->softMatchFound)? PROBESTATE_FINISHED_SOFTMATCHED :
PROBESTATE_FINISHED_NOMATCH,
SG, svc, NULL);
} }
} }
return; return;
@@ -2195,9 +2198,8 @@ static void end_svcprobe(nsock_pool nsp, enum serviceprobestate probe_state, Ser
considerPrintingStats(nsp, SG); considerPrintingStats(nsp, SG);
if (nsi) { if (nsi)
nsi_delete(nsi, NSOCK_PENDING_SILENT); nsock_iod_delete(nsi, NSOCK_PENDING_SILENT);
}
handleHostIfDone(SG, target); handleHostIfDone(SG, target);
return; return;
@@ -2233,7 +2235,7 @@ static int launchSomeServiceProbes(nsock_pool nsp, ServiceGroup *SG) {
} }
// We start by requesting a connection to the target // 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__); fatal("Failed to allocate Nsock I/O descriptor in %s()", __func__);
} }
if (o.debugging > 1) { if (o.debugging > 1) {
@@ -2241,10 +2243,10 @@ static int launchSomeServiceProbes(nsock_pool nsp, ServiceGroup *SG) {
} }
if (o.spoofsource) { if (o.spoofsource) {
o.SourceSockAddr(&ss, &ss_len); 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) 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); svc->target->TargetSockAddr(&ss, &ss_len);
if (svc->proto == IPPROTO_TCP) if (svc->proto == IPPROTO_TCP)
nsock_connect_tcp(nsp, svc->niod, servicescan_connect_handler, 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 #if HAVE_OPENSSL
// Snag our SSL_SESSION from the nsi for use in subsequent connections. // Snag our SSL_SESSION from the nsi for use in subsequent connections.
if (nsi_checkssl(nsi)) { if (nsock_iod_check_ssl(nsi)) {
if (svc->ssl_session ) { if (svc->ssl_session) {
if (svc->ssl_session == (SSL_SESSION *)(nsi_get0_ssl_session(nsi))) { if (svc->ssl_session == (SSL_SESSION *)(nsock_iod_get_ssl_session(nsi, 0))) {
//nada //nada
} else { } else {
SSL_SESSION_free((SSL_SESSION*)svc->ssl_session); 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 { } else {
svc->ssl_session = (SSL_SESSION *)(nsi_get1_ssl_session(nsi)); svc->ssl_session = (SSL_SESSION *)(nsock_iod_get_ssl_session(nsi, 1));
} }
} }
#endif #endif