auth: use sockaddr_storage to store ports

This commit is contained in:
Elizabeth Myers 2016-03-10 09:32:37 -06:00
parent c70ae2e5cb
commit b74739c247
2 changed files with 17 additions and 9 deletions

View file

@ -174,7 +174,7 @@ void notice_client(struct auth_client *auth, const char *notice)
} }
/* Begin authenticating user */ /* Begin authenticating user */
static void start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_addr, const char *c_port) static void start_auth(const char *cid, const char *l_ip, const char *l_port, const char *c_ip, const char *c_port)
{ {
rb_dlink_node *ptr; rb_dlink_node *ptr;
struct auth_provider *provider; struct auth_provider *provider;
@ -191,11 +191,22 @@ static void start_auth(const char *cid, const char *l_ip, const char *l_port, co
auth->cid = (uint16_t)lcid; auth->cid = (uint16_t)lcid;
(void)rb_inet_pton_sock(l_ip, (struct sockaddr *)&auth->l_ip); (void)rb_inet_pton_sock(l_ip, (struct sockaddr *)&auth->l_addr);
auth->l_port = (uint16_t)atoi(l_port); /* Safe cast, port shouldn't exceed 16 bits */ #ifdef RB_IPV6
if(GET_SS_FAMILY(&auth->l_addr) == AF_INET6)
((struct sockaddr_in6 *)&auth->l_addr)->sin6_port = htons(atoi(l_ip));
else
#endif
((struct sockaddr_in *)&auth->l_addr)->sin_port = htons(atoi(l_ip));
(void)rb_inet_pton_sock(c_ip, (struct sockaddr *)&auth->c_addr);
#ifdef RB_IPV6
if(GET_SS_FAMILY(&auth->c_addr) == AF_INET6)
((struct sockaddr_in6 *)&auth->c_addr)->sin6_port = htons(atoi(c_ip));
else
#endif
((struct sockaddr_in *)&auth->c_addr)->sin_port = htons(atoi(c_ip));
(void)rb_inet_pton_sock(c_addr, (struct sockaddr *)&auth->c_addr);
auth->c_port = (uint16_t)atoi(c_port);
RB_DLINK_FOREACH(ptr, auth_providers.head) RB_DLINK_FOREACH(ptr, auth_providers.head)
{ {

View file

@ -39,11 +39,8 @@ struct auth_client
{ {
uint16_t cid; /* Client ID */ uint16_t cid; /* Client ID */
struct rb_sockaddr_storage l_ip; /* Listener IP address */ struct rb_sockaddr_storage l_addr; /* Listener IP address */
uint16_t l_port; /* Listener port */
struct rb_sockaddr_storage c_addr; /* Client IP address */ struct rb_sockaddr_storage c_addr; /* Client IP address */
uint16_t c_port; /* Client port */
char hostname[HOSTLEN + 1]; /* Used for DNS lookup */ char hostname[HOSTLEN + 1]; /* Used for DNS lookup */
char username[USERLEN + 1]; /* Used for ident lookup */ char username[USERLEN + 1]; /* Used for ident lookup */