summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Messenger.c8
-rw-r--r--core/Messenger.h6
-rw-r--r--core/network.c19
-rw-r--r--core/network.h3
4 files changed, 26 insertions, 10 deletions
diff --git a/core/Messenger.c b/core/Messenger.c
index 1330e8ed..043700e5 100644
--- a/core/Messenger.c
+++ b/core/Messenger.c
@@ -393,14 +393,18 @@ void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t))
393 393
394#define PORT 33445 394#define PORT 33445
395/* run this at startup */ 395/* run this at startup */
396void initMessenger() 396int initMessenger()
397{ 397{
398 new_keys(); 398 new_keys();
399 m_set_userstatus((uint8_t*)"Online", sizeof("Online")); 399 m_set_userstatus((uint8_t*)"Online", sizeof("Online"));
400 initNetCrypto(); 400 initNetCrypto();
401 IP ip; 401 IP ip;
402 ip.i = 0; 402 ip.i = 0;
403 init_networking(ip, PORT); 403
404 if(init_networking(ip,PORT) == -1)
405 return -1;
406
407 return 0;
404} 408}
405 409
406static void doFriends() 410static void doFriends()
diff --git a/core/Messenger.h b/core/Messenger.h
index 2484692c..6afe84ac 100644
--- a/core/Messenger.h
+++ b/core/Messenger.h
@@ -132,8 +132,10 @@ void m_callback_namechange(void (*function)(int, uint8_t *, uint16_t));
132 you are not responsible for freeing newstatus */ 132 you are not responsible for freeing newstatus */
133void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t)); 133void m_callback_userstatus(void (*function)(int, uint8_t *, uint16_t));
134 134
135/* run this at startup */ 135/* run this at startup
136void initMessenger(); 136 returns 0 if no connection problems
137 returns -1 if there are problems */
138int initMessenger();
137 139
138 140
139/* the main loop that needs to be run at least 200 times per second */ 141/* the main loop that needs to be run at least 200 times per second */
diff --git a/core/network.c b/core/network.c
index 6337651a..bc6738ac 100644
--- a/core/network.c
+++ b/core/network.c
@@ -101,8 +101,8 @@ int receivepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length)
101 bind to ip and port 101 bind to ip and port
102 ip must be in network order EX: 127.0.0.1 = (7F000001) 102 ip must be in network order EX: 127.0.0.1 = (7F000001)
103 port is in host byte order (this means don't worry about it) 103 port is in host byte order (this means don't worry about it)
104 returns 0 if no problems 104 returns 0 if no problems
105 TODO: add something to check if there are errors */ 105 returns -1 if there are problems */
106int init_networking(IP ip ,uint16_t port) 106int init_networking(IP ip ,uint16_t port)
107{ 107{
108 #ifdef WIN32 108 #ifdef WIN32
@@ -119,7 +119,17 @@ int init_networking(IP ip ,uint16_t port)
119 119
120 /* initialize our socket */ 120 /* initialize our socket */
121 sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 121 sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
122 122
123 /* Check for socket error */
124 #ifdef WIN32
125 if (sock == INVALID_SOCKET) //MSDN recommends this
126 return -1;
127 #else
128 if (sock < 0)
129 return -1;
130 #endif
131
132
123 /* Functions to increase the size of the send and receive UDP buffers 133 /* Functions to increase the size of the send and receive UDP buffers
124 NOTE: uncomment if necessary */ 134 NOTE: uncomment if necessary */
125 /* 135 /*
@@ -146,7 +156,8 @@ int init_networking(IP ip ,uint16_t port)
146 156
147 /* Bind our socket to port PORT and address 0.0.0.0 */ 157 /* Bind our socket to port PORT and address 0.0.0.0 */
148 ADDR addr = {AF_INET, htons(port), ip}; 158 ADDR addr = {AF_INET, htons(port), ip};
149 bind(sock, (struct sockaddr*)&addr, sizeof(addr)); 159 bind(sock, (struct sockaddr*)&addr, sizeof(addr));
160
150 return 0; 161 return 0;
151 162
152} 163}
diff --git a/core/network.h b/core/network.h
index 6f140d0c..62169d88 100644
--- a/core/network.h
+++ b/core/network.h
@@ -121,10 +121,9 @@ int receivepacket(IP_Port * ip_port, uint8_t * data, uint32_t * length);
121 ip must be in network order EX: 127.0.0.1 = (7F000001) 121 ip must be in network order EX: 127.0.0.1 = (7F000001)
122 port is in host byte order (this means don't worry about it) 122 port is in host byte order (this means don't worry about it)
123 returns 0 if no problems 123 returns 0 if no problems
124 TODO: add something to check if there are errors */ 124 returns -1 if there were problems */
125int init_networking(IP ip ,uint16_t port); 125int init_networking(IP ip ,uint16_t port);
126 126
127
128/* function to cleanup networking stuff(doesn't do much right now) */ 127/* function to cleanup networking stuff(doesn't do much right now) */
129void shutdown_networking(); 128void shutdown_networking();
130 129