summaryrefslogtreecommitdiff
path: root/core/network.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/network.c')
-rw-r--r--core/network.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/core/network.c b/core/network.c
index 9ec390fb..849c7e2a 100644
--- a/core/network.c
+++ b/core/network.c
@@ -86,13 +86,13 @@ static int receivepacket(int sock, IP_Port *ip_port, uint8_t *data, uint32_t *le
86 return 0; 86 return 0;
87} 87}
88 88
89void networking_registerhandler(Networking_Core * net, uint8_t byte, packet_handler_callback cb, void * object) 89void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handler_callback cb, void *object)
90{ 90{
91 net->packethandlers[byte].function = cb; 91 net->packethandlers[byte].function = cb;
92 net->packethandlers[byte].object = object; 92 net->packethandlers[byte].object = object;
93} 93}
94 94
95void networking_poll(Networking_Core * net) 95void networking_poll(Networking_Core *net)
96{ 96{
97 IP_Port ip_port; 97 IP_Port ip_port;
98 uint8_t data[MAX_UDP_PACKET_SIZE]; 98 uint8_t data[MAX_UDP_PACKET_SIZE];
@@ -112,6 +112,7 @@ static void at_startup(void)
112{ 112{
113 if (at_startup_ran != 0) 113 if (at_startup_ran != 0)
114 return; 114 return;
115
115#ifdef WIN32 116#ifdef WIN32
116 WSADATA wsaData; 117 WSADATA wsaData;
117 118
@@ -121,7 +122,7 @@ static void at_startup(void)
121#else 122#else
122 srandom((uint32_t)current_time()); 123 srandom((uint32_t)current_time());
123#endif 124#endif
124 srand((uint32_t)current_time()); 125 srand((uint32_t)current_time());
125 at_startup_ran = 1; 126 at_startup_ran = 1;
126} 127}
127 128
@@ -130,7 +131,7 @@ static void at_shutdown(void)
130{ 131{
131#ifdef WIN32 132#ifdef WIN32
132 WSACleanup(); 133 WSACleanup();
133#endif 134#endif
134} 135}
135*/ 136*/
136 137
@@ -140,13 +141,15 @@ static void at_shutdown(void)
140 port is in host byte order (this means don't worry about it) 141 port is in host byte order (this means don't worry about it)
141 returns Networking_Core object if no problems 142 returns Networking_Core object if no problems
142 returns NULL if there are problems */ 143 returns NULL if there are problems */
143Networking_Core * new_networking(IP ip, uint16_t port) 144Networking_Core *new_networking(IP ip, uint16_t port)
144{ 145{
145 at_startup(); 146 at_startup();
146 /* initialize our socket */ 147 /* initialize our socket */
147 Networking_Core * temp = calloc(1, sizeof(Networking_Core)); 148 Networking_Core *temp = calloc(1, sizeof(Networking_Core));
149
148 if (temp == NULL) 150 if (temp == NULL)
149 return NULL; 151 return NULL;
152
150 temp->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 153 temp->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
151 154
152 /* Check for socket error */ 155 /* Check for socket error */
@@ -200,7 +203,7 @@ Networking_Core * new_networking(IP ip, uint16_t port)
200} 203}
201 204
202/* function to cleanup networking stuff */ 205/* function to cleanup networking stuff */
203void kill_networking(Networking_Core * net) 206void kill_networking(Networking_Core *net)
204{ 207{
205#ifdef WIN32 208#ifdef WIN32
206 closesocket(net->sock); 209 closesocket(net->sock);