Skip to content

Commit

Permalink
Fix formatting with astyle
Browse files Browse the repository at this point in the history
Fix #494
  • Loading branch information
Diadlo committed Mar 4, 2017
1 parent f91af5c commit c1e3358
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
1 change: 1 addition & 0 deletions testing/dns3_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ int main(int argc, char *argv[])
}

unsigned int i;

for (i = r_len - 1; i != 0 && buffer[i] != '='; --i) {
;
}
Expand Down
55 changes: 33 additions & 22 deletions toxcore/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -1209,16 +1209,19 @@ int net_connect(Socket sock, IP_Port ip_port)
return connect(sock, (struct sockaddr *)&addr, addrsize);
}

int32_t net_getipport(const char* node, IP_Port** res, int type)
int32_t net_getipport(const char *node, IP_Port **res, int type)
{
struct addrinfo *infos;
int ret = getaddrinfo(node, NULL, NULL, &infos);

if (ret != 0) {
return -1;
}

struct addrinfo *cur;

int count = 0;

for (cur = infos; count < INT32_MAX && cur != NULL; cur = cur->ai_next) {
if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
continue;
Expand All @@ -1235,12 +1238,14 @@ int32_t net_getipport(const char* node, IP_Port** res, int type)
return -1;
}

*res = (IP_Port*)malloc(sizeof(IP_Port) * count);
*res = (IP_Port *)malloc(sizeof(IP_Port) * count);

if (*res == NULL) {
return -1;
}

IP_Port *ip_port = *res;

for (cur = infos; cur != NULL; cur = cur->ai_next) {
if (cur->ai_socktype && type > 0 && cur->ai_socktype != type) {
continue;
Expand All @@ -1266,7 +1271,7 @@ int32_t net_getipport(const char* node, IP_Port** res, int type)
return count;
}

void net_freeipport(IP_Port* ip_ports)
void net_freeipport(IP_Port *ip_ports)
{
free(ip_ports);
}
Expand Down Expand Up @@ -1301,36 +1306,42 @@ int bind_to_port(Socket sock, int family, uint16_t port)
static int make_family(int family)
{
switch (family) {
case TOX_AF_INET:
return AF_INET;
case TOX_AF_INET6:
return AF_INET6;
default:
return family;
case TOX_AF_INET:
return AF_INET;

case TOX_AF_INET6:
return AF_INET6;

default:
return family;
}
}

static int make_socktype(int type)
{
switch (type) {
case TOX_SOCK_STREAM:
return SOCK_STREAM;
case TOX_SOCK_DGRAM:
return SOCK_DGRAM;
default:
return type;
case TOX_SOCK_STREAM:
return SOCK_STREAM;

case TOX_SOCK_DGRAM:
return SOCK_DGRAM;

default:
return type;
}
}

static int make_proto(int proto)
{
switch (proto) {
case TOX_PROTO_TCP:
return IPPROTO_TCP;
case TOX_PROTO_UDP:
return IPPROTO_UDP;
default:
return proto;
case TOX_PROTO_TCP:
return IPPROTO_TCP;

case TOX_PROTO_UDP:
return IPPROTO_UDP;

default:
return proto;
}
}

Expand All @@ -1345,7 +1356,7 @@ Socket net_socket(int domain, int type, int protocol)
/* TODO: Remove, when tox DNS support will be removed.
* Used only by dns3_test.c
*/
size_t net_sendto_ip4(Socket sock, const char* buf, size_t n, IP_Port ip_port)
size_t net_sendto_ip4(Socket sock, const char *buf, size_t n, IP_Port ip_port)
{
struct sockaddr_in target;
size_t addrsize = sizeof(target);
Expand Down
6 changes: 3 additions & 3 deletions toxcore/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -391,18 +391,18 @@ int net_connect(Socket sock, IP_Port ip_port);
*
* return number of elements in res array.
*/
int32_t net_getipport(const char* node, IP_Port** res, int type);
int32_t net_getipport(const char *node, IP_Port **res, int type);

/* Deallocates memory allocated by net_getipport
*/
void net_freeipport(IP_Port* ip_ports);
void net_freeipport(IP_Port *ip_ports);

/* return 1 on success
* return 0 on failure
*/
int bind_to_port(Socket sock, int family, uint16_t port);

size_t net_sendto_ip4(Socket sock, const char* buf, size_t n, IP_Port ip_port);
size_t net_sendto_ip4(Socket sock, const char *buf, size_t n, IP_Port ip_port);

/* Initialize networking.
* bind to ip and port.
Expand Down
6 changes: 5 additions & 1 deletion toxcore/tox.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,14 @@ bool tox_bootstrap(Tox *tox, const char *address, uint16_t port, const uint8_t *
IP_Port *root;

int32_t count = net_getipport(address, &root, SOCK_DGRAM);

if (count == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
return 0;
}

unsigned int i;

for (i = 0; i < count; i++) {
root[i].port = htons(port);

Expand Down Expand Up @@ -277,12 +279,14 @@ bool tox_add_tcp_relay(Tox *tox, const char *address, uint16_t port, const uint8
IP_Port *root;

int32_t count = net_getipport(address, &root, SOCK_STREAM);

if (count == -1) {
SET_ERROR_PARAMETER(error, TOX_ERR_BOOTSTRAP_BAD_HOST);
return 0;
}

unsigned int i;

for (i = 0; i < count; i++) {
root[i].port = htons(port);

Expand Down Expand Up @@ -1513,7 +1517,7 @@ void tox_self_get_dht_id(const Tox *tox, uint8_t *dht_id)
{
if (dht_id) {
const Messenger *m = tox;
memcpy(dht_id , m->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
memcpy(dht_id, m->dht->self_public_key, CRYPTO_PUBLIC_KEY_SIZE);
}
}

Expand Down

0 comments on commit c1e3358

Please sign in to comment.