}
}
+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) {
extern void sockaddrunmap(sockaddr_t *);
extern void sockaddrfree(sockaddr_t *);
extern void sockaddrcpy(sockaddr_t *, const sockaddr_t *);
+extern void sockaddr_setport(sockaddr_t *, const char *);
extern int maskcmp(const void *, const void *, int);
extern void maskcpy(void *, const void *, int, int);
extern void mask(void *, int, int);
bool ack_h(connection_t *c) {
char hisport[MAX_STRING_SIZE];
- char *hisaddress;
int weight, mtu;
uint32_t options;
node_t *n;
c->edge = new_edge();
c->edge->from = myself;
c->edge->to = n;
- sockaddr2str(&c->address, &hisaddress, NULL);
- c->edge->address = str2sockaddr(hisaddress, hisport);
- free(hisaddress);
+ sockaddrcpy(&c->edge->address, &c->address);
+ sockaddr_setport(&c->edge->address, hisport);
c->edge->weight = (weight + c->estimated_weight) / 2;
c->edge->connection = c;
c->edge->options = c->options;