From 14b43651c10b596efc33e11739c22321c3dbc3bf Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 27 Jul 2013 08:43:36 -0400 Subject: Ran the code through: astyle --style=linux --- core/network.c | 64 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'core/network.c') diff --git a/core/network.c b/core/network.c index 8804ab4e..aa16bda9 100644 --- a/core/network.c +++ b/core/network.c @@ -1,7 +1,7 @@ /* network.h - * + * * Functions for the core networking. - * + * * Copyright (C) 2013 Tox project All Rights Reserved. * * This file is part of Tox. @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with Tox. If not, see . - * + * */ #include "network.h" @@ -27,7 +27,7 @@ uint64_t current_time() { uint64_t time; - #ifdef WIN32 +#ifdef WIN32 /* This probably works fine */ FILETIME ft; GetSystemTimeAsFileTime(&ft); @@ -36,24 +36,24 @@ uint64_t current_time() time |= ft.dwLowDateTime; time -= 116444736000000000UL; return time/10; - #else +#else struct timeval a; gettimeofday(&a, NULL); time = 1000000UL*a.tv_sec + a.tv_usec; return time; - #endif +#endif } /* return a random number NOTE: this function should probably not be used where cryptographic randomness is absolutely necessary */ uint32_t random_int() { - #ifndef VANILLA_NACL +#ifndef VANILLA_NACL //NOTE: this function comes from libsodium return randombytes_random(); - #else +#else return random(); - #endif +#endif } /* our UDP socket, a global variable. */ @@ -63,7 +63,7 @@ static int sock; Function to send packet(data) of length length to ip_port */ int sendpacket(IP_Port ip_port, uint8_t * data, uint32_t length) { - ADDR addr = {AF_INET, ip_port.port, ip_port.ip}; + ADDR addr = {AF_INET, ip_port.port, ip_port.ip}; return sendto(sock,(char *) data, length, 0, (struct sockaddr *)&addr, sizeof(addr)); } @@ -74,15 +74,15 @@ int sendpacket(IP_Port ip_port, uint8_t * data, uint32_t length) int receivepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length) { ADDR addr; - #ifdef WIN32 +#ifdef WIN32 int addrlen = sizeof(addr); - #else +#else uint32_t addrlen = sizeof(addr); - #endif +#endif (*(int32_t*)length) = recvfrom(sock,(char*) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr*)&addr, &addrlen); if (*(int32_t*)length <= 0) return -1; /* nothing received or empty packet */ - + ip_port->ip = addr.ip; ip_port->port = addr.port; return 0; @@ -92,30 +92,30 @@ int receivepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length) bind to ip and port ip must be in network order EX: 127.0.0.1 = (7F000001) port is in host byte order (this means don't worry about it) - returns 0 if no problems + returns 0 if no problems returns -1 if there are problems */ int init_networking(IP ip, uint16_t port) { - #ifdef WIN32 +#ifdef WIN32 WSADATA wsaData; if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) return -1; - #else +#else srandom((uint32_t)current_time()); - #endif +#endif srand((uint32_t)current_time()); /* initialize our socket */ - sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); /* Check for socket error */ - #ifdef WIN32 +#ifdef WIN32 if (sock == INVALID_SOCKET) /* MSDN recommends this */ return -1; - #else +#else if (sock < 0) return -1; - #endif +#endif /* Functions to increase the size of the send and receive UDP buffers NOTE: uncomment if necessary */ @@ -129,23 +129,23 @@ int init_networking(IP ip, uint16_t port) if(setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char*)&n, sizeof(n)) == -1) return -1; */ - + /* Enable broadcast on socket */ int broadcast = 1; setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*)&broadcast, sizeof(broadcast)); /* Set socket nonblocking */ - #ifdef WIN32 +#ifdef WIN32 /* I think this works for windows */ u_long mode = 1; /* ioctl(sock, FIONBIO, &mode); */ - ioctlsocket(sock, FIONBIO, &mode); - #else + ioctlsocket(sock, FIONBIO, &mode); +#else fcntl(sock, F_SETFL, O_NONBLOCK, 1); - #endif - +#endif + /* Bind our socket to port PORT and address 0.0.0.0 */ - ADDR addr = {AF_INET, htons(port), ip}; + ADDR addr = {AF_INET, htons(port), ip}; bind(sock, (struct sockaddr*)&addr, sizeof(addr)); return 0; @@ -155,12 +155,12 @@ int init_networking(IP ip, uint16_t port) /* function to cleanup networking stuff */ void shutdown_networking() { - #ifdef WIN32 +#ifdef WIN32 closesocket(sock); WSACleanup(); - #else +#else close(sock); - #endif +#endif return; } -- cgit v1.2.3