annotate network.c @ 865:83919c1b9924

removed redundant osd.h includes
author arpi_esp
date Thu, 24 May 2001 20:48:45 +0000
parents c906b7600fc6
children 7f6641b1b0df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
1 #include <unistd.h>
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
2 #include <netinet/in.h>
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
3 #include <netdb.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
4 #include <sys/types.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
5 #include <sys/socket.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
6
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
7 #include <stdio.h>
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
8
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
9 #include "network.h"
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
10
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
11 int
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
12 connect2Server(char *host, int port) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
13 int socket_server_fd;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
14 struct sockaddr_in server_address;
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
15 printf(">>>> connect2Server [%s:%d]\n", host, port );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
16 socket_server_fd = socket(AF_INET, SOCK_STREAM, 0);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
17 if( socket_server_fd==-1 ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
18 perror("Failed to create socket");
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
19 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
20 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
21
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
22 if( isalpha(host[0]) ) {
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
23 struct hostent *hp =(struct hostent*)gethostbyname( host );
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
24 if( hp==NULL ) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
25 printf("Unknown host: %s\n", host);
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
26 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
27 }
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
28 memcpy( (void*)&server_address.sin_addr.s_addr, (void*)hp->h_addr, hp->h_length );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
29 } else {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
30 inet_pton(AF_INET, host, &server_address.sin_addr);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
31 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
32 server_address.sin_family=AF_INET;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
33 server_address.sin_port=htons(port);
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
34
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
35 if( connect( socket_server_fd, (struct sockaddr*)&server_address, sizeof(server_address) )==-1 ) {
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
36 perror("Failed to connect to server");
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
37 close(socket_server_fd);
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
38 return -1;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
39 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
40 return socket_server_fd;
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
41 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
42