summaryrefslogtreecommitdiff
path: root/core/network.c
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-07-26 15:13:44 -0700
committerirungentoo <irungentoo@gmail.com>2013-07-26 15:13:44 -0700
commitbd48ef52ec99cc45a6b361d8072eef34c343045a (patch)
treed4a4409160753f209b8f70ee50c73b07efe251be /core/network.c
parentef2e0c7aad804c3b96f07b5ddfaef9b7929904a9 (diff)
parenta3298d2b9e8174f39c8d11f6df8526f360f65592 (diff)
Merge pull request #107 from sometwo/patch-4
Fix some indenting
Diffstat (limited to 'core/network.c')
-rw-r--r--core/network.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/core/network.c b/core/network.c
index 6a4d0bce..549427bf 100644
--- a/core/network.c
+++ b/core/network.c
@@ -42,8 +42,6 @@ uint64_t current_time()
42 time = 1000000UL*a.tv_sec + a.tv_usec; 42 time = 1000000UL*a.tv_sec + a.tv_usec;
43 return time; 43 return time;
44 #endif 44 #endif
45
46
47} 45}
48 46
49/* return a random number 47/* return a random number
@@ -67,7 +65,6 @@ int sendpacket(IP_Port ip_port, uint8_t * data, uint32_t length)
67{ 65{
68 ADDR addr = {AF_INET, ip_port.port, ip_port.ip}; 66 ADDR addr = {AF_INET, ip_port.port, ip_port.ip};
69 return sendto(sock,(char *) data, length, 0, (struct sockaddr *)&addr, sizeof(addr)); 67 return sendto(sock,(char *) data, length, 0, (struct sockaddr *)&addr, sizeof(addr));
70
71} 68}
72 69
73/* Function to receive data, ip and port of sender is put into ip_port 70/* Function to receive data, ip and port of sender is put into ip_port
@@ -92,7 +89,6 @@ int receivepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length)
92 ip_port->ip = addr.ip; 89 ip_port->ip = addr.ip;
93 ip_port->port = addr.port; 90 ip_port->port = addr.port;
94 return 0; 91 return 0;
95
96} 92}
97 93
98/* initialize networking 94/* initialize networking
@@ -106,21 +102,18 @@ int init_networking(IP ip, uint16_t port)
106 #ifdef WIN32 102 #ifdef WIN32
107 WSADATA wsaData; 103 WSADATA wsaData;
108 if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) 104 if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR)
109 {
110 return -1; 105 return -1;
111 }
112
113 #else 106 #else
114 srandom((uint32_t)current_time()); 107 srandom((uint32_t)current_time());
115 #endif 108 #endif
116 srand((uint32_t)current_time()); 109 srand((uint32_t)current_time());
117 110
118 /* initialize our socket */ 111 /* initialize our socket */
119 sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 112 sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
120 113
121 /* Check for socket error */ 114 /* Check for socket error */
122 #ifdef WIN32 115 #ifdef WIN32
123 if (sock == INVALID_SOCKET) //MSDN recommends this 116 if (sock == INVALID_SOCKET) /* MSDN recommends this */
124 return -1; 117 return -1;
125 #else 118 #else
126 if (sock < 0) 119 if (sock < 0)
@@ -137,11 +130,10 @@ int init_networking(IP ip, uint16_t port)
137 } 130 }
138 131
139 if(setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char*)&n, sizeof(n)) == -1) 132 if(setsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char*)&n, sizeof(n)) == -1)
140 {
141 return -1; 133 return -1;
142 }*/ 134 */
143 135
144 /*Enable broadcast on socket*/ 136 /* Enable broadcast on socket */
145 int broadcast = 1; 137 int broadcast = 1;
146 setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*)&broadcast, sizeof(broadcast)); 138 setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char*)&broadcast, sizeof(broadcast));
147 139
@@ -188,11 +180,9 @@ int resolve_addr(char *address)
188 180
189 int success = getaddrinfo(address, "7", &hints, &server); 181 int success = getaddrinfo(address, "7", &hints, &server);
190 if(success != 0) 182 if(success != 0)
191 {
192 return -1; 183 return -1;
193 }
194 184
195 int resolved = ((struct sockaddr_in*)server->ai_addr)->sin_addr.s_addr; 185 int resolved = ((struct sockaddr_in*)server->ai_addr)->sin_addr.s_addr;
196 freeaddrinfo(server); 186 freeaddrinfo(server);
197 return resolved; 187 return resolved;
198} \ No newline at end of file 188}