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.
10 #include <sys/types.h>
11 #include <sys/socket.h>
18 source_udp(int sockfd
) /* TODO: use sendto ?? */
23 pattern(wbuf
, writelen
); /* fill send buffer with a pattern */
26 sleep_us(pauseinit
*1000);
28 for (i
= 1; i
<= nbuf
; i
++) {
30 if ( (n
= write(sockfd
, wbuf
, writelen
)) != writelen
) {
32 err_ret("write returned %d, expected %d", n
, writelen
);
33 /* also call getsockopt() to clear so_error */
34 optlen
= sizeof(option
);
35 if (getsockopt(sockfd
, SOL_SOCKET
, SO_ERROR
,
36 &option
, &optlen
) < 0)
37 err_sys("SO_ERROR getsockopt error");
39 err_sys("write returned %d, expected %d", n
, writelen
);
42 if ( (n
= sendto(sockfd
, wbuf
, writelen
, 0,
43 (struct sockaddr
*) &servaddr
,
44 sizeof(struct sockaddr
))) != writelen
) {
46 err_ret("sendto returned %d, expected %d", n
, writelen
);
47 /* also call getsockopt() to clear so_error */
48 optlen
= sizeof(option
);
49 if (getsockopt(sockfd
, SOL_SOCKET
, SO_ERROR
,
50 &option
, &optlen
) < 0)
51 err_sys("SO_ERROR getsockopt error");
53 err_sys("sendto returned %d, expected %d", n
, writelen
);
58 fprintf(stderr
, "wrote %d bytes\n", n
);
61 sleep_us(pauserw
*1000);
66 fprintf(stderr
, "pausing before close\n");
67 sleep_us(pauseclose
*1000);
70 if (close(sockfd
) < 0)
71 err_sys("close error"); /* since SO_LINGER may be set */