rbb 99/04/19 07:16:41
Modified: include apr_network_io.h
docs networkio.txt
apr/network_io/unix sockets.c
Log:
Initial commit of connect function. This is needed to do any sort of test
program, and I have been meaning to write it. Not tested yet, but hopefully
soon.
Revision Changes Path
1.9 +1 -0 apache-apr/include/apr_network_io.h
Index: apr_network_io.h
===================================================================
RCS file: /home/cvs/apache-apr/include/apr_network_io.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- apr_network_io.h 1999/04/15 20:08:20 1.8
+++ apr_network_io.h 1999/04/19 14:16:39 1.9
@@ -90,6 +90,7 @@
apr_status_t apr_bind(apr_socket_t *);
apr_status_t apr_listen(apr_socket_t *, apr_int32_t);
apr_socket_t *apr_accept(const apr_socket_t *);
+apr_socket_t *apr_connect(char *, unsigned short);
char *apr_get_remote_hostname(apr_socket_t *);
apr_status_t apr_gethostname(char *, int);
1.11 +9 -0 apache-apr/docs/networkio.txt
Index: networkio.txt
===================================================================
RCS file: /home/cvs/apache-apr/docs/networkio.txt,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- networkio.txt 1999/04/15 20:08:21 1.10
+++ networkio.txt 1999/04/19 14:16:40 1.11
@@ -130,6 +130,15 @@
return) new socket that has the accepted connection.
NOTE: accepted socket can not accept more connections. Original socket
remains open, and can accept more connections.
+
+ apr_socket_t *apr_connect(char *, unisigned short)
+ Connect to a listening socket.
+
+ Arguments:
+ arg 1) hostname of the machine to connect to.
+ arg 2) port to connect to.
+ return) socket which is connected to server machine. NULL on
failure.
+NOTE: On failure, socket is closed, and memory is free'd on failure.
char *apr_get_remote_hostname(apr_socket_t *)
Get the host name for the remote machine
1.6 +33 -0 apache-apr/apr/network_io/unix/sockets.c
Index: sockets.c
===================================================================
RCS file: /home/cvs/apache-apr/apr/network_io/unix/sockets.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- sockets.c 1999/04/15 20:08:16 1.5
+++ sockets.c 1999/04/19 14:16:41 1.6
@@ -149,4 +149,37 @@
return NULL;
}
+apr_socket_t * apr_connect(char *hostname, unsigned short port)
+{
+ apr_socket_t *new = (apr_socket_t *)malloc(sizeof(apr_socket_t));
+ struct hostent *hp;
+ hp = gethostbyname(hostname);
+ new->socketdes = socket(AF_INET, SOCK_STREAM, 0);
+ new->addr = (struct sockaddr_in *)malloc (sizeof (struct sockaddr_in));
+
+ if ((new->socketdes < 0) || (!hp) || (!new->addr)) {
+ free(new->addr);
+ free(new);
+ return NULL;
+ }
+
+ memcpy((char *)&new->addr->sin_addr, hp->h_addr_list[0], hp->h_length);
+
+ new->addr->sin_port = htons((short)port);
+ new->addr->sin_family = AF_INET;
+
+ new->addr_len = sizeof(new->addr);
+
+ if (connect(new->socketdes, new->addr, new->addr_len) < 0) {
+ free(new->addr);
+ free(new);
+ return NULL;
+ }
+ else {
+ new->remote_hostname = strdup(hostname);
+ return new;
+ }
+}
+
+