Windows: Add support to build as a DLL under windows
This commit is contained in:
@@ -14,7 +14,11 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#if defined(WIN32)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
|
||||
|
||||
@@ -15,10 +15,14 @@
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(WIN32)
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
|
||||
|
||||
14
lib/init.c
14
lib/init.c
@@ -16,14 +16,18 @@
|
||||
*/
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#if defined(WIN32)
|
||||
#else
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
@@ -50,7 +54,7 @@ iscsi_create_context(const char *initiator_name)
|
||||
iscsi->fd = -1;
|
||||
|
||||
/* initialize to a "random" isid */
|
||||
iscsi_set_isid_random(iscsi, random(), 0);
|
||||
iscsi_set_isid_random(iscsi, rand(), 0);
|
||||
|
||||
/* assume we start in security negotiation phase */
|
||||
iscsi->current_phase = ISCSI_PDU_LOGIN_CSG_SECNEG;
|
||||
@@ -242,8 +246,10 @@ iscsi_set_error(struct iscsi_context *iscsi, const char *error_string, ...)
|
||||
char *str;
|
||||
|
||||
va_start(ap, error_string);
|
||||
if (vasprintf(&str, error_string, ap) < 0) {
|
||||
str = malloc(1024);
|
||||
if (vsnprintf(str, 1024, error_string, ap) < 0) {
|
||||
/* not much we can do here */
|
||||
free(str);
|
||||
str = NULL;
|
||||
}
|
||||
|
||||
|
||||
84
lib/libiscsi.def
Normal file
84
lib/libiscsi.def
Normal file
@@ -0,0 +1,84 @@
|
||||
LIBRARY libiscsi
|
||||
EXPORTS
|
||||
iscsi_get_fd
|
||||
iscsi_which_events
|
||||
iscsi_service
|
||||
iscsi_queue_length
|
||||
iscsi_parse_full_url
|
||||
iscsi_destroy_url
|
||||
iscsi_parse_portal_url
|
||||
iscsi_get_error
|
||||
iscsi_create_context
|
||||
iscsi_destroy_context
|
||||
iscsi_set_alias
|
||||
iscsi_set_targetname
|
||||
iscsi_get_target_address
|
||||
iscsi_set_session_type
|
||||
iscsi_set_header_digest
|
||||
iscsi_set_initiator_username_pwd
|
||||
iscsi_is_logged_in
|
||||
iscsi_connect_async
|
||||
iscsi_connect_sync
|
||||
iscsi_full_connect_async
|
||||
iscsi_full_connect_sync
|
||||
iscsi_disconnect
|
||||
iscsi_login_async
|
||||
iscsi_login_sync
|
||||
iscsi_logout_async
|
||||
iscsi_logout_sync
|
||||
iscsi_discovery_async
|
||||
iscsi_nop_out_async
|
||||
iscsi_task_mgmt_async
|
||||
iscsi_task_mgmt_abort_task_async
|
||||
iscsi_task_mgmt_abort_task_set_async
|
||||
iscsi_task_mgmt_lun_reset_async
|
||||
iscsi_task_mgmt_target_warm_reset_async
|
||||
iscsi_task_mgmt_target_cold_reset_async
|
||||
iscsi_set_isid_oui
|
||||
iscsi_set_isid_en
|
||||
iscsi_set_isid_random
|
||||
iscsi_set_isid_reserved
|
||||
iscsi_scsi_command_async
|
||||
iscsi_reportluns_task
|
||||
iscsi_testunitready_task
|
||||
iscsi_inquiry_task
|
||||
iscsi_readcapacity10_task
|
||||
iscsi_synchronizecache10_task
|
||||
iscsi_read6_task
|
||||
iscsi_read10_task
|
||||
iscsi_write10_task
|
||||
iscsi_modesense6_task
|
||||
iscsi_scsi_command_sync
|
||||
iscsi_reportluns_sync
|
||||
iscsi_testunitready_sync
|
||||
iscsi_inquiry_sync
|
||||
iscsi_readcapacity10_sync
|
||||
iscsi_synchronizecache10_sync
|
||||
iscsi_read6_sync
|
||||
iscsi_read10_sync
|
||||
poll
|
||||
scsi_task_add_data_in_buffer
|
||||
scsi_sense_key_str
|
||||
scsi_sense_ascq_str
|
||||
scsi_free_scsi_task
|
||||
scsi_set_task_private_ptr
|
||||
scsi_get_task_private_ptr
|
||||
scsi_cdb_testunitready
|
||||
scsi_reportluns_cdb
|
||||
scsi_cdb_readcapacity10
|
||||
scsi_devtype_to_str
|
||||
scsi_version_to_str
|
||||
scsi_inquiry_pagecode_to_str
|
||||
scsi_cdb_inquiry
|
||||
scsi_protocol_identifier_to_str
|
||||
scsi_codeset_to_str
|
||||
scsi_association_to_str
|
||||
scsi_designator_type_to_str
|
||||
scsi_cdb_modesense6
|
||||
scsi_datain_getfullsize
|
||||
scsi_datain_unmarshall
|
||||
scsi_cdb_read6
|
||||
scsi_cdb_read10
|
||||
scsi_cdb_write10
|
||||
scsi_cdb_synchronizecache10
|
||||
|
||||
75
lib/login.c
75
lib/login.c
@@ -19,10 +19,15 @@
|
||||
#define _GNU_SOURCE
|
||||
#endif
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "md5.h"
|
||||
@@ -38,11 +43,17 @@ iscsi_login_add_initiatorname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (asprintf(&str, "InitiatorName=%s", iscsi->initiator_name) == -1) {
|
||||
str = malloc(1024);
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, 1024, 1024, "InitiatorName=%s", iscsi->initiator_name) == -1) {
|
||||
#else
|
||||
if (snprintf(str, 1024, "InitiatorName=%s", iscsi->initiator_name) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("initiatorname:%s\n", str);
|
||||
if (iscsi_pdu_add_data(iscsi, pdu, (unsigned char *)str, strlen(str)+1)
|
||||
!= 0) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: pdu add data failed.");
|
||||
@@ -64,8 +75,14 @@ iscsi_login_add_alias(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (asprintf(&str, "InitiatorAlias=%s", iscsi->alias) == -1) {
|
||||
str = malloc(1024);
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, 1024, 1024, "InitiatorAlias=%s", iscsi->alias) == -1) {
|
||||
#else
|
||||
if (snprintf(str, 1024, "InitiatorAlias=%s", iscsi->alias) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -96,8 +113,14 @@ iscsi_login_add_targetname(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (asprintf(&str, "TargetName=%s", iscsi->target_name) == -1) {
|
||||
str = malloc(1024);
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, 1024, 1024, "TargetName=%s", iscsi->target_name) == -1) {
|
||||
#else
|
||||
if (snprintf(str, 1024, "TargetName=%s", iscsi->target_name) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -207,9 +230,15 @@ iscsi_login_add_initialr2t(struct iscsi_context *iscsi, struct iscsi_pdu *pdu)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (asprintf(&str, "InitialR2T=%s", iscsi->want_initial_r2t == ISCSI_INITIAL_R2T_NO ?
|
||||
str = malloc(1024);
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, 1024, 1024, "InitialR2T=%s", iscsi->want_initial_r2t == ISCSI_INITIAL_R2T_NO ?
|
||||
#else
|
||||
if (snprintf(str, 1024, "InitialR2T=%s", iscsi->want_initial_r2t == ISCSI_INITIAL_R2T_NO ?
|
||||
#endif
|
||||
"No" : "Yes") == -1) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -234,9 +263,15 @@ iscsi_login_add_immediatedata(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (asprintf(&str, "ImmediateData=%s", iscsi->want_immediate_data == ISCSI_IMMEDIATE_DATA_NO ?
|
||||
str = malloc(1024);
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, 1024, 1024, "ImmediateData=%s", iscsi->want_immediate_data == ISCSI_IMMEDIATE_DATA_NO ?
|
||||
#else
|
||||
if (snprintf(str, 1024, "ImmediateData=%s", iscsi->want_immediate_data == ISCSI_IMMEDIATE_DATA_NO ?
|
||||
#endif
|
||||
"No" : "Yes") == -1) {
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -261,8 +296,14 @@ iscsi_login_add_maxburstlength(struct iscsi_context *iscsi, struct iscsi_pdu *pd
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (asprintf(&str, "MaxBurstLength=%d", iscsi->max_burst_length) == -1) {
|
||||
str = malloc(1024);
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, 1024, 1024, "MaxBurstLength=%d", iscsi->max_burst_length) == -1) {
|
||||
#else
|
||||
if (snprintf(str, 1024, "MaxBurstLength=%d", iscsi->max_burst_length) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -286,8 +327,14 @@ iscsi_login_add_firstburstlength(struct iscsi_context *iscsi, struct iscsi_pdu *
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (asprintf(&str, "FirstBurstLength=%d", iscsi->first_burst_length) == -1) {
|
||||
str = malloc(1024);
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, 1024, 1024, "FirstBurstLength=%d", iscsi->first_burst_length) == -1) {
|
||||
#else
|
||||
if (snprintf(str, 1024, "FirstBurstLength=%d", iscsi->first_burst_length) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -311,8 +358,14 @@ iscsi_login_add_maxrecvdatasegmentlength(struct iscsi_context *iscsi, struct isc
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (asprintf(&str, "MaxRecvDataSegmentLength=%d", iscsi->initiator_max_recv_data_segment_length) == -1) {
|
||||
str = malloc(1024);
|
||||
#if defined(WIN32)
|
||||
if (_snprintf_s(str, 1024, 1024, "MaxRecvDataSegmentLength=%d", iscsi->initiator_max_recv_data_segment_length) == -1) {
|
||||
#else
|
||||
if (snprintf(str, 1024, "MaxRecvDataSegmentLength=%d", iscsi->initiator_max_recv_data_segment_length) == -1) {
|
||||
#endif
|
||||
iscsi_set_error(iscsi, "Out-of-memory: aprintf failed.");
|
||||
free(str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -658,6 +711,8 @@ iscsi_login_async(struct iscsi_context *iscsi, iscsi_command_cb cb,
|
||||
struct iscsi_pdu *pdu;
|
||||
int transit;
|
||||
|
||||
printf("login async\n");
|
||||
fprintf(stderr, "login async\n");
|
||||
if (iscsi->login_attempts++ > 10) {
|
||||
iscsi_set_error(iscsi, "login took too many tries."
|
||||
" giving up.");
|
||||
|
||||
@@ -15,8 +15,12 @@
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#if defined(WIN32)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <strings.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
@@ -15,10 +15,15 @@
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
@@ -22,15 +22,22 @@
|
||||
* 4, marshall a real structure into a data-out blob
|
||||
*/
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <strings.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <stdint.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "slist.h"
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-private.h"
|
||||
|
||||
|
||||
void
|
||||
|
||||
68
lib/socket.c
68
lib/socket.c
@@ -14,31 +14,42 @@
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#if defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#define ioctl ioctlsocket
|
||||
#define close closesocket
|
||||
#else
|
||||
#include "config.h"
|
||||
#include <strings.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <poll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "slist.h"
|
||||
|
||||
static void set_nonblocking(int fd)
|
||||
{
|
||||
#if defined(WIN32)
|
||||
#else
|
||||
unsigned v;
|
||||
v = fcntl(fd, F_GETFL, 0);
|
||||
fcntl(fd, F_SETFL, v | O_NONBLOCK);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
@@ -167,6 +178,7 @@ iscsi_disconnect(struct iscsi_context *iscsi)
|
||||
}
|
||||
|
||||
close(iscsi->fd);
|
||||
|
||||
iscsi->fd = -1;
|
||||
iscsi->is_connected = 0;
|
||||
|
||||
@@ -244,7 +256,7 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
|
||||
if (socket_count < count) {
|
||||
count = socket_count;
|
||||
}
|
||||
count = read(iscsi->fd, &in->hdr[in->hdr_pos], count);
|
||||
count = recv(iscsi->fd, &in->hdr[in->hdr_pos], count, 0);
|
||||
if (count < 0) {
|
||||
if (errno == EINTR) {
|
||||
return 0;
|
||||
@@ -292,7 +304,7 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
|
||||
buf = &in->data[in->data_pos];
|
||||
}
|
||||
|
||||
count = read(iscsi->fd, buf, count);
|
||||
count = recv(iscsi->fd, buf, count, 0);
|
||||
if (count < 0) {
|
||||
if (errno == EINTR) {
|
||||
return 0;
|
||||
@@ -346,10 +358,11 @@ iscsi_write_to_socket(struct iscsi_context *iscsi)
|
||||
total = iscsi->outqueue->outdata.size;
|
||||
total = (total + 3) & 0xfffffffc;
|
||||
|
||||
count = write(iscsi->fd,
|
||||
count = send(iscsi->fd,
|
||||
iscsi->outqueue->outdata.data
|
||||
+ iscsi->outqueue->written,
|
||||
total - iscsi->outqueue->written);
|
||||
total - iscsi->outqueue->written,
|
||||
0);
|
||||
if (count == -1) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||
return 0;
|
||||
@@ -524,3 +537,34 @@ int iscsi_set_tcp_keepalive(struct iscsi_context *iscsi, int idle, int count, in
|
||||
}
|
||||
|
||||
#endif
|
||||
#if defined(WIN32)
|
||||
int poll(struct pollfd *fds, int nfsd, int timeout)
|
||||
{
|
||||
fd_set rfds, wfds, efds;
|
||||
int ret;
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_ZERO(&wfds);
|
||||
FD_ZERO(&efds);
|
||||
if (fds->events & POLLIN) {
|
||||
FD_SET(fds->fd, &rfds);
|
||||
}
|
||||
if (fds->events & POLLOUT) {
|
||||
FD_SET(fds->fd, &wfds);
|
||||
}
|
||||
FD_SET(fds->fd, &efds);
|
||||
select(fds->fd + 1, &rfds, &wfds, &efds, NULL);
|
||||
fds->revents = 0;
|
||||
if (FD_ISSET(fds->fd, &rfds)) {
|
||||
fds->revents |= POLLIN;
|
||||
}
|
||||
if (FD_ISSET(fds->fd, &wfds)) {
|
||||
fds->revents |= POLLOUT;
|
||||
}
|
||||
if (FD_ISSET(fds->fd, &efds)) {
|
||||
fds->revents |= POLLHUP;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -15,10 +15,15 @@
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <poll.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
@@ -15,8 +15,12 @@
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#if defined(WIN32)
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
Reference in New Issue
Block a user