diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c index 7ac70f757..4d8ec2615 100644 --- a/src/plugins/xfer/xfer.c +++ b/src/plugins/xfer/xfer.c @@ -669,21 +669,14 @@ xfer_new (const char *plugin_name, const char *plugin_id, snprintf (str_address, sizeof (str_address), "?"); } - new_xfer->local_address = calloc (1, sizeof (struct sockaddr_storage)); - new_xfer->local_address_length = sizeof (struct sockaddr_storage); - new_xfer->remote_address = calloc (1, sizeof (struct sockaddr_storage)); - new_xfer->remote_address_length = sizeof (struct sockaddr_storage); - if (XFER_IS_RECV(type)) { new_xfer->local_address_str = strdup (""); - new_xfer->remote_address_str = strdup (str_address); - memcpy (new_xfer->remote_address, address, address_length); + xfer_set_remote_address(new_xfer, address, address_length, str_address); } else { - new_xfer->local_address_str = strdup (str_address); - memcpy (new_xfer->local_address, address, address_length); + xfer_set_local_address(new_xfer, address, address_length, str_address); new_xfer->remote_address_str = strdup (""); } @@ -835,12 +828,12 @@ xfer_new (const char *plugin_name, const char *plugin_id, */ void -xfer_set_remote_address (struct t_xfer *xfer, struct sockaddr *address, - socklen_t length, char *address_str) +xfer_set_remote_address (struct t_xfer *xfer, const struct sockaddr *address, + socklen_t length, const char *address_str) { if (xfer->remote_address) free (xfer->remote_address); - xfer->remote_address = calloc (1, length); + xfer->remote_address = malloc (length); xfer->remote_address_length = length; memcpy (xfer->remote_address, address, length); @@ -849,6 +842,24 @@ xfer_set_remote_address (struct t_xfer *xfer, struct sockaddr *address, xfer->remote_address_str = strdup ((address_str) ? address_str : ""); } +/* + * Sets the local address field. + */ +void +xfer_set_local_address (struct t_xfer *xfer, const struct sockaddr *address, + socklen_t length, const char *address_str) +{ + if (xfer->local_address) + free (xfer->local_address); + xfer->local_address = malloc (length); + xfer->local_address_length = length; + memcpy (xfer->local_address, address, length); + + if (xfer->local_address_str) + free (xfer->local_address_str); + xfer->local_address_str = strdup ((address_str) ? address_str : ""); +} + /* * Frees xfer struct and removes it from list. */ diff --git a/src/plugins/xfer/xfer.h b/src/plugins/xfer/xfer.h index c4f9758d4..c9c1edd72 100644 --- a/src/plugins/xfer/xfer.h +++ b/src/plugins/xfer/xfer.h @@ -196,8 +196,11 @@ extern struct t_xfer *xfer_search_by_buffer (struct t_gui_buffer *buffer); extern void xfer_close (struct t_xfer *xfer, enum t_xfer_status status); extern void xfer_send_signal (struct t_xfer *xfer, const char *signal); extern void xfer_set_remote_address (struct t_xfer *xfer, - struct sockaddr *address, socklen_t length, - char *address_str); + const struct sockaddr *address, + socklen_t length, const char *address_str); +extern void xfer_set_local_address (struct t_xfer *xfer, + const struct sockaddr *address, + socklen_t length, const char *address_str); extern void xfer_free (struct t_xfer *xfer); extern int xfer_add_to_infolist (struct t_infolist *infolist, struct t_xfer *xfer);