- memset(key, 0, KEY_LENGTH);
-
- if(from.ss_family == AF_INET) {
- memcpy(fromaddress, &((struct sockaddr_in*)&from)->sin_addr, sizeof(in_addr_t));
- fromport = ntohs(((struct sockaddr_in*)&from)->sin_port);
- memcpy(&key[0], &fromport, 2);
- memcpy(&key[2], fromaddress, sizeof(in_addr_t));
- } else {
- memcpy(fromaddress, &((struct sockaddr_in6*)&from)->sin6_addr, 4 * sizeof(in_addr_t));
- fromport = ntohs(((struct sockaddr_in6*)&from)->sin6_port);
- memcpy(&key[0], &fromport, 2);
- memcpy(&key[2], fromaddress, 4 * sizeof(in_addr_t));
- }
-
- if (len == 0) {
- return -1;
- } else if (len < 0) {
+ memset(key, 0, KEY_LENGTH);
+
+ fromport = Util_addressToPort(&from);
+
+ if(from.ss_family == AF_INET) {
+ memcpy(fromaddress, &((struct sockaddr_in*)&from)->sin_addr, sizeof(in_addr_t));
+ memcpy(&key[0], &fromport, 2);
+ memcpy(&key[2], fromaddress, sizeof(in_addr_t));
+ } else {
+ memcpy(fromaddress, &((struct sockaddr_in6*)&from)->sin6_addr, 4 * sizeof(in_addr_t));
+ memcpy(&key[0], &fromport, 2);
+ memcpy(&key[2], fromaddress, 4 * sizeof(in_addr_t));
+ }
+
+ if (len <= 0)