/** * bin_send - computes the checksum of the current packet and then * sends the packet over UDP to the @dest destination * * @return: number of bytes sent, or -1 on error */ int bin_send(union sockaddr_union *dest) { int rc, destlen; str st; if (!dest) return 0; st.s = send_buffer + HEADER_SIZE; st.len = bin_send_size - HEADER_SIZE; /* compute a checksum of the binary packet content */ crc32_uint(&st, (unsigned int *)(send_buffer + BIN_PACKET_MARKER_SIZE)); LM_DBG("sending packet {'%.*s', %d}: %.*s [%d B] from socket %d\n", *(int *)(send_buffer + HEADER_SIZE), send_buffer + HEADER_SIZE + LEN_FIELD_SIZE, bin_send_type, bin_send_size, send_buffer, bin_send_size, bin->socket); destlen=sockaddru_len(*dest); again: rc=sendto(bin->socket, send_buffer, bin_send_size, 0, &dest->s, destlen); if (rc==-1){ if (errno==EINTR) goto again; LM_ERR("sendto() failed with %s(%d)\n", strerror(errno),errno); } return rc; }
static int has_valid_checksum(char *buf, int len) { unsigned int crc, real_crc; str st; crc = *(unsigned int *)(buf + BIN_PACKET_MARKER_SIZE); st.s = buf + HEADER_SIZE; st.len = len - HEADER_SIZE; crc32_uint(&st, &real_crc); return crc == real_crc; }
static int compute_id(str* first, str* second){ unsigned int crc32_val; #define BUF_MAXSIZE 1024 char aux[BUF_MAXSIZE]; str tmp; if(!first){ LM_ERR("Null first parameter received\n"); return -1; } if(use_domain){ //compute crc32(user@domain) LM_DBG("XDBGX: compute_id HAS second key : %.*s", first->len, first->s); if(!second){ LM_ERR("Null second parameter received and use_domain set to true\n"); return -1; } tmp.len = first->len + second->len + 1; if( tmp.len > BUF_MAXSIZE - 1 ){ LM_ERR("Very long user or domain\n"); return -1; } memcpy(aux, first->s, first->len); aux[first->len] = '@'; memcpy(aux + first->len + 1, second->s, second->len); tmp.s = aux; crc32_uint(&tmp, &crc32_val); return crc32_val % max_loc_nr + 1; }else{ crc32_uint(first, &crc32_val); LM_DBG("crc32 for %.*s is %u\n", first->len, first->s, crc32_val); return crc32_val % max_loc_nr + 1; } }
int hash_func (struct sip_msg * msg, enum hash_source source, int denominator) { int ret; unsigned int hash; str source_string; if(determine_source (msg, source, &source_string) == -1) { return -1; } crc32_uint(&source_string, &hash); ret = hash % denominator; LM_DBG("hash: %u %% %i = %i\n", hash, denominator, ret); return ret; }
int hash_func(struct _sipcapture_object *sco, enum hash_source source, int denominator) { int ret; unsigned int hash; str source_string; if(get_source(sco, source, &source_string) == -1) { return -1; } LM_DBG("source string: [%.*s]\n", source_string.len, source_string.s); crc32_uint(&source_string, &hash); ret = hash % denominator; return ret; }