summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAstonex <softukitu@gmail.com>2013-07-24 00:32:50 +0100
committerAstonex <softukitu@gmail.com>2013-07-24 00:32:50 +0100
commit29aa702a4f0cc50c091e0e9624d5ee897138ddf3 (patch)
treed94b6894a004509b3cbc756a3b0a4fb1eb0e4791
parentb7a4c20279ba32e89119c78c2e78ee279358d338 (diff)
Added simple init_networking() error checking
-rw-r--r--core/Messenger.c8
-rw-r--r--core/Messenger.h6
-rw-r--r--core/network.c8
-rw-r--r--core/network.h3
4 files changed, 16 insertions, 9 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..fa6c99fc 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
@@ -146,7 +146,9 @@ int init_networking(IP ip ,uint16_t port)
146 146
147 /* Bind our socket to port PORT and address 0.0.0.0 */ 147 /* Bind our socket to port PORT and address 0.0.0.0 */
148 ADDR addr = {AF_INET, htons(port), ip}; 148 ADDR addr = {AF_INET, htons(port), ip};
149 bind(sock, (struct sockaddr*)&addr, sizeof(addr)); 149 if(bind(sock, (struct sockaddr*)&addr, sizeof(addr)) == -1)
150 return -1;
151
150 return 0; 152 return 0;
151 153
152} 154}
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