1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-20 14:39:02 +00:00

More code cleaning: whitespace and indentation fixes.

This commit is contained in:
henri
2012-01-20 08:26:14 +00:00
parent 8dd5bc49ca
commit 9c7f72108b
3 changed files with 145 additions and 146 deletions

View File

@@ -363,7 +363,7 @@ void iterate_through_event_lists(mspool *nsp) {
timer_last = GH_LIST_LAST_ELEM(&nsp->timer_events); timer_last = GH_LIST_LAST_ELEM(&nsp->timer_events);
for (current = GH_LIST_FIRST_ELEM(&nsp->active_iods); for (current = GH_LIST_FIRST_ELEM(&nsp->active_iods);
current != NULL && GH_LIST_ELEM_PREV(current) != last; current = next) { current != NULL && GH_LIST_ELEM_PREV(current) != last; current = next) {
msiod *nsi = (msiod *)GH_LIST_ELEM_DATA(current); msiod *nsi = (msiod *)GH_LIST_ELEM_DATA(current);
if (nsi->state != NSIOD_STATE_DELETED && nsi->events_pending) { if (nsi->state != NSIOD_STATE_DELETED && nsi->events_pending) {
@@ -395,7 +395,7 @@ void iterate_through_event_lists(mspool *nsp) {
/* iterate through timers */ /* iterate through timers */
for (current = GH_LIST_FIRST_ELEM(&nsp->timer_events); for (current = GH_LIST_FIRST_ELEM(&nsp->timer_events);
current != NULL && GH_LIST_ELEM_PREV(current) != timer_last; current = next) { current != NULL && GH_LIST_ELEM_PREV(current) != timer_last; current = next) {
msevent *nse = (msevent *)GH_LIST_ELEM_DATA(current); msevent *nse = (msevent *)GH_LIST_ELEM_DATA(current);

View File

@@ -180,7 +180,6 @@ static int socket_count_dec_ssl_desire(msevent *nse) {
* If this counter reaches zero, the event won't be watched anymore by the * If this counter reaches zero, the event won't be watched anymore by the
* IO engine for this IOD. * IO engine for this IOD.
*/ */
static void update_events(msiod * iod, mspool *ms, int ev_inc, int ev_dec) { static void update_events(msiod * iod, mspool *ms, int ev_inc, int ev_dec) {
int setmask, clrmask; int setmask, clrmask;
@@ -223,60 +222,60 @@ static void update_events(msiod * iod, mspool *ms, int ev_inc, int ev_dec) {
*/ */
static int iod_add_event(msiod *iod, msevent *nse) { static int iod_add_event(msiod *iod, msevent *nse) {
switch(nse->type) { switch(nse->type) {
case NSE_TYPE_CONNECT: case NSE_TYPE_CONNECT:
case NSE_TYPE_CONNECT_SSL: case NSE_TYPE_CONNECT_SSL:
if (iod->first_connect) if (iod->first_connect)
iod->first_connect = gh_list_insert_before(&iod->nsp->connect_events, iod->first_connect, nse); iod->first_connect = gh_list_insert_before(&iod->nsp->connect_events, iod->first_connect, nse);
else else
iod->first_connect = gh_list_append(&iod->nsp->connect_events, nse); iod->first_connect = gh_list_append(&iod->nsp->connect_events, nse);
break; break;
case NSE_TYPE_READ: case NSE_TYPE_READ:
if (iod->first_read)
iod->first_read = gh_list_insert_before(&iod->nsp->read_events, iod->first_read, nse);
else
iod->first_read = gh_list_append(&iod->nsp->read_events, nse);
break;
case NSE_TYPE_WRITE:
if (iod->first_write)
iod->first_write = gh_list_insert_before(&iod->nsp->write_events, iod->first_write, nse);
else
iod->first_write = gh_list_append(&iod->nsp->write_events, nse);
break;
#if HAVE_PCAP
case NSE_TYPE_PCAP_READ: {
char add_read = 0, add_pcap_read = 0;
#if PCAP_BSD_SELECT_HACK
/* BSD hack mode: add event to both read and pcap_read lists */
add_read = add_pcap_read = 1;
#else
if (((mspcap *)iod->pcap)->pcap_desc >= 0) {
add_read = 1;
} else {
add_pcap_read = 1;
}
#endif
if (add_read) {
if (iod->first_read) if (iod->first_read)
iod->first_read = gh_list_insert_before(&iod->nsp->read_events, iod->first_read, nse); iod->first_read = gh_list_insert_before(&iod->nsp->read_events, iod->first_read, nse);
else else
iod->first_read = gh_list_append(&iod->nsp->read_events, nse); iod->first_read = gh_list_append(&iod->nsp->read_events, nse);
break;
case NSE_TYPE_WRITE:
if (iod->first_write)
iod->first_write = gh_list_insert_before(&iod->nsp->write_events, iod->first_write, nse);
else
iod->first_write = gh_list_append(&iod->nsp->write_events, nse);
break;
#if HAVE_PCAP
case NSE_TYPE_PCAP_READ: {
char add_read = 0, add_pcap_read = 0;
#if PCAP_BSD_SELECT_HACK
/* BSD hack mode: add event to both read and pcap_read lists */
add_read = add_pcap_read = 1;
#else
if (((mspcap *)iod->pcap)->pcap_desc >= 0) {
add_read = 1;
} else {
add_pcap_read = 1;
}
#endif
if (add_read) {
if (iod->first_read)
iod->first_read = gh_list_insert_before(&iod->nsp->read_events, iod->first_read, nse);
else
iod->first_read = gh_list_append(&iod->nsp->read_events, nse);
}
if (add_pcap_read) {
if (iod->first_pcap_read)
iod->first_pcap_read = gh_list_insert_before(&iod->nsp->pcap_read_events, iod->first_pcap_read, nse);
else
iod->first_pcap_read = gh_list_append(&iod->nsp->pcap_read_events, nse);
}
break;
} }
if (add_pcap_read) {
if (iod->first_pcap_read)
iod->first_pcap_read = gh_list_insert_before(&iod->nsp->pcap_read_events, iod->first_pcap_read, nse);
else
iod->first_pcap_read = gh_list_append(&iod->nsp->pcap_read_events, nse);
}
break;
}
#endif #endif
default: default:
fatal("Unknown event type (%d) for IOD #%d\n", nse->type, iod->id); fatal("Unknown event type (%d) for IOD #%d\n", nse->type, iod->id);
} }
return 0; return 0;
} }
@@ -744,38 +743,38 @@ void handle_read_result(mspool *ms, msevent *nse, enum nse_status status) {
nse->iod->read_count += rc; nse->iod->read_count += rc;
/* We decide whether we have read enough to return */ /* We decide whether we have read enough to return */
switch(nse->readinfo.read_type) { switch(nse->readinfo.read_type) {
case NSOCK_READ: case NSOCK_READ:
nse->status = NSE_STATUS_SUCCESS;
nse->event_done = 1;
break;
case NSOCK_READBYTES:
if (FILESPACE_LENGTH(&nse->iobuf) >= nse->readinfo.num) {
nse->status = NSE_STATUS_SUCCESS; nse->status = NSE_STATUS_SUCCESS;
nse->event_done = 1; nse->event_done = 1;
} break;
/* else we are not done */ case NSOCK_READBYTES:
break; if (FILESPACE_LENGTH(&nse->iobuf) >= nse->readinfo.num) {
case NSOCK_READLINES: nse->status = NSE_STATUS_SUCCESS;
/* Lets count the number of lines we have ... */ nse->event_done = 1;
count = 0;
len = FILESPACE_LENGTH(&nse->iobuf) -1;
str = FILESPACE_STR(&nse->iobuf);
for (count=0; len >= 0; len--) {
if (str[len] == '\n') {
count++;
if ((int)count >= nse->readinfo.num)
break;
} }
} /* else we are not done */
if ((int) count >= nse->readinfo.num) { break;
nse->event_done = 1; case NSOCK_READLINES:
nse->status = NSE_STATUS_SUCCESS; /* Lets count the number of lines we have ... */
} count = 0;
/* Else we are not done */ len = FILESPACE_LENGTH(&nse->iobuf) -1;
break; str = FILESPACE_STR(&nse->iobuf);
default: for (count=0; len >= 0; len--) {
assert(0); if (str[len] == '\n') {
break; /* unreached */ count++;
if ((int)count >= nse->readinfo.num)
break;
}
}
if ((int) count >= nse->readinfo.num) {
nse->event_done = 1;
nse->status = NSE_STATUS_SUCCESS;
}
/* Else we are not done */
break;
default:
assert(0);
break; /* unreached */
} }
} }
} else { } else {
@@ -1208,26 +1207,26 @@ void nsp_add_event(mspool *nsp, msevent *nse) {
if (nsp->tracelevel > 8) if (nsp->tracelevel > 8)
nsock_trace(nsp, "PCAP NSE #%lu: Adding event to READ_EVENTS", nse->id); nsock_trace(nsp, "PCAP NSE #%lu: Adding event to READ_EVENTS", nse->id);
#if PCAP_BSD_SELECT_HACK #if PCAP_BSD_SELECT_HACK
/* when using BSD hack we must do pcap_next() after select(). /* when using BSD hack we must do pcap_next() after select().
* Let's insert this pcap to bot queues, to selectable and nonselectable. * Let's insert this pcap to bot queues, to selectable and nonselectable.
* This will result in doing pcap_next_ex() just before select() */ * This will result in doing pcap_next_ex() just before select() */
if (nsp->tracelevel > 8) if (nsp->tracelevel > 8)
nsock_trace(nsp, "PCAP NSE #%lu: Adding event to PCAP_READ_EVENTS", nse->id); nsock_trace(nsp, "PCAP NSE #%lu: Adding event to PCAP_READ_EVENTS", nse->id);
#endif #endif
} else { } else {
/* pcap isn't selectable. Add it to pcap-specific queue. */ /* pcap isn't selectable. Add it to pcap-specific queue. */
if (nsp->tracelevel > 8) if (nsp->tracelevel > 8)
nsock_trace(nsp, "PCAP NSE #%lu: Adding event to PCAP_READ_EVENTS", nse->id); nsock_trace(nsp, "PCAP NSE #%lu: Adding event to PCAP_READ_EVENTS", nse->id);
} }
iod_add_event(nse->iod, nse); iod_add_event(nse->iod, nse);
break; break;
} }
#endif #endif
default: default:
assert(0); assert(0);
break; /* unreached */ break; /* unreached */
} }
} }

View File

@@ -272,60 +272,60 @@ int nsock_pcap_get_l3_offset(pcap_t *pt, int *dl) {
* if a new offset ever exceeds the current max (24), adjust max_link_headersz in tcpip.h */ * if a new offset ever exceeds the current max (24), adjust max_link_headersz in tcpip.h */
switch(datalink) { switch(datalink) {
case DLT_EN10MB: offset = 14; break; case DLT_EN10MB: offset = 14; break;
case DLT_IEEE802: offset = 22; break; case DLT_IEEE802: offset = 22; break;
#ifdef __amigaos__ #ifdef __amigaos__
case DLT_MIAMI: offset = 16; break; case DLT_MIAMI: offset = 16; break;
#endif #endif
#ifdef DLT_LOOP #ifdef DLT_LOOP
case DLT_LOOP: case DLT_LOOP:
#endif #endif
case DLT_NULL: offset = 4; break; case DLT_NULL: offset = 4; break;
case DLT_SLIP: case DLT_SLIP:
#ifdef DLT_SLIP_BSDOS #ifdef DLT_SLIP_BSDOS
case DLT_SLIP_BSDOS: case DLT_SLIP_BSDOS:
#endif #endif
#if (FREEBSD || OPENBSD || NETBSD || BSDI || MACOSX) #if (FREEBSD || OPENBSD || NETBSD || BSDI || MACOSX)
offset = 16;break; offset = 16;break;
#else
offset = 24;break; /* Anyone use this??? */
#endif
case DLT_PPP:
#ifdef DLT_PPP_BSDOS
case DLT_PPP_BSDOS:
#endif
#ifdef DLT_PPP_SERIAL
case DLT_PPP_SERIAL:
#endif
#ifdef DLT_PPP_ETHER
case DLT_PPP_ETHER:
#endif
#if (FREEBSD || OPENBSD || NETBSD || BSDI || MACOSX)
offset = 4;break;
#else
#ifdef SOLARIS
offset = 8;break;
#else #else
offset = 24;break; /* Anyone use this? */ offset = 24;break; /* Anyone use this??? */
#endif /* ifdef solaris */ #endif
#endif /* if freebsd || openbsd || netbsd || bsdi */
#ifdef DLT_RAW
case DLT_RAW: offset = 0; break;
#endif /* DLT_RAW */
case DLT_FDDI: offset = 21; break;
#ifdef DLT_ENC
case DLT_ENC: offset = 12; break;
#endif /* DLT_ENC */
#ifdef DLT_LINUX_SLL
case DLT_LINUX_SLL: offset = 16; break;
#endif
#ifdef DLT_IPNET
case DLT_IPNET: offset = 24; break;
#endif /* DLT_IPNET */
default: /* Sorry, link type is unknown. */ case DLT_PPP:
fatal("Unknown datalink type %d.\n", datalink); #ifdef DLT_PPP_BSDOS
case DLT_PPP_BSDOS:
#endif
#ifdef DLT_PPP_SERIAL
case DLT_PPP_SERIAL:
#endif
#ifdef DLT_PPP_ETHER
case DLT_PPP_ETHER:
#endif
#if (FREEBSD || OPENBSD || NETBSD || BSDI || MACOSX)
offset = 4;break;
#else
#ifdef SOLARIS
offset = 8;break;
#else
offset = 24;break; /* Anyone use this? */
#endif /* ifdef solaris */
#endif /* if freebsd || openbsd || netbsd || bsdi */
#ifdef DLT_RAW
case DLT_RAW: offset = 0; break;
#endif /* DLT_RAW */
case DLT_FDDI: offset = 21; break;
#ifdef DLT_ENC
case DLT_ENC: offset = 12; break;
#endif /* DLT_ENC */
#ifdef DLT_LINUX_SLL
case DLT_LINUX_SLL: offset = 16; break;
#endif
#ifdef DLT_IPNET
case DLT_IPNET: offset = 24; break;
#endif /* DLT_IPNET */
default: /* Sorry, link type is unknown. */
fatal("Unknown datalink type %d.\n", datalink);
} }
if (dl) if (dl)
*dl = datalink; *dl = datalink;