Professional Documents
Culture Documents
#include
#include
#include
#include
#include
#include
#include
#include
#include
<errno.h>
<stdarg.h>
<stdio.h>
<stdlib.h>
<string.h>
<unistd.h>
<sys/types.h>
<sys/socket.h>
<netinet/in.h>
<arpa/inet.h>
/* Ime programa. */
void
do_work (int server, struct sockaddr *address, socklen_t length)
{
char buffer[BUFFER_SIZE];
/* Bafer za razmenu poruka
* sa serverom. */
int count;
/* Duzina poruke. */
if (sendto (server, NULL, 0, 0, address, length) != 0)
error_fatal ("%s sendto() error\n", program);
/* ...a zatim ocitava odgovor od servera... */
if ((count = recvfrom (server, buffer, BUFFER_SIZE - 1, 0, NULL, NULL)) < 0)
error_fatal ("%s recvfrom() error\n", program);
buffer[count] = 0;
/* ...i ispisuje na standardni izlaz. */
if (fputs (buffer, stdout) == EOF)
error_fatal ("%s fputs() error: %s\n", program, strerror (errno));
}
static void
error_fatal (char *format, ...)
{
va_list arguments;
/* Lista argumenata funkcije. */
/* Stampa se string predstavljen argumentima funkcije. */
va_start (arguments, format);
vfprintf (stderr, format, arguments);
va_end (arguments);
/* Prekida se program. */
exit (EXIT_FAILURE);
}