pdu.c (203460) | pdu.c (211095) |
---|---|
1/*- | 1/*- |
2 * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il> | 2 * Copyright (c) 2005-2010 Daniel Braniss <danny@cs.huji.ac.il> |
3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 13 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 * 26 */ 27/* 28 | $Id: pdu.c,v 2.2 2006/12/01 09:11:56 danny Exp danny $ 29 */ 30 31#include <sys/cdefs.h> | 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright --- 13 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 * 26 */ 27/* 28 | $Id: pdu.c,v 2.2 2006/12/01 09:11:56 danny Exp danny $ 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/sbin/iscontrol/pdu.c 203460 2010-02-03 23:58:00Z delphij $"); | 32__FBSDID("$FreeBSD: head/sbin/iscontrol/pdu.c 211095 2010-08-09 12:36:36Z des $"); |
33 34#include <sys/types.h> 35#include <sys/time.h> 36#include <sys/uio.h> 37#include <sys/ioctl.h> 38#include <unistd.h> 39#include <stdlib.h> 40#include <string.h> 41#include <errno.h> 42#include <stdio.h> 43#include <stdarg.h> 44#include <camlib.h> 45 | 33 34#include <sys/types.h> 35#include <sys/time.h> 36#include <sys/uio.h> 37#include <sys/ioctl.h> 38#include <unistd.h> 39#include <stdlib.h> 40#include <string.h> 41#include <errno.h> 42#include <stdio.h> 43#include <stdarg.h> 44#include <camlib.h> 45 |
46#include "iscsi.h" | 46#include <dev/iscsi/initiator/iscsi.h> |
47#include "iscontrol.h" 48 49static void pukeText(char *it, pdu_t *pp); 50 51int 52xmitpdu(isess_t *sess, pdu_t *pp) 53{ 54 if(ioctl(sess->fd, ISCSISEND, pp)) { --- 25 unchanged lines hidden (view full) --- 80sendPDU(isess_t *sess, pdu_t *pp, handler_t *hdlr) 81{ 82 if(xmitpdu(sess, pp)) 83 return 0; 84 if(hdlr) { 85 int res; 86 87 pp->ahs_size = 8 * 1024; | 47#include "iscontrol.h" 48 49static void pukeText(char *it, pdu_t *pp); 50 51int 52xmitpdu(isess_t *sess, pdu_t *pp) 53{ 54 if(ioctl(sess->fd, ISCSISEND, pp)) { --- 25 unchanged lines hidden (view full) --- 80sendPDU(isess_t *sess, pdu_t *pp, handler_t *hdlr) 81{ 82 if(xmitpdu(sess, pp)) 83 return 0; 84 if(hdlr) { 85 int res; 86 87 pp->ahs_size = 8 * 1024; |
88 if((pp->ahs = malloc(pp->ahs_size)) == NULL) { | 88 if((pp->ahs_addr = malloc(pp->ahs_size)) == NULL) { |
89 fprintf(stderr, "out of mem!"); 90 return -1; 91 } 92 pp->ds_size = 0; 93 if((res = recvpdu(sess, pp)) != 0) { 94 fprintf(stderr, "recvpdu failed\n"); 95 return res; 96 } --- 24 unchanged lines hidden (view full) --- 121 printf("ds overflow\n"); 122 free(str); 123 return 0; 124 } 125 126 if((pp->ds_len + len) > pp->ds_size) { 127 u_char *np; 128 | 89 fprintf(stderr, "out of mem!"); 90 return -1; 91 } 92 pp->ds_size = 0; 93 if((res = recvpdu(sess, pp)) != 0) { 94 fprintf(stderr, "recvpdu failed\n"); 95 return res; 96 } --- 24 unchanged lines hidden (view full) --- 121 printf("ds overflow\n"); 122 free(str); 123 return 0; 124 } 125 126 if((pp->ds_len + len) > pp->ds_size) { 127 u_char *np; 128 |
129 np = realloc(pp->ds, pp->ds_size + len + FUDGE); | 129 np = realloc(pp->ds_addr, pp->ds_size + len + FUDGE); |
130 if(np == NULL) { 131 free(str); 132 //XXX: out of memory! 133 return -1; 134 } | 130 if(np == NULL) { 131 free(str); 132 //XXX: out of memory! 133 return -1; 134 } |
135 pp->ds = np; | 135 pp->ds_addr = np; |
136 pp->ds_size += len + FUDGE; 137 } | 136 pp->ds_size += len + FUDGE; 137 } |
138 memcpy(pp->ds + pp->ds_len, str, len); | 138 memcpy(pp->ds_addr + pp->ds_len, str, len); |
139 pp->ds_len += len; 140 free(str); 141 return len; 142} 143 144void 145freePDU(pdu_t *pp) 146{ 147 if(pp->ahs_size) | 139 pp->ds_len += len; 140 free(str); 141 return len; 142} 143 144void 145freePDU(pdu_t *pp) 146{ 147 if(pp->ahs_size) |
148 free(pp->ahs); | 148 free(pp->ahs_addr); |
149 if(pp->ds_size) | 149 if(pp->ds_size) |
150 free(pp->ds); | 150 free(pp->ds_addr); |
151 bzero(&pp->ipdu, sizeof(union ipdu_u)); | 151 bzero(&pp->ipdu, sizeof(union ipdu_u)); |
152 pp->ahs = NULL; 153 pp->ds = NULL; | 152 pp->ahs_addr = NULL; 153 pp->ds_addr = NULL; |
154 pp->ahs_size = 0; 155 pp->ds_size = pp->ds_len = 0; 156} 157 158static void 159pukeText(char *it, pdu_t *pp) 160{ 161 char *ptr; 162 int cmd; 163 size_t len, n; 164 165 len = pp->ds_len; | 154 pp->ahs_size = 0; 155 pp->ds_size = pp->ds_len = 0; 156} 157 158static void 159pukeText(char *it, pdu_t *pp) 160{ 161 char *ptr; 162 int cmd; 163 size_t len, n; 164 165 len = pp->ds_len; |
166 ptr = (char *)pp->ds; | 166 ptr = (char *)pp->ds_addr; |
167 cmd = pp->ipdu.bhs.opcode; 168 169 printf("%s: cmd=0x%x len=%d\n", it, cmd, (int)len); 170 while(len > 0) { 171 printf("\t%s\n", ptr); 172 n = strlen(ptr) + 1; 173 len -= n; 174 ptr += n; 175 } 176} | 167 cmd = pp->ipdu.bhs.opcode; 168 169 printf("%s: cmd=0x%x len=%d\n", it, cmd, (int)len); 170 while(len > 0) { 171 printf("\t%s\n", ptr); 172 n = strlen(ptr) + 1; 173 len -= n; 174 ptr += n; 175 } 176} |