X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnetutl.c;h=e473f17699a0f619dc45ad9cb73f2e057cd3ca09;hp=2abbe86db8727703993fd8e6b41f4c3d43650f7d;hb=ed20896612bcee11ff4180ff78ede950623c2fa6;hpb=776dbf88df1911ec379c2fece0089fd2f5c71021 diff --git a/src/netutl.c b/src/netutl.c index 2abbe86d..e473f176 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -1,7 +1,7 @@ /* netutl.c -- some supporting network utility code Copyright (C) 1998-2005 Ivo Timmermans - 2000-2015 Guus Sliepen + 2000-2016 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -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) {