Preserve IPv6 scope_id in edges.
[oweals/tinc.git] / src / netutl.c
index 2abbe86..37887be 100644 (file)
@@ -231,6 +231,25 @@ void sockaddrunmap(sockaddr_t *sa) {
        }
 }
 
+void sockaddr_setport(sockaddr_t *sa, const char *port) {
+       uint16_t portnum = htons(atoi(port));
+       if(!portnum)
+               return;
+       switch(sa->sa.sa_family) {
+               case AF_INET:
+                       sa->in.sin_port = portnum;
+                       break;
+               case AF_INET6:
+                       sa->in6.sin6_port = portnum;
+                       break;
+               case AF_UNKNOWN:
+                       free(sa->unknown.port);
+                       sa->unknown.port = xstrdup(port);
+               default:
+                       return;
+       }
+}
+
 /* Subnet mask handling */
 
 int maskcmp(const void *va, const void *vb, int masklen) {