return(NULL);
}
+struct socket *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data)
+{
+ struct sockaddr_in addr;
+#ifdef HAVE_IPV6
+ struct sockaddr_in6 addr6;
+#endif
+ struct socket *(*csfunc)(int, struct sockaddr *, socklen_t, void (*)(struct socket *, struct socket *, void *), void *);
+ struct socket *ret;
+
+ if(local)
+ csfunc = netcslistenlocal;
+ else
+ csfunc = netcslisten;
+#ifdef HAVE_IPV6
+ memset(&addr6, 0, sizeof(addr6));
+ addr6.sin6_family = AF_INET6;
+ addr6.sin6_port = htons(port);
+ addr6.sin6_addr = in6addr_any;
+ if((ret = csfunc(SOCK_STREAM, (struct sockaddr *)&addr6, sizeof(addr6), func, data)) != NULL)
+ return(ret);
+ if((ret == NULL) && (errno != EAFNOSUPPORT))
+ return(NULL);
+#endif
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = htons(port);
+ return(csfunc(SOCK_STREAM, (struct sockaddr *)&addr, sizeof(addr), func, data));
+}
+
struct socket *netcsdgram(struct sockaddr *name, socklen_t namelen)
{
struct socket *sk;
void getsock(struct socket *sk);
struct socket *netcslisten(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
struct socket *netcslistenlocal(int type, struct sockaddr *name, socklen_t namelen, void (*func)(struct socket *, struct socket *, void *), void *data);
+struct socket *netcstcplisten(int port, int local, void (*func)(struct socket *, struct socket *, void *), void *data);
struct socket *netcsconn(struct sockaddr *addr, socklen_t addrlen, void (*func)(struct socket *, int, void *), void *data);
int pollsocks(int timeout);
void sockqueue(struct socket *sk, void *data, size_t size);
}
}
-#ifdef HAVE_IPV6
-static struct sockaddr *getnameforport(int port, socklen_t *len)
-{
- static struct sockaddr_in6 addr;
-
- memset(&addr, 0, sizeof(addr));
- addr.sin6_family = AF_INET6;
- addr.sin6_port = htons(port);
- addr.sin6_addr = in6addr_any;
- if(len != NULL)
- *len = sizeof(addr);
- return((struct sockaddr *)&addr);
-}
-#else
-static struct sockaddr *getnameforport(int port, socklen_t *len)
-{
- static struct sockaddr_in addr;
-
- memset(&addr, 0, sizeof(addr));
- addr.sin_family = AF_INET;
- addr.sin_port = htons(port);
- if(len != NULL)
- *len = sizeof(addr);
- return((struct sockaddr *)&addr);
-}
-#endif
-
static int portupdate(struct configvar *var, void *uudata)
{
- struct sockaddr *addr;
- socklen_t addrlen;
struct socket *newsock;
- addr = getnameforport(var->val.num, &addrlen);
- if((uisocket = netcslistenlocal(SOCK_STREAM, addr, addrlen, uiaccept, NULL)) == NULL)
+ if((uisocket = netcstcplisten(var->val.num, 1, uiaccept, NULL)) == NULL)
{
flog(LOG_WARNING, "could not create new UI socket, reverting to old: %s", strerror(errno));
return(0);
static int init(int hup)
{
- struct sockaddr *addr;
- socklen_t addrlen;
struct uiuser *user, *next;
if(hup)
{
if(uisocket != NULL)
putsock(uisocket);
- addr = getnameforport(confgetint("ui", "port"), &addrlen);
- if((uisocket = netcslistenlocal(SOCK_STREAM, addr, addrlen, uiaccept, NULL)) == NULL)
+ if((uisocket = netcstcplisten(confgetint("ui", "port"), 1, uiaccept, NULL)) == NULL)
{
flog(LOG_CRIT, "could not create UI socket: %s", strerror(errno));
return(1);