Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Sep 1999 23:48:51 -0700
From:      "N. C. Hong" <nchong@uswest.net>
To:        <freebsd-net@freebsd.org>
Subject:   FreeBSD 3.2 bug when calling connect on a UDP socket?
Message-ID:  <000201bf058f$b27c0e40$0200000a@gchunghome>

next in thread | raw e-mail | index | archive | help
On FreeBSD 3.2, when running two instances of the following program, the
second instance fails during the connect call. It works fine on Windows NT.
I haven't tested on other platforms. I don't see any reason why two UDP
sockets bound to the same port on the same host can't both be "connected" to
a multicast endpoint.

#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdio.h>
#include <errno.h>
#include <assert.h>

void checkError(int status)
{
if (status < 0)
{
fprintf(stderr, "SOCKET ERROR: %d\n", errno);
assert(0);
}
}

void main()
{
int status;
struct sockaddr_in sa;

printf("before socket\n");
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
checkError(sockfd);
printf("after socket\n");

printf("before setsockopt SO_REUSEPORT\n");
const int on = 1;
status = setsockopt(sockfd, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on));
checkError(status);
printf("after setsockopt SO_REUSEPORT\n");

printf("before bind\n");
bzero(&sa, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(10000);
sa.sin_addr.s_addr = htonl(INADDR_ANY);
status = bind(sockfd, (const sockaddr *)&sa, sizeof(sa));
checkError(status);
printf("after bind\n");

printf("before connect\n");
bzero(&sa, sizeof(sa));
sa.sin_family = AF_INET;
sa.sin_port = htons(10001);
sa.sin_addr.s_addr = inet_addr("225.0.0.1");
status = connect(sockfd, (const struct sockaddr *)&sa, sizeof(sa));
checkError(status);
printf("after connect\n");

printf("before recvfrom\n");
char buf[8192];
status = recvfrom(sockfd, buf, 8192, 0, 0, 0);
checkError(status);
printf("after recvfrom\n");
}






To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000201bf058f$b27c0e40$0200000a>