]> git.ozlabs.org Git - ccan/commitdiff
iscsi: ccanize a little more, add silly simple test case.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 8 Nov 2010 09:54:47 +0000 (20:24 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 8 Nov 2010 09:54:47 +0000 (20:24 +1030)
15 files changed:
ccan/iscsi/Makefile
ccan/iscsi/_info
ccan/iscsi/discovery.c
ccan/iscsi/dlinklist.h
ccan/iscsi/init.c
ccan/iscsi/iscsi-private.h
ccan/iscsi/iscsi.h
ccan/iscsi/login.c
ccan/iscsi/nop.c
ccan/iscsi/pdu.c
ccan/iscsi/scsi-command.c
ccan/iscsi/scsi-lowlevel.c
ccan/iscsi/scsi-lowlevel.h
ccan/iscsi/socket.c
ccan/iscsi/test/run.c [new file with mode: 0644]

index 6995bfd78f51d73f79aae695c85c82c88d73df5f..278a236ac790c81dae20e77029908f96f4b10129 100644 (file)
@@ -1,6 +1,6 @@
 LIBS=
 CC=gcc
 LIBS=
 CC=gcc
-CFLAGS=-g -O0 -Wall -W -I../.. "-D_U_=__attribute__((unused))"
+CFLAGS=-g -O0 -Wall -W -I../..
 LIBISCSI_OBJ = socket.o init.o login.o nop.o pdu.o discovery.o scsi-command.o scsi-lowlevel.o
 
 all: tools/iscsiclient
 LIBISCSI_OBJ = socket.o init.o login.o nop.o pdu.o discovery.o scsi-command.o scsi-lowlevel.o
 
 all: tools/iscsiclient
index 6e02fec0db936df59220f5eb356fc53f86932aa1..33ae4e4622320393b2b36dc52c22c6b5a7f75978 100644 (file)
@@ -20,6 +20,7 @@ int main(int argc, char *argv[])
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
                return 1;
 
        if (strcmp(argv[1], "depends") == 0) {
+               printf("ccan/compiler\n");
                return 0;
        }
 
                return 0;
        }
 
index 05250429b4e8e6e652ea02a51a9196ae0f52ce2a..3f297554a3c7e49648150a373b0b7bf3cfa555c9 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
@@ -90,7 +90,7 @@ static void iscsi_free_discovery_addresses(struct iscsi_discovery_address *addre
                free(addresses);
                addresses = next;
        }
                free(addresses);
                addresses = next;
        }
