From d0970ce743caabb185362728cefcc0ef4b49712d Mon Sep 17 00:00:00 2001 From: bertrand Date: Sun, 20 May 2001 12:58:41 +0000 Subject: [PATCH] Included "netdb.h" file needed. Changed exit to return -1. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@842 b3059339-0415-0410-9bf9-f77b7e298cf2 --- network.c | 20 ++++++++++++-------- network.h | 7 +++++++ 2 files changed, 19 insertions(+), 8 deletions(-) create mode 100644 network.h diff --git a/network.c b/network.c index f7c3067451..62603ec801 100644 --- a/network.c +++ b/network.c @@ -1,27 +1,31 @@ #include +#include +#include #include #include #include +#include "network.h" + int connect2Server(char *host, int port) { int socket_server_fd; struct sockaddr_in server_address; - printf(">>>> connect2Server [%s@%d]\n", host, port ); + printf(">>>> connect2Server [%s:%d]\n", host, port ); socket_server_fd = socket(AF_INET, SOCK_STREAM, 0); if( socket_server_fd==-1 ) { perror("Failed to create socket"); - exit(1); + return -1; } if( isalpha(host[0]) ) { - struct hostent *hp; - if( (hp=gethostbyname( host ))==NULL ) { + struct hostent *hp =(struct hostent*)gethostbyname( host ); + if( hp==NULL ) { printf("Unknown host: %s\n", host); - exit(1); + return -1; } - memcpy( &server_address.sin_addr.s_addr, hp->h_addr, hp->h_length ); + memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length ); } else { inet_pton(AF_INET, host, &server_address.sin_addr); } @@ -30,8 +34,8 @@ connect2Server(char *host, int port) { if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) { perror("Failed to connect to server"); - close(socket_Stream_fd); - exit(1); + close(socket_server_fd); + return -1; } return socket_server_fd; } diff --git a/network.h b/network.h new file mode 100644 index 0000000000..63fadbd00e --- /dev/null +++ b/network.h @@ -0,0 +1,7 @@ +#ifndef NETWORK_H +#define NETWORK_H + + +int connect2Server(char *host, int port); + +#endif