dgecholoop1.c 396 B

12345678910111213141516171819202122232425262728
  1. #include "unp.h"
  2. static void recvfrom_int(int);
  3. static int count;
  4. void
  5. dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen)
  6. {
  7. socklen_t len;
  8. char mesg[MAXLINE];
  9. Signal(SIGINT, recvfrom_int);
  10. for ( ; ; ) {
  11. len = clilen;
  12. Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len);
  13. count++;
  14. }
  15. }
  16. static void
  17. recvfrom_int(int signo)
  18. {
  19. printf("\nreceived %d datagrams\n", count);
  20. exit(0);
  21. }