@rzookol, post #1
/* ** modul_nadawczy.c -- datagram ** Piotr Niemojewski - -///- (R) ** wykonano na laboratorium QNX ** temat Komunikator Sieciowy ** v1.16 */ #include#include #include #include #include #include #include #include #include int main(int argc, char *argv[]) { int sockfd; int PORT; /* ustalamy na ktorym porcie jest polaczenie */ printf("Wpisz tresc wiadomosci. Koniec programu = Ctrl+Cnn"); for(;;) { char tresc[255]; struct sockaddr_in their_addr; /* adres lacznika */ struct hostent *he; int numbytes; if (argc != 3) { fprintf(stderr,"uzycie: %s nazwa_komputeranumer_portun",argv[0]); exit(1); } PORT = atoi(argv[2]); if ((he=gethostbyname(argv[1])) == NULL) { /* dns */ perror("Nie moge odnalezc komputera"); exit(1); } if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { perror("socket"); exit(1); } their_addr.sin_family = AF_INET; /* host byte order */ their_addr.sin_port = htons(PORT); /* short, network byte order */ their_addr.sin_addr = *((struct in_addr *)he->h_addr); bzero(&(their_addr.sin_zero), 8); /* zero the rest of the struct */ printf(">"); scanf("%s",&tresc); printf("n"); if ((numbytes=sendto(sockfd,tresc,strlen(tresc),0,(struct sockaddr *)&their_addr, sizeof(struct sockaddr))) == -1) { perror("recvfrom"); exit(1); } printf("Wyslano na %s /Koniec = Ctrl+C/nn",inet_ntoa(their_addr.sin_addr)); close(sockfd); } return 0; }