recv.c 356 B

123456789101112131415161718192021
  1. #include "unp.h"
  2. void
  3. recv_all(int recvfd, socklen_t salen)
  4. {
  5. int n;
  6. char line[MAXLINE+1];
  7. socklen_t len;
  8. struct sockaddr *safrom;
  9. safrom = Malloc(salen);
  10. for ( ; ; ) {
  11. len = salen;
  12. n = Recvfrom(recvfd, line, MAXLINE, 0, safrom, &len);
  13. line[n] = 0; /* null terminate */
  14. printf("from %s: %s", Sock_ntop(safrom, len), line);
  15. }
  16. }