mp.c (53684) | mp.c (53970) |
---|---|
1/*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/usr.sbin/ppp/mp.c 53684 1999-11-25 02:47:04Z brian $ | 26 * $FreeBSD: head/usr.sbin/ppp/mp.c 53970 1999-11-30 23:52:37Z brian $ |
27 */ 28 29#include <sys/param.h> 30#include <netinet/in.h> 31#include <netinet/in_systm.h> 32#include <netinet/ip.h> 33#include <arpa/inet.h> 34#include <net/if_dl.h> --- 1006 unchanged lines hidden (view full) --- 1041 s->send.dl = NULL; 1042 s->fd = -1; 1043 memset(&s->socket, '\0', sizeof s->socket); 1044} 1045 1046int 1047mpserver_Open(struct mpserver *s, struct peerid *peer) 1048{ | 27 */ 28 29#include <sys/param.h> 30#include <netinet/in.h> 31#include <netinet/in_systm.h> 32#include <netinet/ip.h> 33#include <arpa/inet.h> 34#include <net/if_dl.h> --- 1006 unchanged lines hidden (view full) --- 1041 s->send.dl = NULL; 1042 s->fd = -1; 1043 memset(&s->socket, '\0', sizeof s->socket); 1044} 1045 1046int 1047mpserver_Open(struct mpserver *s, struct peerid *peer) 1048{ |
1049 int f, l, bufsz; | 1049 int f, l; |
1050 mode_t mask; 1051 1052 if (s->fd != -1) { 1053 log_Printf(LogALERT, "Internal error ! mpserver already open\n"); 1054 mpserver_Close(s); 1055 } 1056 1057 l = snprintf(s->socket.sun_path, sizeof s->socket.sun_path, "%sppp-%s-%02x-", --- 13 unchanged lines hidden (view full) --- 1071 return MPSERVER_FAILED; 1072 } 1073 1074 setsockopt(s->fd, SOL_SOCKET, SO_REUSEADDR, (struct sockaddr *)&s->socket, 1075 sizeof s->socket); 1076 mask = umask(0177); 1077 1078 /* | 1050 mode_t mask; 1051 1052 if (s->fd != -1) { 1053 log_Printf(LogALERT, "Internal error ! mpserver already open\n"); 1054 mpserver_Close(s); 1055 } 1056 1057 l = snprintf(s->socket.sun_path, sizeof s->socket.sun_path, "%sppp-%s-%02x-", --- 13 unchanged lines hidden (view full) --- 1071 return MPSERVER_FAILED; 1072 } 1073 1074 setsockopt(s->fd, SOL_SOCKET, SO_REUSEADDR, (struct sockaddr *)&s->socket, 1075 sizeof s->socket); 1076 mask = umask(0177); 1077 1078 /* |
1079 * Calculate how big a link is. It's vital that we set our receive 1080 * buffer size before binding the socket, otherwise we'll end up with 1081 * a sendmsg() failing with ENOBUFS. | 1079 * Try to bind the socket. If we succeed we play server, if we fail 1080 * we connect() and hand the link off. |
1082 */ 1083 | 1081 */ 1082 |
1084 bufsz = bundle_LinkSize() + SOCKET_OVERHEAD; 1085 log_Printf(LogDEBUG, "Setting MP socket buffer size to %d\n", bufsz); 1086 if (setsockopt(s->fd, SOL_SOCKET, SO_RCVBUF, &bufsz, sizeof bufsz) == -1) 1087 log_Printf(LogERROR, "setsockopt(SO_RCVBUF, %d): %s\n", bufsz, 1088 strerror(errno)); 1089 | |
1090 if (ID0bind_un(s->fd, &s->socket) < 0) { 1091 if (errno != EADDRINUSE) { 1092 log_Printf(LogPHASE, "mpserver: can't create bundle socket %s (%s)\n", 1093 s->socket.sun_path, strerror(errno)); 1094 umask(mask); 1095 close(s->fd); 1096 s->fd = -1; 1097 return MPSERVER_FAILED; 1098 } 1099 | 1083 if (ID0bind_un(s->fd, &s->socket) < 0) { 1084 if (errno != EADDRINUSE) { 1085 log_Printf(LogPHASE, "mpserver: can't create bundle socket %s (%s)\n", 1086 s->socket.sun_path, strerror(errno)); 1087 umask(mask); 1088 close(s->fd); 1089 s->fd = -1; 1090 return MPSERVER_FAILED; 1091 } 1092 |
1100 /* Ok, so we'll play sender... set the send buffer size */ 1101 if (setsockopt(s->fd, SOL_SOCKET, SO_SNDBUF, &bufsz, sizeof bufsz) == -1) 1102 log_Printf(LogERROR, "setsockopt(SO_SNDBUF, %d): %s\n", bufsz, 1103 strerror(errno)); | 1093 /* So we're the sender */ |
1104 umask(mask); 1105 if (ID0connect_un(s->fd, &s->socket) < 0) { 1106 log_Printf(LogPHASE, "mpserver: can't connect to bundle socket %s (%s)\n", 1107 s->socket.sun_path, strerror(errno)); 1108 if (errno == ECONNREFUSED) 1109 log_Printf(LogPHASE, " The previous server died badly !\n"); 1110 close(s->fd); 1111 s->fd = -1; --- 40 unchanged lines hidden --- | 1094 umask(mask); 1095 if (ID0connect_un(s->fd, &s->socket) < 0) { 1096 log_Printf(LogPHASE, "mpserver: can't connect to bundle socket %s (%s)\n", 1097 s->socket.sun_path, strerror(errno)); 1098 if (errno == ECONNREFUSED) 1099 log_Printf(LogPHASE, " The previous server died badly !\n"); 1100 close(s->fd); 1101 s->fd = -1; --- 40 unchanged lines hidden --- |