diff options
| author | Eli Zaretskii | 2017-05-17 18:12:58 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-05-17 18:12:58 +0300 |
| commit | f861353b684e5c40dade61f89fd1742e4226a282 (patch) | |
| tree | de238231504c77b9fc2c1c485c3d4e8752a238bd /src/process.c | |
| parent | f7c07930b581b1bcfdfb1874b6883233516bdf11 (diff) | |
| download | emacs-f861353b684e5c40dade61f89fd1742e4226a282.tar.gz emacs-f861353b684e5c40dade61f89fd1742e4226a282.zip | |
Remove redundant code in connect_network_socket
* src/process.c (connect_network_socket) [HAVE_GETSOCKNAME]:
Remove redundant type-casting and variables. Don't call
'getsockname' to find the port for AF_LOCAL sockets.
[AF_INET6]: Add an assertion to verify that the ports in the IPv4
and IPv6 structures are at the same offset and have the same size.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/src/process.c b/src/process.c index fdea97722f2..ecb1b0ca6df 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -3418,34 +3418,31 @@ connect_network_socket (Lisp_Object proc, Lisp_Object addrinfos, | |||
| 3418 | report_file_error ("Cannot bind server socket", Qnil); | 3418 | report_file_error ("Cannot bind server socket", Qnil); |
| 3419 | 3419 | ||
| 3420 | #ifdef HAVE_GETSOCKNAME | 3420 | #ifdef HAVE_GETSOCKNAME |
| 3421 | if (p->port == 0) | 3421 | if (p->port == 0 |
| 3422 | #ifdef HAVE_LOCAL_SOCKETS | ||
| 3423 | && family != AF_LOCAL | ||
| 3424 | #endif | ||
| 3425 | ) | ||
| 3422 | { | 3426 | { |
| 3423 | struct sockaddr_storage sa1; | 3427 | struct sockaddr_in sa1; |
| 3424 | socklen_t len1 = sizeof (sa1); | 3428 | socklen_t len1 = sizeof (sa1); |
| 3429 | #ifdef AF_INET6 | ||
| 3430 | /* The code below assumes the port is at the same offset | ||
| 3431 | and of the same width in both IPv4 and IPv6 | ||
| 3432 | structures, but the standards don't guarantee that, | ||
| 3433 | so we have this assertion to make sure. */ | ||
| 3434 | eassert ((offsetof (struct sockaddr_in, sin_port) | ||
| 3435 | == offsetof (struct sockaddr_in6, sin6_port)) | ||
| 3436 | && (sizeof (sa1.sin_port) | ||
| 3437 | == sizeof (((struct sockaddr_in6 *) &sa1)->sin6_port))); | ||
| 3438 | #endif | ||
| 3425 | if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0) | 3439 | if (getsockname (s, (struct sockaddr *)&sa1, &len1) == 0) |
| 3426 | { | 3440 | { |
| 3441 | Lisp_Object service = make_number (ntohs (sa1.sin_port)); | ||
| 3442 | contact = Fplist_put (contact, QCservice, service); | ||
| 3427 | /* Save the port number so that we can stash it in | 3443 | /* Save the port number so that we can stash it in |
| 3428 | the process object later. */ | 3444 | the process object later. */ |
| 3429 | int port = -1; | 3445 | ((struct sockaddr_in *) sa)->sin_port = sa1.sin_port; |
| 3430 | switch (family) | ||
| 3431 | { | ||
| 3432 | case AF_INET: | ||
| 3433 | ((struct sockaddr_in *) sa)->sin_port | ||
| 3434 | = port = ((struct sockaddr_in *) &sa1)->sin_port; | ||
| 3435 | break; | ||
| 3436 | # ifdef AF_INET6 | ||
| 3437 | case AF_INET6: | ||
| 3438 | ((struct sockaddr_in6 *) sa)->sin6_port | ||
| 3439 | = port = ((struct sockaddr_in6 *) &sa1)->sin6_port; | ||
| 3440 | break; | ||
| 3441 | # endif | ||
| 3442 | } | ||
| 3443 | |||
| 3444 | if (0 <= port) | ||
| 3445 | { | ||
| 3446 | Lisp_Object service = make_number (ntohs (port)); | ||
| 3447 | contact = Fplist_put (contact, QCservice, service); | ||
| 3448 | } | ||
| 3449 | } | 3446 | } |
| 3450 | } | 3447 | } |
| 3451 | #endif | 3448 | #endif |