Detect if a udp socket on STDIN_FILENO is connected by calling

getpeername() and don't set PASSIVE mode if it's is.
This commit is contained in:
Brian Somers 2002-01-23 23:36:35 +00:00
parent ae967e6461
commit c3805e0152

View File

@ -293,21 +293,30 @@ udp_Create(struct physical *p)
}
if (sz == sizeof type && type == SOCK_DGRAM) {
struct sockaddr_in sock;
struct sockaddr *sockp = (struct sockaddr *)&sock;
if ((dev = malloc(sizeof *dev)) == NULL) {
log_Printf(LogWARN, "%s: Cannot allocate a udp device: %s\n",
p->link.name, strerror(errno));
return NULL;
}
/* We can't getpeername().... */
dev->connected = UDP_MAYBEUNCONNECTED;
log_Printf(LogPHASE, "%s: Link is a udp socket\n", p->link.name);
if (p->link.lcp.cfg.openmode != OPEN_PASSIVE) {
log_Printf(LogPHASE, "%s: Changing openmode to PASSIVE\n",
if (getpeername(p->fd, sockp, &sz) == 0) {
log_Printf(LogPHASE, "%s: Link is a connected udp socket\n",
p->link.name);
p->link.lcp.cfg.openmode = OPEN_PASSIVE;
dev->connected = UDP_CONNECTED;
} else {
log_Printf(LogPHASE, "%s: Link is a disconnected udp socket\n",
p->link.name);
dev->connected = UDP_MAYBEUNCONNECTED;
if (p->link.lcp.cfg.openmode != OPEN_PASSIVE) {
log_Printf(LogPHASE, "%s: Changing openmode to PASSIVE\n",
p->link.name);
p->link.lcp.cfg.openmode = OPEN_PASSIVE;
}
}
}
}