#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>


/* Port fuer die Requests */
#define PORT 7777

/* Puffergroesse */
#define BUFSIZE 4096

int main(void)
  {
  int sockfd;                                   /* unsere Socket   */
  struct sockaddr_in my_addr, remote_addr;      /* 2 Adressen      */
  int remote_addr_size = sizeof(remote_addr);   /* fuer recvfrom() */
  char buf[BUFSIZE];                            /* Datenpuffer     */

  if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    {
    fprintf(stderr, "Error: socket()\n");
    exit(1);
    }

  memset( &my_addr, 0, sizeof (my_addr));
  my_addr.sin_family      = AF_INET;
  my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  my_addr.sin_port        = htons(PORT);

  if (bind(sockfd, (struct sockaddr*)&my_addr, sizeof(my_addr)) < 0)
    {
    fprintf(stderr, "Error: bind()\n");
    close(sockfd);
    exit(1);
    }

  if (recvfrom(sockfd, buf, sizeof(buf), 0,
	       (struct sockaddr*)&remote_addr, (socklen_t*)&remote_addr_size) > 0)
    {
    printf("Getting Data from %s\n", inet_ntoa(remote_addr.sin_addr));
    printf("Data : %s\n", buf);
    }
  close(sockfd);
  return(0);
  }

