🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.os.linux.programowanie
Article #261

Re: TCP/IP jako plik w C

#261
From: Bohdan R. Rau
Date: Fri, 10 Sep 1999 11:49
63 lines
2444 bytes
Dnia 9 września 1999 o godzinie 19:14:40 GMT Hadrianowi
 Lutogniewskiemu wpadło na myśl aby napisać tak:
>
>Bede wdzieczny za wszelkie podpowiedzi

UWAGA! Procedura NIE JEST sprawdzona, przerobiłem na czuja procedurę
tconnect.c z pakietu icon.9.3/ipl! Oryginalna procedura działała.

#include <string.h>
#include <stdio.h>

#include <fcntl.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>



FILE *tconnect(char *hostname, int port)	/*: connect to TCP socket */
   {
   unsigned char *p;
   int fd, i, d[4];
   FILE *fp;
   struct hostent *h;
   struct sockaddr_in sin;

   memset(&sin, 0, sizeof(sin));


   /* get host address */
   if (sscanf(hostname, "%d.%d.%d.%d", &d[0], &d[1], &d[2], &d[3]) == 4) {
      p = (unsigned char *) &sin.sin_addr;
      for (i = 0; i < 4; i++)
         p[i] = d[i];
      }
   else {
      h = gethostbyname(hostname);
      if (!h) return 0;
      memcpy(&sin.sin_addr, h->h_addr, sizeof(struct in_addr));
      endhostent();
      }

   /* create socket and connect */
   sin.sin_family = AF_INET;
   sin.sin_port = htons(port);
   if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) return 0;
   if (connect(fd, (struct sockaddr *) &sin, sizeof(sin)) < 0) return 0;
   
   /* create stdio file pointer */
   return fdopen(fd, "r+");
}



Pozdrawiam

ethanak
http://ethanak.i.sex.pl
-- 
Gdyby Word zrzucał core, to mógłbyś pomylić kontrolkę "HDD"
z kontrolkÄ… "Power"
                                          Radosław Gancarz
Technical Details
Message-ID: <slrn7thl0j.bl8.ethanak@guru.banialuka>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!uw.edu.pl!news.swierk.pl!paa.gov.pl!opoka-warszawa!orion.cst.tpsa.pl!news.tpnet.pl!not-for-mail
References: <7r90v0$ppa$1@Waldemar.mat.uni.torun.pl>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!pingwin.icm.edu.pl!mat.uni.torun.pl!uw.edu.pl!news.swierk.pl!paa.gov.pl!opoka-warszawa!orion.cst.tpsa.pl!news.tpnet.pl!not-for-mail
From: ethanak@bigfoot.com (Bohdan R. Rau)
Newsgroups: pl.comp.os.linux.programowanie
Subject: Re: TCP/IP jako plik w C
References: <7r90v0$ppa$1@Waldemar.mat.uni.torun.pl>
Organization: Penguin Farm
X-Ethanak-Motto: Wszystko przemija nawet najdluzsza zmija
Message-ID: <slrn7thl0j.bl8.ethanak@guru.banialuka>
Mime-Version: 1.0
X-Newsreader: slrn (0.9.4.3 UNIX)
Lines: 63
Date: Fri, 10 Sep 1999 11:49:47 GMT
NNTP-Posting-Host: 212.160.22.61
X-Complaints-To: abuse@tpsa.pl
X-Trace: news.tpnet.pl 936964187 212.160.22.61 (Fri, 10 Sep 1999 13:49:47 MET DST)
NNTP-Posting-Date: Fri, 10 Sep 1999 13:49:47 MET DST
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit