diff options
author | Mike Christie <michaelc@cs.wisc.edu> | 2011-02-16 16:04:35 -0500 |
---|---|---|
committer | James Bottomley <James.Bottomley@suse.de> | 2011-02-24 12:41:08 -0500 |
commit | 00f3708e6ed1698d6aee3901ea991197e31a8007 (patch) | |
tree | 6ae295fe4c03de52525f32c4bf8a732e19aa1c82 /drivers/scsi/libiscsi.c | |
parent | bbc5261b2cb5e69754c935ea2466fb22775f0e48 (diff) |
[SCSI] libiscsi: add helper to convert addr to string
This adds a helper to convert a addr struct to
a string. This will be used by the drivers in
the next patches.
Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Signed-off-by: James Bottomley <James.Bottomley@suse.de>
Diffstat (limited to 'drivers/scsi/libiscsi.c')
-rw-r--r-- | drivers/scsi/libiscsi.c | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index da8b61543ee4..0c550d5b9133 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c | |||
@@ -3352,6 +3352,47 @@ int iscsi_session_get_param(struct iscsi_cls_session *cls_session, | |||
3352 | } | 3352 | } |
3353 | EXPORT_SYMBOL_GPL(iscsi_session_get_param); | 3353 | EXPORT_SYMBOL_GPL(iscsi_session_get_param); |
3354 | 3354 | ||
3355 | int iscsi_conn_get_addr_param(struct sockaddr_storage *addr, | ||
3356 | enum iscsi_param param, char *buf) | ||
3357 | { | ||
3358 | struct sockaddr_in6 *sin6 = NULL; | ||
3359 | struct sockaddr_in *sin = NULL; | ||
3360 | int len; | ||
3361 | |||
3362 | switch (addr->ss_family) { | ||
3363 | case AF_INET: | ||
3364 | sin = (struct sockaddr_in *)addr; | ||
3365 | break; | ||
3366 | case AF_INET6: | ||
3367 | sin6 = (struct sockaddr_in6 *)addr; | ||
3368 | break; | ||
3369 | default: | ||
3370 | return -EINVAL; | ||
3371 | } | ||
3372 | |||
3373 | switch (param) { | ||
3374 | case ISCSI_PARAM_CONN_ADDRESS: | ||
3375 | case ISCSI_HOST_PARAM_IPADDRESS: | ||
3376 | if (sin) | ||
3377 | len = sprintf(buf, "%pI4\n", &sin->sin_addr.s_addr); | ||
3378 | else | ||
3379 | len = sprintf(buf, "%pI6\n", &sin6->sin6_addr); | ||
3380 | break; | ||
3381 | case ISCSI_PARAM_CONN_PORT: | ||
3382 | if (sin) | ||
3383 | len = sprintf(buf, "%hu\n", be16_to_cpu(sin->sin_port)); | ||
3384 | else | ||
3385 | len = sprintf(buf, "%hu\n", | ||
3386 | be16_to_cpu(sin6->sin6_port)); | ||
3387 | break; | ||
3388 | default: | ||
3389 | return -EINVAL; | ||
3390 | } | ||
3391 | |||
3392 | return len; | ||
3393 | } | ||
3394 | EXPORT_SYMBOL_GPL(iscsi_conn_get_addr_param); | ||
3395 | |||
3355 | int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn, | 3396 | int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn, |
3356 | enum iscsi_param param, char *buf) | 3397 | enum iscsi_param param, char *buf) |
3357 | { | 3398 | { |
@@ -3416,9 +3457,6 @@ int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param, | |||
3416 | case ISCSI_HOST_PARAM_INITIATOR_NAME: | 3457 | case ISCSI_HOST_PARAM_INITIATOR_NAME: |
3417 | len = sprintf(buf, "%s\n", ihost->initiatorname); | 3458 | len = sprintf(buf, "%s\n", ihost->initiatorname); |
3418 | break; | 3459 | break; |
3419 | case ISCSI_HOST_PARAM_IPADDRESS: | ||
3420 | len = sprintf(buf, "%s\n", ihost->local_address); | ||
3421 | break; | ||
3422 | default: | 3460 | default: |
3423 | return -ENOSYS; | 3461 | return -ENOSYS; |
3424 | } | 3462 | } |