🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: TCP/IP jako plik w C

#260
From: Krzysztof Krzyżaniak
Date: Thu, 09 Sep 1999 20:45
43 lines
2367 bytes
Pewnego dnia, a było to 9 Sep 1999 19:14:40 GMT przyszła do mnie
wiadomość od <hadrian@Leon.mat.uni.torun.pl> i powiedziała:

>A Hoj,
>
>Co trzeba zrobic, aby uruchomic klienta TCP/IP w C tak, aby komunikacja
>odbywala sie tak, jak pisanie/czytanie z pliku tzn.:

Generalnie poszukaj sobie w info libc na temat programowania socketów:
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
		     
int make_socket(uint16_t port){	 
       sock = socket (PF_INET, SOCK_STREAM, 0);
       if (sock < 0){
           perror ("socket");
           exit (EXIT_FAILURE);
       }
		      
      /* Give the socket a name. */
       name.sin_family = AF_INET;
       name.sin_port = htons (port);
       name.sin_addr.s_addr = htonl (INADDR_ANY);
       if (bind (sock, (struct sockaddr *) &name,sizeof (name)) < 0){
            perror ("bind");
            exit (EXIT_FAILURE);
       }
			
       return sock;
}

Funkcja zwraca deskryptor gniazdka, które możesz wykorzystać w funkcjach
open, write itp. Polecam `Programowanie zastosowań sieciowych w systemie
Unix' R.W. Stevens.

	eloy
-- 
 * Krzysztof `eloy' Krzyżaniak * HP -> http://www.pawnhearts.eu.org/~eloy/
 * <eloy@pawnhearts.eu.org>    * KabaretLoza44 -> http://loza44.topnet.pl/
 * PH Member                   * Rock -> http://wwwv.venco.com.pl/~eloy/muzyka/
                 Życie jest średnie, ani dobre, ani złe... (MZ)
Technical Details
Message-ID: <slrn7tg7ad.53l.eloy@inkubus.hstl6.put.poznan.pl>
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.icm.edu.pl!news.man.poznan.pl!eloy
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.icm.edu.pl!news.man.poznan.pl!eloy
From: Krzysztof Krzyżaniak <eloy@inkubus.hstl6.put.poznan.pl>
Newsgroups: pl.comp.os.linux.programowanie
Subject: Re: TCP/IP jako plik w C
Date: 9 Sep 1999 20:45:05 GMT
Organization: Poznan Supercomputing & Networking Center
Lines: 43
Message-ID: <slrn7tg7ad.53l.eloy@inkubus.hstl6.put.poznan.pl>
References: <7r90v0$ppa$1@Waldemar.mat.uni.torun.pl>
NNTP-Posting-Host: inkubus.hstl6.put.poznan.pl
Mime-Version: 1.0
X-Trace: sunflower.man.poznan.pl 936909905 10256 150.254.53.43 (9 Sep 1999 20:45:05 GMT)
X-Complaints-To: tomjab@man.poznan.pl
NNTP-Posting-Date: 9 Sep 1999 20:45:05 GMT
User-Agent: slrn/0.9.5.7 (UNIX)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit