1 /* -*- c-basic-offset: 8; -*-
3 * Copyright (c) 1993 W. Richard Stevens. All rights reserved.
4 * Permission to use or modify this software and its documentation only for
5 * educational purposes and without fee is hereby granted, provided that
6 * the above copyright notice appear in all copies. The author makes no
7 * representations about the suitability of this software for any purpose.
8 * It is provided "as is" without express or implied warranty.
15 sink_udp(int sockfd
) /* TODO: use recvfrom ?? */
20 sleep_us(pauseinit
*1000);
22 for ( ; ; ) { /* read until peer closes connection; -n opt ignored */
23 /* msgpeek = 0 or MSG_PEEK */
26 if ( (n
= recv(sockfd
, rbuf
, readlen
, flags
)) < 0) {
27 err_sys("recv error");
31 fprintf(stderr
, "connection closed by peer\n");
34 #ifdef notdef /* following not possible with TCP */
35 } else if (n
!= readlen
)
36 err_quit("read returned %d, expected %d", n
, readlen
);
42 fprintf(stderr
, "received %d bytes%s\n", n
,
43 (flags
== MSG_PEEK
) ? " (MSG_PEEK)" : "");
45 fprintf(stderr
, "printing %d bytes\n", n
);
46 rbuf
[n
] = 0; /* make certain it's null terminated */
47 fprintf(stderr
, "SDAP header: %lx\n", *((long *) rbuf
));
48 fprintf(stderr
, "next long: %lx\n", *((long *) rbuf
+4));
49 fputs(&rbuf
[8], stderr
);
54 sleep_us(pauserw
*1000);
57 flags
= 0; /* avoid infinite loop */
58 goto oncemore
; /* read the message again */
64 fprintf(stderr
, "pausing before close\n");
65 sleep_us(pauseclose
*1000);
68 if (close(sockfd
) < 0)
69 err_sys("close error");