mirror of https://github.com/mpv-player/mpv
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
This commit is contained in:
parent
fffaf83e4b
commit
d0970ce743
20
network.c
20
network.c
|
@ -1,27 +1,31 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <netdb.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "network.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
connect2Server(char *host, int port) {
|
connect2Server(char *host, int port) {
|
||||||
int socket_server_fd;
|
int socket_server_fd;
|
||||||
struct sockaddr_in server_address;
|
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);
|
socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if( socket_server_fd==-1 ) {
|
if( socket_server_fd==-1 ) {
|
||||||
perror("Failed to create socket");
|
perror("Failed to create socket");
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( isalpha(host[0]) ) {
|
if( isalpha(host[0]) ) {
|
||||||
struct hostent *hp;
|
struct hostent *hp =(struct hostent*)gethostbyname( host );
|
||||||
if( (hp=gethostbyname( host ))==NULL ) {
|
if( hp==NULL ) {
|
||||||
printf("Unknown host: %s\n", host);
|
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 {
|
} else {
|
||||||
inet_pton(AF_INET, host, &server_address.sin_addr);
|
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 ) {
|
if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
|
||||||
perror("Failed to connect to server");
|
perror("Failed to connect to server");
|
||||||
close(socket_Stream_fd);
|
close(socket_server_fd);
|
||||||
exit(1);
|
return -1;
|
||||||
}
|
}
|
||||||
return socket_server_fd;
|
return socket_server_fd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue