/* * This file part of gsopcast - A gtk front-end of p2p tv sopcast. * http://lianwei3.googlepages.com/home2 * Copyright (C) 2006 Wei Lian * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "header.h" extern char outport[8]; //----------------------------------------------------- //////////////network related stuff int connect_to_server(const char *host, int portnum) { int sock; struct sockaddr_in serv_addr; struct hostent *server; sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == -1) { perror("ERROR opening socket"); return -3; } server = gethostbyname(host); if (server == NULL) { perror("ERROR, no such host"); close(sock); return -2; } memset((char *) &serv_addr, 0, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; memcpy((char *) &serv_addr.sin_addr.s_addr, (char *) server->h_addr, server->h_length); serv_addr.sin_port = htons(portnum); if (connect (sock, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) == -1) { close(sock); return -1; } return sock; } ///network client using tcp /*int client_read (char *buff, int sizbuff) { int n; int sock; memset (buff, 0, sizbuff); sock = connect_to_server ("127.0.0.1", atoi (outport)); if (sock < 0) return -2; ////socket fd now created ////for sp-sc 0.8, client need to send message first to receive data write (sock, "1", strlen ("1") + 1); n = recv (sock, buff, sizbuff - 1, 0); if (n == -1) { perror ("ERROR reading from socket"); } close (sock); return n; ///>0 data;=0 shutdown;<0 err }*/