1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

xfer: Don't use sockaddr_storage for address_length

Hopefully this addresses #25.
This commit is contained in:
Andrew Potter
2014-03-13 20:06:05 -07:00
parent d52e5d8c8a
commit 92d454eb8d
2 changed files with 28 additions and 14 deletions
+23 -12
View File
@@ -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.
*/
+5 -2
View File
@@ -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);