-}      
+}
 
 int iscsi_process_text_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size)
 {
 
 int iscsi_process_text_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size)
 {
@@ -121,7 +121,7 @@ int iscsi_process_text_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
                        pdu->callback(iscsi, ISCSI_STATUS_ERROR, NULL, pdu->private_data);
                        iscsi_free_discovery_addresses(targets);
                        return -1;
                        pdu->callback(iscsi, ISCSI_STATUS_ERROR, NULL, pdu->private_data);
                        iscsi_free_discovery_addresses(targets);
                        return -1;
-               } 
+               }
 
                /* parse the strings */
                if (!strncmp((char *)hdr, "TargetName=", 11)) {
 
                /* parse the strings */
                if (!strncmp((char *)hdr, "TargetName=", 11)) {
index 6d525f903644c61f9062b29e83dd60074190d905..acbb98637c83fab7805d875710b683bac61b4ebf 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    some simple double linked list macros
 
    Unix SMB/CIFS implementation.
    some simple double linked list macros
 
index 096985e48b9e9fa6d2697b295f9817a208c1bfbd..e428c941b814d487061925b0299515259fa52704 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
index 8c95b4d1655bab6ec5a065176d2b1dbca94a9e40..090d3c4692645f9ab6c592828205dec8634a98d6 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
+#ifndef CCAN_ISCSI_PRIVATE_H
+#define CCAN_ISCSI_PRIVATE_H
 
 #include <stdint.h>
 
 
 #include <stdint.h>
 
-#ifndef _U_
-#define _U_
-#endif
-
 #ifndef discard_const
 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
 #endif
 #ifndef discard_const
 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
 #endif
@@ -141,3 +139,5 @@ int iscsi_process_logout_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pd
 int iscsi_process_scsi_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
 int iscsi_process_scsi_data_in(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size, int *is_finished);
 int iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
 int iscsi_process_scsi_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
 int iscsi_process_scsi_data_in(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size, int *is_finished);
 int iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
+
+#endif /* CCAN_ISCSI_PRIVATE_H */
index 47c99169cb8c58595f9917a299f890115b15d704..4aa4670970d83c51274df9a19f7f94f3fd014db5 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
@@ -14,6 +14,8 @@
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
+#ifndef CCAN_ISCSI_H
+#define CCAN_ISCSI_H
 
 struct iscsi_context;
 struct sockaddr;
 
 struct iscsi_context;
 struct sockaddr;
@@ -103,7 +105,7 @@ enum icsi_status { ISCSI_STATUS_GOOD                =0,
                   ISCSI_STATUS_ERROR           =0x0f000001 };
 
 
                   ISCSI_STATUS_ERROR           =0x0f000001 };
 
 
-/* 
+/*
  * Generic callback for completion of iscsi_*_async().
  * command_data depends on status.
  */
  * Generic callback for completion of iscsi_*_async().
  * command_data depends on status.
  */
@@ -125,7 +127,7 @@ typedef void (*iscsi_command_cb)(struct iscsi_context *iscsi, int status, void *
  *    ISCSI_STATUS_GOOD     : Connection was successful. Command_data is NULL.
  *                            In this case the callback will be invoked a second time once the connection
  *                            is torn down.
  *    ISCSI_STATUS_GOOD     : Connection was successful. Command_data is NULL.
  *                            In this case the callback will be invoked a second time once the connection
  *                            is torn down.
- * 
+ *
  *    ISCSI_STATUS_ERROR    : Either failed to establish the connection, or an already established connection
  *                            has failed with an error.
  *
  *    ISCSI_STATUS_ERROR    : Either failed to establish the connection, or an already established connection
  *                            has failed with an error.
  *
@@ -226,7 +228,7 @@ int iscsi_nop_out_async(struct iscsi_context *iscsi, iscsi_command_cb cb, unsign
  *
  * status :
  *   ISCSI_STATUS_GOOD the scsi command completed successfullt on the target.
  *
  * status :
  *   ISCSI_STATUS_GOOD the scsi command completed successfullt on the target.
- *   If this scsi command returns DATA-IN, that data is stored in an scsi_task structure 
+ *   If this scsi command returns DATA-IN, that data is stored in an scsi_task structure
  *   returned in the command_data parameter. This buffer will be automatically freed once the callback
  *   returns.
  *
  *   returned in the command_data parameter. This buffer will be automatically freed once the callback
  *   returns.
  *
@@ -259,4 +261,4 @@ int iscsi_write10_async(struct iscsi_context *iscsi, int lun, iscsi_command_cb c
 int iscsi_modesense6_async(struct iscsi_context *iscsi, int lun, iscsi_command_cb cb, int dbd, int pc, int page_code, int sub_page_code, unsigned char alloc_len, void *private_data);
 
 
 int iscsi_modesense6_async(struct iscsi_context *iscsi, int lun, iscsi_command_cb cb, int dbd, int pc, int page_code, int sub_page_code, unsigned char alloc_len, void *private_data);
 
 
-
+#endif /* CCAN_ISCSI_H */
index ff0d4cce77216895732e53bc841ad6c06c021b8a..5863d88331db4ffd2a46be54a241ca4922afac81 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <arpa/inet.h>
 #include <stdlib.h>
 #include <string.h>
 #include <arpa/inet.h>
+#include <ccan/compiler/compiler.h>
 #include "iscsi.h"
 #include "iscsi-private.h"
 
 #include "iscsi.h"
 #include "iscsi-private.h"
 
@@ -212,7 +213,7 @@ int iscsi_process_login_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
         *     some parameters.
         *     we should also do proper handshaking if the target is not yet prepared to transition
         *     to the next stage
         *     some parameters.
         *     we should also do proper handshaking if the target is not yet prepared to transition
         *     to the next stage
-        */ 
+        */
        status = ntohs(*(uint16_t *)&hdr[36]);
        if (status != 0) {
                pdu->callback(iscsi, ISCSI_STATUS_ERROR, NULL, pdu->private_data);
        status = ntohs(*(uint16_t *)&hdr[36]);
        if (status != 0) {
                pdu->callback(iscsi, ISCSI_STATUS_ERROR, NULL, pdu->private_data);
@@ -267,7 +268,7 @@ int iscsi_logout_async(struct iscsi_context *iscsi, iscsi_command_cb cb, void *p
        return 0;
 }
 
        return 0;
 }
 
-int iscsi_process_logout_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size _U_)
+int iscsi_process_logout_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size UNNEEDED_ATTRIBUTE)
 {
        iscsi->is_loggedin = 0;
        pdu->callback(iscsi, ISCSI_STATUS_GOOD, NULL, pdu->private_data);
 {
        iscsi->is_loggedin = 0;
        pdu->callback(iscsi, ISCSI_STATUS_GOOD, NULL, pdu->private_data);
index e12bd48a0eb252dd5abad5569d80d6855827a7ea..5c288b0a3a191aefe85eb931ff68dad898a61fef 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
index e073ebab198b1a3ed4ed8a61904853d9023c2747..0b290d92092fe0a4900ca34a944bb6760594a58c 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
@@ -104,7 +104,7 @@ int iscsi_add_data(struct iscsi_data *data, unsigned char *dptr, int dsize, int
                aligned = (aligned+3)&0xfffffffc;
        }
        buf = malloc(aligned);
                aligned = (aligned+3)&0xfffffffc;
        }
        buf = malloc(aligned);
-       if (buf == NULL) {      
+       if (buf == NULL) {
                printf("failed to allocate buffer for %d bytes\n", len);
                return -2;
        }
                printf("failed to allocate buffer for %d bytes\n", len);
                return -2;
        }
@@ -125,9 +125,6 @@ int iscsi_add_data(struct iscsi_data *data, unsigned char *dptr, int dsize, int
 
 int iscsi_pdu_add_data(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, unsigned char *dptr, int dsize)
 {
 
 int iscsi_pdu_add_data(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, unsigned char *dptr, int dsize)
 {
-       int len, aligned;
-       unsigned char *buf;
        if (pdu == NULL) {
                printf("trying to add data to NULL pdu\n");
                return -1;
        if (pdu == NULL) {
                printf("trying to add data to NULL pdu\n");
                return -1;
index 15782eb604d7a5f6cde40a616c71606973a9a479..eb3ae5bcf177ab35d73487bfd589953caaf49189 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
@@ -50,16 +50,16 @@ static void iscsi_scsi_response_cb(struct iscsi_context *iscsi, int status, void
 
        switch (status) {
        case ISCSI_STATUS_CHECK_CONDITION:
 
        switch (status) {
        case ISCSI_STATUS_CHECK_CONDITION:
-               scsi_cbdata->callback(iscsi, ISCSI_STATUS_CHECK_CONDITION, task, scsi_cbdata->private_data);    
+               scsi_cbdata->callback(iscsi, ISCSI_STATUS_CHECK_CONDITION, task, scsi_cbdata->private_data);
                return;
        
 
        case ISCSI_STATUS_GOOD:
                return;
        
 
        case ISCSI_STATUS_GOOD:
-               scsi_cbdata->callback(iscsi, ISCSI_STATUS_GOOD, task, scsi_cbdata->private_data);       
+               scsi_cbdata->callback(iscsi, ISCSI_STATUS_GOOD, task, scsi_cbdata->private_data);
                return;
        default:
                printf("Cant handle  scsi status %d yet\n", status);
                return;
        default:
                printf("Cant handle  scsi status %d yet\n", status);
-               scsi_cbdata->callback(iscsi, ISCSI_STATUS_ERROR, task, scsi_cbdata->private_data);      
+               scsi_cbdata->callback(iscsi, ISCSI_STATUS_ERROR, task, scsi_cbdata->private_data);
        }
 }
 
        }
 }
 
@@ -228,12 +228,12 @@ int iscsi_process_scsi_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
                task->sense.key        = task->datain.data[4] & 0x0f;
                task->sense.ascq       = ntohs(*(uint16_t *)&(task->datain.data[14]));
 
                task->sense.key        = task->datain.data[4] & 0x0f;
                task->sense.ascq       = ntohs(*(uint16_t *)&(task->datain.data[14]));
 
-               pdu->callback(iscsi, ISCSI_STATUS_CHECK_CONDITION, task, pdu->private_data);    
+               pdu->callback(iscsi, ISCSI_STATUS_CHECK_CONDITION, task, pdu->private_data);
                break;
        default:
                printf("Unknown status :%d\n", status);
 
                break;
        default:
                printf("Unknown status :%d\n", status);
 
-               pdu->callback(iscsi, ISCSI_STATUS_ERROR, task, pdu->private_data);      
+               pdu->callback(iscsi, ISCSI_STATUS_ERROR, task, pdu->private_data);
                return -1;
        }
 
                return -1;
        }
 
index 7199bf824653cec9ea2bbd659f1edd5da34bbc2a..620916fe77c05898607056bde90906015e351dc6 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
@@ -15,7 +15,7 @@
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 /*
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
 /*
- * would be nice if this could grow into a full blown library for scsi to 
+ * would be nice if this could grow into a full blown library for scsi to
  * 1, build a CDB
  * 2, check how big a complete data-in structure needs to be
  * 3, unmarshall data-in into a real structure
  * 1, build a CDB
  * 2, check how big a complete data-in structure needs to be
  * 3, unmarshall data-in into a real structure
@@ -29,6 +29,7 @@
 #include <strings.h>
 #include <stdint.h>
 #include <arpa/inet.h>
 #include <strings.h>
 #include <stdint.h>
 #include <arpa/inet.h>
+#include <ccan/compiler/compiler.h>
 #include "scsi-lowlevel.h"
 #include "dlinklist.h"
 
 #include "scsi-lowlevel.h"
 #include "dlinklist.h"
 
@@ -44,7 +45,7 @@ void scsi_free_scsi_task(struct scsi_task *task)
        free(task);
 }
 
        free(task);
 }
 
-void *scsi_malloc(struct scsi_task *task, size_t size)
+static void *scsi_malloc(struct scsi_task *task, size_t size)
 {
        struct scsi_allocated_memory *mem;
 
 {
        struct scsi_allocated_memory *mem;
 
@@ -161,7 +162,7 @@ static struct scsi_reportluns_list *scsi_reportluns_datain_unmarshall(struct scs
        }
        
        return list;
        }
        
        return list;
-}      
+}
 
 
 /*
 
 
 /*
@@ -199,7 +200,8 @@ struct scsi_task *scsi_cdb_readcapacity10(int lba, int pmi)
 /*
  * parse the data in blob and calcualte the size of a full readcapacity10 datain structure
  */
 /*
  * parse the data in blob and calcualte the size of a full readcapacity10 datain structure
  */
-static int scsi_readcapacity10_datain_getfullsize(struct scsi_task *task _U_)
+static int scsi_readcapacity10_datain_getfullsize(struct scsi_task *task
+                                                 UNNEEDED_ATTRIBUTE)
 {
        return 8;
 }
 {
        return 8;
 }
@@ -282,7 +284,7 @@ static int scsi_inquiry_datain_getfullsize(struct scsi_task *task)
 /*
  * unmarshall the data in blob for inquiry into a structure
  */
 /*
  * unmarshall the data in blob for inquiry into a structure
  */
-void *scsi_inquiry_datain_unmarshall(struct scsi_task *task)
+static void *scsi_inquiry_datain_unmarshall(struct scsi_task *task)
 {
        struct scsi_inquiry_standard *inq;
 
 {
        struct scsi_inquiry_standard *inq;
 
index 9417f42f4f0ec866397ffbbb8c7c0453f0de053b..3d477fc61c1086c7d64076bb6231f3c0511e683f 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
    You should have received a copy of the GNU General Public License
    along with this program; if not, see <http://www.gnu.org/licenses/>.
 */
-
-#ifndef _U_
-#define _U_
-#endif
+#ifndef CCAN_ISCSI_SCSI_LOWLEVEL_H
+#define CCAN_ISCSI_SCSI_LOWLEVEL_H
 
 #define SCSI_CDB_MAX_SIZE                      16
 
 
 #define SCSI_CDB_MAX_SIZE                      16
 
@@ -165,7 +163,7 @@ struct scsi_inquiry_standard {
        char vendor_identification[8+1];
        char product_identification[16+1];
        char product_revision_level[4+1];
        char vendor_identification[8+1];
        char product_identification[16+1];
        char product_revision_level[4+1];
-}; 
+};
 
 struct scsi_task *scsi_cdb_inquiry(int evpd, int page_code, int alloc_len);
 
 
 struct scsi_task *scsi_cdb_inquiry(int evpd, int page_code, int alloc_len);
 
@@ -192,3 +190,4 @@ void *scsi_datain_unmarshall(struct scsi_task *task);
 struct scsi_task *scsi_cdb_read10(int lba, int xferlen, int blocksize);
 struct scsi_task *scsi_cdb_write10(int lba, int xferlen, int fua, int fuanv, int blocksize);
 
 struct scsi_task *scsi_cdb_read10(int lba, int xferlen, int blocksize);
 struct scsi_task *scsi_cdb_write10(int lba, int xferlen, int fua, int fuanv, int blocksize);
 
+#endif /* CCAN_ISCSI_SCSI_LOWLEVEL_H */
index 6f1eeddac291c0881bfaddb1f9b6d613556fde16..ce3526e1e12945b997b86716f943d9e69f7bb38b 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
    
    This program is free software; you can redistribute it and/or modify
@@ -43,8 +43,11 @@ int iscsi_connect_async(struct iscsi_context *iscsi, const char *target, iscsi_c
        int port = 3260;
        char *str;
        char *addr;
        int port = 3260;
        char *str;
        char *addr;
-       struct sockaddr_storage s;
-       struct sockaddr_in *sin = (struct sockaddr_in *)&s;
+       union {
+               struct sockaddr sa;
+               struct sockaddr_storage ss;
+               struct sockaddr_in sin;
+       } s;
        int socksize;
 
        if (iscsi == NULL) {
        int socksize;
 
        if (iscsi == NULL) {
@@ -75,22 +78,22 @@ int iscsi_connect_async(struct iscsi_context *iscsi, const char *target, iscsi_c
                str[0] = 0;
        }
 
                str[0] = 0;
        }
 
-       sin->sin_family = AF_INET;
-       sin->sin_port   = htons(port);
-       if (inet_pton(AF_INET, addr, &sin->sin_addr) != 1) {
+       s.sin.sin_family = AF_INET;
+       s.sin.sin_port   = htons(port);
+       if (inet_pton(AF_INET, addr, &s.sin.sin_addr) != 1) {
                printf("failed to convert to ip address\n");
                free(addr);
                return -4;
        }
        free(addr);
 
                printf("failed to convert to ip address\n");
                free(addr);
                return -4;
        }
        free(addr);
 
-       switch (s.ss_family) {
+       switch (s.ss.ss_family) {
        case AF_INET:
                iscsi->fd = socket(AF_INET, SOCK_STREAM, 0);
                socksize = sizeof(struct sockaddr_in);
                break;
        default:
        case AF_INET:
                iscsi->fd = socket(AF_INET, SOCK_STREAM, 0);
                socksize = sizeof(struct sockaddr_in);
                break;
        default:
-               printf("Unknown family :%d\n", s.ss_family);
+               printf("Unknown family :%d\n", s.ss.ss_family);
                return -5;
 
        }
                return -5;
 
        }
@@ -106,13 +109,13 @@ int iscsi_connect_async(struct iscsi_context *iscsi, const char *target, iscsi_c
 
        set_nonblocking(iscsi->fd);
 
 
        set_nonblocking(iscsi->fd);
 
-       if (connect(iscsi->fd, (struct sockaddr *)&s, socksize) != 0 && errno != EINPROGRESS) {
+       if (connect(iscsi->fd, &s.sa, socksize) != 0 && errno != EINPROGRESS) {
                printf("Connect failed errno : %s (%d)\n", strerror(errno), errno);
                return -7;
                printf("Connect failed errno : %s (%d)\n", strerror(errno), errno);
                return -7;
-       }               
+       }
 
        return 0;
 
        return 0;
-}          
+}
 
 int iscsi_disconnect(struct iscsi_context *iscsi)
 {
 
 int iscsi_disconnect(struct iscsi_context *iscsi)
 {
@@ -153,7 +156,7 @@ int iscsi_which_events(struct iscsi_context *iscsi)
 
        if (iscsi->is_connected == 0) {
                events |= POLLOUT;
 
        if (iscsi->is_connected == 0) {
                events |= POLLOUT;
-       }       
+       }
 
        if (iscsi->outqueue) {
                events |= POLLOUT;
 
        if (iscsi->outqueue) {
                events |= POLLOUT;
diff --git a/ccan/iscsi/test/run.c b/ccan/iscsi/test/run.c
new file mode 100644 (file)
index 0000000..5a37c91
--- /dev/null
@@ -0,0 +1,24 @@
+#include <ccan/iscsi/iscsi.h>
+#include <ccan/iscsi/discovery.c>
+#include <ccan/iscsi/socket.c>
+#include <ccan/iscsi/init.c>
+#include <ccan/iscsi/pdu.c>
+#include <ccan/iscsi/scsi-lowlevel.c>
+#include <ccan/iscsi/nop.c>
+#include <ccan/iscsi/login.c>
+#include <ccan/iscsi/scsi-command.c>
+#include <ccan/tap/tap.h>
+
+int main(void)
+{
+       struct iscsi_context *iscsi;
+
+       plan_tests(2);
+
+       iscsi = iscsi_create_context("some name");
+       ok1(iscsi);
+       ok1(iscsi_destroy_context(iscsi) == 0);
+
+       /* This exits depending on whether all tests passed */
+       return exit_status();
+}