PERFORCE change 125015 for review
Matus Harvan
mharvan at FreeBSD.org
Fri Aug 10 07:57:38 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=125015
Change 125015 by mharvan at mharvan_bike-planet on 2007/08/10 14:57:03
test program for UDP_CATCHALL was broken
Well, it is still not fully funtional, but at least less broken.
Affected files ...
.. //depot/projects/soc2007/mharvan-mtund/sys.patches/catchall_tcp_udp/test_catchall/README#1 add
.. //depot/projects/soc2007/mharvan-mtund/sys.patches/catchall_tcp_udp/test_catchall/ucatchalld.c#2 edit
Differences ...
==== //depot/projects/soc2007/mharvan-mtund/sys.patches/catchall_tcp_udp/test_catchall/ucatchalld.c#2 (text+ko) ====
@@ -279,9 +279,14 @@
{
int fd;
char *msg = "Welcome to catchalld\r\n";
- int n, nwrite;
+ int n, nwrite, nread;
int soval = 1;
int count = 5;
+ char buf[1234];
+ struct sockaddr_storage from;
+ socklen_t fromlen = sizeof(from);
+ char host[NI_MAXHOST];
+ char serv[NI_MAXSERV];
fd = udp_open("1234");
@@ -289,11 +294,33 @@
err(EX_UNAVAILABLE, "setsockopt(UDP_CATCHALL) failed");
while (count > 0) {
+ nread = recvfrom(fd, buf, sizeof(buf), 0,
+ (struct sockaddr *) &from, &fromlen);
+ if (nread < 0) {
+ warn("recvfrom() returned %d", nread);
+ continue;
+ }
+
+ if (getnameinfo((struct sockaddr *) &from, fromlen,
+ host, sizeof(host), serv, sizeof(serv),
+ NI_NUMERICHOST | NI_DGRAM) ) {
+ fprintf(stderr, "getnameinfo failed: %s\n",
+ gai_strerror(errno));
+ } else {
+ fprintf(stderr, "received traffic from client %s:%s\n",
+ host, serv);
+ }
+
fprintf(stderr, "traffic on UDP socket \n");
n = 0;
nwrite = 0;
do {
- nwrite = send(fd, msg + n, strlen(msg) - n, 0);
+ nwrite = sendto(fd, msg + n, strlen(msg) - n, 0,
+ (struct sockaddr *) &from, fromlen);
+ if (nwrite < 0)
+ warn("sendto() returned %d", nwrite);
+ else if (nwrite == 0)
+ warnx("sendto() returned %d", nwrite);
n += nwrite;
} while (n < strlen(msg) && nwrite > 0);
count--;
More information about the p4-projects
mailing list