diff options
author | E. Westbrook <github@westbrook.io> | 2019-02-19 09:59:35 -0700 |
---|---|---|
committer | E. Westbrook <github@westbrook.io> | 2019-02-19 10:05:10 -0700 |
commit | 024646de54dca99c65b705a6c01260f1d1d8ff91 (patch) | |
tree | 322a4b01ac5af2bba34eb2a196f812cc98fdd7cd | |
parent | 531012df1ad65d9b075a1644a930a09ac584f106 (diff) | |
download | luasocket-024646de54dca99c65b705a6c01260f1d1d8ff91.tar.gz luasocket-024646de54dca99c65b705a6c01260f1d1d8ff91.tar.bz2 luasocket-024646de54dca99c65b705a6c01260f1d1d8ff91.zip |
Use SUN_LEN macro
-rw-r--r-- | src/unixdgram.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/unixdgram.c b/src/unixdgram.c index 07c394c..0d6f18c 100644 --- a/src/unixdgram.c +++ b/src/unixdgram.c | |||
@@ -17,6 +17,12 @@ | |||
17 | 17 | ||
18 | #define UNIXDGRAM_DATAGRAMSIZE 8192 | 18 | #define UNIXDGRAM_DATAGRAMSIZE 8192 |
19 | 19 | ||
20 | // provide a SUN_LEN macro if sys/un.h doesn't (e.g. Android) | ||
21 | #ifndef SUN_LEN | ||
22 | #define SUN_LEN(ptr) \ | ||
23 | ((size_t) (((struct sockaddr_un *) 0)->sun_path) \ | ||
24 | + strlen ((ptr)->sun_path)) | ||
25 | #endif | ||
20 | /*=========================================================================*\ | 26 | /*=========================================================================*\ |
21 | * Internal function prototypes | 27 | * Internal function prototypes |
22 | \*=========================================================================*/ | 28 | \*=========================================================================*/ |
@@ -265,7 +271,7 @@ static const char *unixdgram_trybind(p_unix un, const char *path) { | |||
265 | memset(&local, 0, sizeof(local)); | 271 | memset(&local, 0, sizeof(local)); |
266 | strcpy(local.sun_path, path); | 272 | strcpy(local.sun_path, path); |
267 | local.sun_family = AF_UNIX; | 273 | local.sun_family = AF_UNIX; |
268 | size_t addrlen = sizeof(local) - sizeof(local.sun_path) + len; | 274 | size_t addrlen = SUN_LEN(&local); |
269 | #ifdef UNIX_HAS_SUN_LEN | 275 | #ifdef UNIX_HAS_SUN_LEN |
270 | local.sun_len = addrlen + 1; | 276 | local.sun_len = addrlen + 1; |
271 | #endif | 277 | #endif |
@@ -316,7 +322,7 @@ static const char *unixdgram_tryconnect(p_unix un, const char *path) | |||
316 | strcpy(remote.sun_path, path); | 322 | strcpy(remote.sun_path, path); |
317 | remote.sun_family = AF_UNIX; | 323 | remote.sun_family = AF_UNIX; |
318 | timeout_markstart(&un->tm); | 324 | timeout_markstart(&un->tm); |
319 | size_t addrlen = sizeof(remote) - sizeof(remote.sun_path) + len; | 325 | size_t addrlen = SUN_LEN(&remote); |
320 | #ifdef UNIX_HAS_SUN_LEN | 326 | #ifdef UNIX_HAS_SUN_LEN |
321 | remote.sun_len = addrlen + 1; | 327 | remote.sun_len = addrlen + 1; |
322 | #endif | 328 | #endif |