Mercurial > hg > mlmmj
view src/init_sockfd.c @ 0:21ce01de8109
Initial revision
author | mmj |
---|---|
date | Thu, 22 Apr 2004 04:02:09 +1000 |
parents | |
children | 65d01831c0eb |
line wrap: on
line source
/* Copyright (C) 2002, 2003 Mads Martin Joergensen <mmj at mmj.dk> * * $Id$ * * This file is redistributable under version 2 of the GNU General * Public License as described at http://www.gnu.org/licenses/gpl.txt */ #include <stdlib.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include "init_sockfd.h" #include "log_error.c" void init_sockfd(int *sockfd, const char *relayhost) { int len; struct sockaddr_in addr; *sockfd = socket(PF_INET, SOCK_STREAM, 0); if(*sockfd == -1) { log_error( "Could not get socket"); exit(EXIT_FAILURE); } addr.sin_family = PF_INET; addr.sin_addr.s_addr = inet_addr(relayhost); addr.sin_port = htons(25); len = sizeof(addr); if(connect(*sockfd, (struct sockaddr *)&addr, len) == -1) { log_error("Could not connect"); exit(EXIT_FAILURE); } }