Czy mógłby ktoś sprawdzić te source pod Linuxem, nie wiem czy mam kłopoty ze źródłem czy też z Linuxem.
Klient:
[code]
#include < stdio.h >
#include < string.h >
#include < sys/types.h >
#include < sys/socket.h >
#include < netinet/in.h >
#include < netdb.h >

#define PORT_DOMYSLNY 13

int main(int argc, char **argv)
{
struct hostent *host;
struct sockaddr_in adres;
char *komputer=NULL,domyslny[]="localhost",buf[1024];
int gnz,i,port=0;

switch (argc)
{
case 3 : port=atoi(argv[2]);
case 2 : komputer=argv[1];
}

if (!komputer) komputer=domyslny;
if (!port) port=PORT_DOMYSLNY;

bzero((char *)&adres,sizeof(adres));
adres.sin_family=AF_INET;
adres.sin_port=htons(port);

host=gethostbyname(komputer);
if (host)
bcopy(host->h_addr,(char *)&adres.sin_addr,host->h_length);
else
{
perror("Blad: Nie moge znalezc hosta");
return 1;
}

gnz=socket(PF_INET,SOCK_DGRAM,0);
if (gnz==-1)
{
perror("Blad: Nie moge utworzyc deskryptora gniazdka!");
return 1;
}

if (connect(gnz,(struct sockaddr *)&adres,sizeof(adres)))
{
perror("Blad funkcji connect!");
return 1;
}

while (*gets(buf))
{
write(gnz,buf,strlen(buf));
i=read(gnz,buf,sizeof(buf));
if (i < 1)
{
perror("Blad odbioru!");
return 1;
}
buf[i]='\0';
puts(buf);
}

close(gnz);
}
[/code]
Serwer:
[code]
#include < stdio.h >
#include < sys/types.h >
#include < sys/socket.h >
#include < netinet/in.h >

#define PORT_DOMYSLNY 7777

int main(int argc, char **argv)
{
struct sockaddr_in adres;
int gnz,i,t,port=0;
char buf[2048];

if (argc > 1) port=atoi(argv[1]);
if (!port) port=PORT_DOMYSLNY;

gnz=socket(PF_INET,SOCK_DGRAM,0);
if (gnz==-1)
{
perror("Blad: Nie moge uzyskac deskryptora gniazdka!");
return 1;
}

bzero((char *)&adres,sizeof(adres));
adres.sin_family=AF_INET;
adres.sin_addr.s_addr=INADDR_ANY;
adres.sin_port=htons(port);

if (bind(gnz,(struct sockaddr *)&adres,sizeof(adres)))
{
perror("Blad: Nie moge zwiazac gniazdka z adresem lokalnym!");
return 1;
}

while (1)
{
t=sizeof(adres);
i=recvfrom(gnz,buf,sizeof(buf),0,(struct sockaddr*)&adres,&t);
buf[i]='\0';
printf("od %s:%d : %s\n\n",inet_ntoa(adres.sin_addr),
ntohs(adres.sin_port),buf);
sendto(gnz,buf,i,0,(struct sockaddr *)&adres,sizeof(adres));
}
}
[/code]