diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2000-12-02 21:29:00 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2000-12-02 21:29:00 +0000 |
commit | 6b6a8cefad468dc1dfc92da06ccb45363e346736 (patch) | |
tree | 2c8d99c514bada3f403a7fd17e2c1da13cdb2c3d /winsup/cygwin/net.cc | |
parent | 294f81d78d6435c69ad94e04a8f2d9881d0b8211 (diff) | |
download | newlib-6b6a8cefad468dc1dfc92da06ccb45363e346736.zip newlib-6b6a8cefad468dc1dfc92da06ccb45363e346736.tar.gz newlib-6b6a8cefad468dc1dfc92da06ccb45363e346736.tar.bz2 |
* net.cc (get_inet_addr ): Close AF_UNIX socket file after reading.
Diffstat (limited to 'winsup/cygwin/net.cc')
-rw-r--r-- | winsup/cygwin/net.cc | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc index 1832eb1..08d076a 100644 --- a/winsup/cygwin/net.cc +++ b/winsup/cygwin/net.cc @@ -387,22 +387,26 @@ static int get_inet_addr (const struct sockaddr *in, int inlen, } else if (in->sa_family == AF_UNIX) { - sockaddr_in sin; - char buf[32]; - - memset (buf, 0, sizeof buf); - int fd = open (in->sa_data, O_RDONLY); + int fd = _open (in->sa_data, O_RDONLY); if (fd == -1) return 0; - if (read (fd, buf, sizeof buf) == -1) - return 0; - sin.sin_family = AF_INET; - sscanf (buf + strlen (SOCKET_COOKIE), "%hu", &sin.sin_port); - sin.sin_port = htons (sin.sin_port); - sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK); - *out = sin; - *outlen = sizeof sin; - return 1; + + int ret = 0; + char buf[32]; + memset (buf, 0, sizeof buf); + if (read (fd, buf, sizeof buf) != -1) + { + sockaddr_in sin; + sin.sin_family = AF_INET; + sscanf (buf + strlen (SOCKET_COOKIE), "%hu", &sin.sin_port); + sin.sin_port = htons (sin.sin_port); + sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK); + *out = sin; + *outlen = sizeof sin; + ret = 1; + } + _close (fd); + return ret; } else { |