socket: Indent according to profile
This commit is contained in:
+30
-16
@@ -25,42 +25,47 @@ typedef struct {
|
|||||||
} sa_t;
|
} sa_t;
|
||||||
|
|
||||||
|
|
||||||
static int _sa_host_lookup(sa_t * sa, const char *host, const char *port)
|
static int _sa_host_lookup(sa_t *sa, const char *host, const char *port)
|
||||||
{
|
{
|
||||||
struct addrinfo hint, *adrinf = NULL, *p;
|
struct addrinfo hint, *adrinf = NULL, *p;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
memset(&hint, 0, sizeof(struct addrinfo));
|
memset(&hint, 0, sizeof(struct addrinfo));
|
||||||
|
|
||||||
if(getaddrinfo(host, port, &hint, &adrinf) != 0) {
|
if (getaddrinfo(host, port, &hint, &adrinf) != 0)
|
||||||
|
{
|
||||||
nvt_log(LOG_ERR, "Cannot resolve host name: %m\n");
|
nvt_log(LOG_ERR, "Cannot resolve host name: %m\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Priority is given to the use of IPv4
|
// Priority is given to the use of IPv4
|
||||||
// This code must be modified if the preffered protocol is changed or varied.
|
// This code must be modified if the preffered protocol is changed or varied.
|
||||||
for(p = adrinf; p; p = p->ai_next) {
|
for (p = adrinf; p; p = p->ai_next)
|
||||||
if(p->ai_family == AF_INET) {
|
{
|
||||||
|
if (p->ai_family == AF_INET)
|
||||||
|
{
|
||||||
sa->slen = sizeof(sa->ipv4);
|
sa->slen = sizeof(sa->ipv4);
|
||||||
memcpy(&sa->ipv4, p->ai_addr, sizeof(struct sockaddr_in));
|
memcpy(&sa->ipv4, p->ai_addr, sizeof(struct sockaddr_in));
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto exit_host_lookup;
|
goto exit_host_lookup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(p = adrinf; p; p = p->ai_next) {
|
for (p = adrinf; p; p = p->ai_next)
|
||||||
if(p->ai_family == AF_INET6) {
|
{
|
||||||
|
if (p->ai_family == AF_INET6)
|
||||||
|
{
|
||||||
sa->slen = sizeof(sa->ipv6);
|
sa->slen = sizeof(sa->ipv6);
|
||||||
memcpy(&sa->ipv6, p->ai_addr, sizeof(struct sockaddr_in6));
|
memcpy(&sa->ipv6, p->ai_addr, sizeof(struct sockaddr_in6));
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto exit_host_lookup;
|
goto exit_host_lookup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exit_host_lookup:
|
exit_host_lookup:
|
||||||
freeaddrinfo(adrinf);
|
freeaddrinfo(adrinf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int _sa_addr_parse(sa_t * sa, const char *addr)
|
static int _sa_addr_parse(sa_t *sa, const char *addr)
|
||||||
{
|
{
|
||||||
ssize_t host_len;
|
ssize_t host_len;
|
||||||
char host[64];
|
char host[64];
|
||||||
@@ -68,9 +73,11 @@ static int _sa_addr_parse(sa_t * sa, const char *addr)
|
|||||||
|
|
||||||
memset(sa, 0, sizeof(sa_t));
|
memset(sa, 0, sizeof(sa_t));
|
||||||
|
|
||||||
if (strncmp(addr, "unix:", 5) == 0) { // case of unix domain sockets ...
|
if (strncmp(addr, "unix:", 5) == 0)
|
||||||
|
{ // case of unix domain sockets ...
|
||||||
addr += 5; // skip "unix:" prefix
|
addr += 5; // skip "unix:" prefix
|
||||||
if(strlen(addr) > sizeof(sa->un.sun_path) - 1) {
|
if (strlen(addr) > sizeof(sa->un.sun_path) - 1)
|
||||||
|
{
|
||||||
nvt_log(LOG_ERR, "UNIX domain socket path is too long.\n");
|
nvt_log(LOG_ERR, "UNIX domain socket path is too long.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -81,23 +88,30 @@ static int _sa_addr_parse(sa_t * sa, const char *addr)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(port = strrchr(addr, ':'))) {
|
if (!(port = strrchr(addr, ':')))
|
||||||
|
{
|
||||||
nvt_log(LOG_ERR, "bad server address format.\n");
|
nvt_log(LOG_ERR, "bad server address format.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
host_len = (port++) - addr;
|
host_len = (port++) - addr;
|
||||||
// *port indicates the last ':', its next is 1st char of the port number
|
// *port indicates the last ':', its next is 1st char of the port number
|
||||||
if(host_len >= 2 && addr[0] == '[' && addr[host_len-1] == ']') {
|
if (host_len >= 2 && addr[0] == '[' && addr[host_len - 1] == ']')
|
||||||
|
{
|
||||||
// IPv6 addresses are enclosed in pair of square brackets.
|
// IPv6 addresses are enclosed in pair of square brackets.
|
||||||
addr += 1;
|
addr += 1;
|
||||||
host_len -= 2;
|
host_len -= 2;
|
||||||
} else {
|
}
|
||||||
if(strchr(addr, ':') != port-1) {
|
else
|
||||||
nvt_log(LOG_ERR, "addresses containing colons must be enclosed in square brackets.\n");
|
{
|
||||||
|
if (strchr(addr, ':') != port - 1)
|
||||||
|
{
|
||||||
|
nvt_log(LOG_ERR,
|
||||||
|
"addresses containing colons must be enclosed in square brackets.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if((ssize_t)sizeof(host) <= host_len) {
|
if ((ssize_t) sizeof(host) <= host_len)
|
||||||
|
{
|
||||||
nvt_log(LOG_ERR, "host name is too long.\n");
|
nvt_log(LOG_ERR, "host name is too long.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user