Remove unused string support in scp_session_set_addr()

Using the same argument for binary and text data is not a good idea. If
string support is ever needed, it should be a separate function.

Remove SCP_ADDRESS_TYPE_IPV4_BIN and SCP_ADDRESS_TYPE_IPV6_BIN, use
SCP_ADDRESS_TYPE_IPV4 and SCP_ADDRESS_TYPE_IPV6, which simplifies the
code.
master
Pavel Roskin 9 years ago
parent f908528a00
commit 1ded8ec437

@ -396,49 +396,15 @@ scp_session_set_display(struct SCP_SESSION *s, SCP_DISPLAY display)
/*******************************************************************/
int
scp_session_set_addr(struct SCP_SESSION *s, int type, void *addr)
scp_session_set_addr(struct SCP_SESSION *s, int type, const void *addr)
{
struct in_addr ip4;
#ifdef IN6ADDR_ANY_INIT
struct in6_addr ip6;
#endif
int ret;
switch (type)
{
case SCP_ADDRESS_TYPE_IPV4:
/* convert from char to 32bit*/
ret = inet_pton(AF_INET, addr, &ip4);
if (ret == 0)
{
log_message(LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__);
inet_pton(AF_INET, "127.0.0.1", &ip4);
g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4);
return 1;
}
g_memcpy(&(s->ipv4addr), &(ip4.s_addr), 4);
break;
case SCP_ADDRESS_TYPE_IPV4_BIN:
g_memcpy(&(s->ipv4addr), addr, 4);
break;
#ifdef IN6ADDR_ANY_INIT
case SCP_ADDRESS_TYPE_IPV6:
/* convert from char to 128bit*/
ret = inet_pton(AF_INET6, addr, &ip6);
if (ret == 0)
{
log_message(LOG_LEVEL_WARNING, "[session:%d] set_addr: invalid address", __LINE__);
inet_pton(AF_INET, "::1", &ip6);
g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16);
return 1;
}
g_memcpy(s->ipv6addr, &(ip6.s6_addr), 16);
break;
case SCP_ADDRESS_TYPE_IPV6_BIN:
g_memcpy(s->ipv6addr, addr, 16);
break;
#endif

@ -83,7 +83,7 @@ int
scp_session_set_hostname(struct SCP_SESSION* s, char* str);
int
scp_session_set_addr(struct SCP_SESSION* s, int type, void* addr);
scp_session_set_addr(struct SCP_SESSION* s, int type, const void* addr);
int
scp_session_set_display(struct SCP_SESSION* s, SCP_DISPLAY display);

@ -51,10 +51,6 @@
#define SCP_ADDRESS_TYPE_IPV4 0x00
#define SCP_ADDRESS_TYPE_IPV6 0x01
/* used in scp_session_set_addr() */
#define SCP_ADDRESS_TYPE_IPV4_BIN 0x80
#define SCP_ADDRESS_TYPE_IPV6_BIN 0x81
#define SCP_COMMAND_SET_DEFAULT 0x0000
#define SCP_COMMAND_SET_MANAGE 0x0001
#define SCP_COMMAND_SET_RSR 0x0002

@ -150,12 +150,12 @@ enum SCP_SERVER_STATES_E scp_v1s_accept(struct SCP_CONNECTION *c, struct SCP_SES
if (sz == SCP_ADDRESS_TYPE_IPV4)
{
in_uint32_be(c->in_s, size);
scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &size);
scp_session_set_addr(session, sz, &size);
}
else if (sz == SCP_ADDRESS_TYPE_IPV6)
{
in_uint8a(c->in_s, buf, 16);
scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV6_BIN, buf);
scp_session_set_addr(session, sz, buf);
}
buf[256] = '\0';

@ -90,12 +90,12 @@ scp_v1s_mng_accept(struct SCP_CONNECTION *c, struct SCP_SESSION **s)
if (sz == SCP_ADDRESS_TYPE_IPV4)
{
in_uint32_be(c->in_s, ipaddr);
scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV4_BIN, &ipaddr);
scp_session_set_addr(session, sz, &ipaddr);
}
else if (sz == SCP_ADDRESS_TYPE_IPV6)
{
in_uint8a(c->in_s, buf, 16);
scp_session_set_addr(session, SCP_ADDRESS_TYPE_IPV6_BIN, buf);
scp_session_set_addr(session, sz, buf);
}
/* reading hostname */

Loading…
Cancel
Save