Format IPv6 address with brackets.
[doldaconnect.git] / daemon / net.c
index 16bcbe7..866e136 100644 (file)
@@ -90,7 +90,7 @@ int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf)
            *lenbuf = sizeof(*ipv4);
            return(0);
        }
-       if((pif = icwcstombs(confgetstr("net", "publicif"), NULL)) == NULL)
+       if((pif = icswcstombs(confgetstr("net", "publicif"), NULL, NULL)) == NULL)
        {
            flog(LOG_ERR, "could not convert net.publicif into local charset: %s", strerror(errno));
            return(-1);
@@ -128,12 +128,14 @@ int getpublicaddr(int af, struct sockaddr **addr, socklen_t *lenbuf)
                    memcpy(ipv4, &ifr->ifr_addr, sizeof(ifr->ifr_addr));
                } else {
                    free(ipv4);
+                   free(conf.ifc_buf);
                    flog(LOG_WARNING, "could not locate an unambiguous interface for determining your public IP address - set net.publicif");
                    errno = ENFILE; /* XXX: There's no appropriate one for this... */
                    return(-1);
                }
            }
        }
+       free(conf.ifc_buf);
        close(sock);
        if(ipv4 != NULL)
        {
@@ -866,17 +868,20 @@ int socksettos(struct socket *sk, int tos)
     {
        switch(tos)
        {
+       case 0:
+           buf = 0;
+           break;
        case SOCK_TOS_MINCOST:
-           buf = IPTOS_MINCOST;
+           buf = 0x02;
            break;
        case SOCK_TOS_MAXREL:
-           buf = IPTOS_RELIABILITY;
+           buf = 0x04;
            break;
        case SOCK_TOS_MAXTP:
-           buf = IPTOS_THROUGHPUT;
+           buf = 0x08;
            break;
        case SOCK_TOS_MINDELAY:
-           buf = IPTOS_LOWDELAY;
+           buf = 0x10;
            break;
        default:
            flog(LOG_WARNING, "attempted to set unknown TOS value %i to IPv4 sock", tos);
@@ -893,6 +898,8 @@ int socksettos(struct socket *sk, int tos)
     {
        switch(tos)
        {
+       case 0:
+           buf = 0;
        case SOCK_TOS_MINCOST:
            buf = confgetint("net", "diffserv-mincost");
            break;
@@ -1117,7 +1124,7 @@ char *formataddress(struct sockaddr *arg, socklen_t arglen)
        ipv6 = (struct sockaddr_in6 *)arg;
        if(inet_ntop(AF_INET6, &ipv6->sin6_addr, buf, sizeof(buf)) == NULL)
            return(NULL);
-       ret = sprintf2("%s:%i", buf, (int)ntohs(ipv6->sin6_port));
+       ret = sprintf2("[%s]:%i", buf, (int)ntohs(ipv6->sin6_port));
        break;
 #endif
     default: