Mercurial > mplayer.hg
comparison network.c @ 833:b8cecdc0c67f
Starting implementation of ASF network streaming.
author | bertrand |
---|---|
date | Fri, 18 May 2001 16:14:06 +0000 |
parents | |
children | c906b7600fc6 |
comparison
equal
deleted
inserted
replaced
832:369697a87773 | 833:b8cecdc0c67f |
---|---|
1 #include <unistd.h> | |
2 #include <sys/types.h> | |
3 #include <sys/socket.h> | |
4 | |
5 #include <stdio.h> | |
6 | |
7 int | |
8 connect2Server(char *host, int port) { | |
9 int socket_server_fd; | |
10 struct sockaddr_in server_address; | |
11 printf(">>>> connect2Server [%s@%d]\n", host, port ); | |
12 socket_server_fd = socket(AF_INET, SOCK_STREAM, 0); | |
13 if( socket_server_fd==-1 ) { | |
14 perror("Failed to create socket"); | |
15 exit(1); | |
16 } | |
17 | |
18 if( isalpha(host[0]) ) { | |
19 struct hostent *hp; | |
20 if( (hp=gethostbyname( host ))==NULL ) { | |
21 printf("Unknown host: %s\n", host); | |
22 exit(1); | |
23 } | |
24 memcpy( &server_address.sin_addr.s_addr, hp->h_addr, hp->h_length ); | |
25 } else { | |
26 inet_pton(AF_INET, host, &server_address.sin_addr); | |
27 } | |
28 server_address.sin_family=AF_INET; | |
29 server_address.sin_port=htons(port); | |
30 | |
31 if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) { | |
32 perror("Failed to connect to server"); | |
33 close(socket_Stream_fd); | |
34 exit(1); | |
35 } | |
36 return socket_server_fd; | |
37 } | |
38 |