mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-24 11:29:10 +00:00
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:
parent
ae967e6461
commit
c3805e0152
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=89720
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user