File tree 1 file changed +7
-4
lines changed
1 file changed +7
-4
lines changed Original file line number Diff line number Diff line change 9
9
SCCS ID: @(#)socket.c 1.5 4/1/94
10
10
programmer: Virginia Tech Computing Center
11
11
compiler: DEC RISC C compiler (Ultrix 4.1)
12
- environment: DEC Ultrix 4.3
12
+ environment: DEC Ultrix 4.3
13
13
description: UNIX sockets code.
14
14
***********************************************************************/
15
-
15
+
16
16
#include <sys/types.h>
17
17
#include <sys/socket.h>
18
18
#include <fcntl.h>
@@ -32,7 +32,7 @@ int Socket(const char *host, int clientPort)
32
32
unsigned long inaddr ;
33
33
struct sockaddr_in ad ;
34
34
struct hostent * hp ;
35
-
35
+
36
36
memset (& ad , 0 , sizeof (ad ));
37
37
ad .sin_family = AF_INET ;
38
38
@@ -47,12 +47,15 @@ int Socket(const char *host, int clientPort)
47
47
memcpy (& ad .sin_addr , hp -> h_addr , hp -> h_length );
48
48
}
49
49
ad .sin_port = htons (clientPort );
50
-
50
+
51
51
sock = socket (AF_INET , SOCK_STREAM , 0 );
52
52
if (sock < 0 )
53
53
return sock ;
54
54
if (connect (sock , (struct sockaddr * )& ad , sizeof (ad )) < 0 )
55
+ {
56
+ close (sock );
55
57
return -1 ;
58
+ }
56
59
return sock ;
57
60
}
58
61
You can’t perform that action at this time.
0 commit comments