From 5b74d7e9c7c1f6bdcbae4e658c76c41016cdbf6b Mon Sep 17 00:00:00 2001 From: des Date: Sat, 11 Jul 1998 18:56:01 +0000 Subject: Too many changes to list. Basically, FTP is nearly there and error reporting is kinda sorted out. Now HTTP needs to catch up... --- lib/libfetch/fetch.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'lib/libfetch/fetch.c') diff --git a/lib/libfetch/fetch.c b/lib/libfetch/fetch.c index 99a2b9f..9e60938 100644 --- a/lib/libfetch/fetch.c +++ b/lib/libfetch/fetch.c @@ -25,15 +25,20 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id$ + * $Id: fetch.c,v 1.1.1.1 1998/07/09 16:52:42 des Exp $ */ #include +#include +#include +#include #include +#include #include #include #include +#include #include "fetch.h" @@ -43,6 +48,8 @@ #define DEBUG(x) do { } while (0) #endif +int fetchLastErrCode; +const char *fetchLastErrText; /* get URL */ FILE * @@ -187,3 +194,31 @@ fetchFreeURL(url_t *u) free(u); } } + +int +fetchConnect(char *host, int port) +{ + struct sockaddr_in sin; + struct hostent *he; + int sd; + + /* look up host name */ + if ((he = gethostbyname(host)) == NULL) + return -1; + + /* set up socket address structure */ + bzero(&sin, sizeof(sin)); + bcopy(he->h_addr, (char *)&sin.sin_addr, he->h_length); + sin.sin_family = he->h_addrtype; + sin.sin_port = htons(port); + + /* try to connect */ + if ((sd = socket(sin.sin_family, SOCK_STREAM, 0)) < 0) + return -1; + if (connect(sd, (struct sockaddr *)&sin, sizeof sin) < 0) { + close(sd); + return -1; + } + + return sd; +} -- cgit v1.1