aboutsummaryrefslogtreecommitdiff
path: root/src/udp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udp.c')
-rw-r--r--src/udp.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/src/udp.c b/src/udp.c
index 8e14fac..6e0de9f 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -159,7 +159,7 @@ static int meth_sendto(lua_State *L) {
159 struct sockaddr_in addr; 159 struct sockaddr_in addr;
160 memset(&addr, 0, sizeof(addr)); 160 memset(&addr, 0, sizeof(addr));
161 if (!inet_pton(AF_INET, ip, &addr.sin_addr)) 161 if (!inet_pton(AF_INET, ip, &addr.sin_addr))
162 luaL_argerror(L, 3, "invalid ip address"); 162 luaL_argerror(L, 3, "invalid ip address");
163 addr.sin_family = AF_INET; 163 addr.sin_family = AF_INET;
164 addr.sin_port = htons(port); 164 addr.sin_port = htons(port);
165 timeout_markstart(tm); 165 timeout_markstart(tm);
@@ -171,7 +171,7 @@ static int meth_sendto(lua_State *L) {
171 struct sockaddr_in6 addr; 171 struct sockaddr_in6 addr;
172 memset(&addr, 0, sizeof(addr)); 172 memset(&addr, 0, sizeof(addr));
173 if (!inet_pton(AF_INET6, ip, &addr.sin6_addr)) 173 if (!inet_pton(AF_INET6, ip, &addr.sin6_addr))
174 luaL_argerror(L, 3, "invalid ip address"); 174 luaL_argerror(L, 3, "invalid ip address");
175 addr.sin6_family = AF_INET6; 175 addr.sin6_family = AF_INET6;
176 addr.sin6_port = htons(port); 176 addr.sin6_port = htons(port);
177 timeout_markstart(tm); 177 timeout_markstart(tm);
@@ -180,9 +180,9 @@ static int meth_sendto(lua_State *L) {
180 break; 180 break;
181 } 181 }
182 default: 182 default:
183 lua_pushnil(L); 183 lua_pushnil(L);
184 lua_pushfstring(L, "unknown family %d", udp->family); 184 lua_pushfstring(L, "unknown family %d", udp->family);
185 return 2; 185 return 2;
186 } 186 }
187 if (err != IO_DONE) { 187 if (err != IO_DONE) {
188 lua_pushnil(L); 188 lua_pushnil(L);
@@ -259,19 +259,19 @@ static int meth_receivefrom(lua_State *L) {
259 (SA *) &addr, &addr_len, tm); 259 (SA *) &addr, &addr_len, tm);
260 /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */ 260 /* Unlike TCP, recv() of zero is not closed, but a zero-length packet. */
261 if (err == IO_CLOSED) 261 if (err == IO_CLOSED)
262 err = IO_DONE; 262 err = IO_DONE;
263 if (err == IO_DONE) { 263 if (err == IO_DONE) {
264 char addrstr[INET6_ADDRSTRLEN]; 264 char addrstr[INET6_ADDRSTRLEN];
265 lua_pushlstring(L, buffer, got); 265 lua_pushlstring(L, buffer, got);
266 if (!inet_ntop(AF_INET6, &addr.sin6_addr, 266 if (!inet_ntop(AF_INET6, &addr.sin6_addr,
267 addrstr, sizeof(addrstr))) { 267 addrstr, sizeof(addrstr))) {
268 lua_pushnil(L); 268 lua_pushnil(L);
269 lua_pushstring(L, "invalid source address"); 269 lua_pushstring(L, "invalid source address");
270 return 2; 270 return 2;
271 } 271 }
272 lua_pushstring(L, addrstr); 272 lua_pushstring(L, addrstr);
273 lua_pushnumber(L, ntohs(addr.sin6_port)); 273 lua_pushnumber(L, ntohs(addr.sin6_port));
274 return 3; 274 return 3;
275 } 275 }
276 break; 276 break;
277 } 277 }