diff options
Diffstat (limited to 'core/network.c')
-rw-r--r-- | core/network.c | 19 |
1 files changed, 15 insertions, 4 deletions
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 */ |
106 | int init_networking(IP ip ,uint16_t port) | 106 | int 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 | } |