~ubuntu-branches/ubuntu/trusty/sflphone/trusty

« back to all changes in this revision

Viewing changes to daemon/libs/pjproject-2.0.1/third_party/srtp/crypto/replay/ut_sim.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (4.3.4 sid)
  • Revision ID: package-import@ubuntu.com-20140128182336-jrsv0k9u6cawc068
Tags: 1.3.0-1
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * ut_sim.c
3
 
 *
4
 
 * an unreliable transport simulator
5
 
 * (for testing replay databases and suchlike)
6
 
 *
7
 
 * David A. McGrew
8
 
 * Cisco Systems, Inc.
9
 
 */
10
 
 
11
 
/*
12
 
 *
13
 
 * Copyright (c) 2001-2006, Cisco Systems, Inc.
14
 
 * All rights reserved.
15
 
 *
16
 
 * Redistribution and use in source and binary forms, with or without
17
 
 * modification, are permitted provided that the following conditions
18
 
 * are met:
19
 
 *
20
 
 *   Redistributions of source code must retain the above copyright
21
 
 *   notice, this list of conditions and the following disclaimer.
22
 
 *
23
 
 *   Redistributions in binary form must reproduce the above
24
 
 *   copyright notice, this list of conditions and the following
25
 
 *   disclaimer in the documentation and/or other materials provided
26
 
 *   with the distribution.
27
 
 *
28
 
 *   Neither the name of the Cisco Systems, Inc. nor the names of its
29
 
 *   contributors may be used to endorse or promote products derived
30
 
 *   from this software without specific prior written permission.
31
 
 *
32
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33
 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34
 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
35
 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
36
 
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
37
 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38
 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
39
 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40
 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
41
 
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
42
 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
43
 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
44
 
 *
45
 
 */
46
 
 
47
 
 
48
 
#include "ut_sim.h"
49
 
 
50
 
 
51
 
int
52
 
ut_compar(const void *a, const void *b) {
53
 
  return rand() > (RAND_MAX/2) ? -1 : 1;
54
 
}
55
 
 
56
 
void
57
 
ut_init(ut_connection *utc) {
58
 
  int i;
59
 
  utc->index = 0;
60
 
 
61
 
  for (i=0; i < UT_BUF; i++)
62
 
    utc->buffer[i] = i;
63
 
 
64
 
  qsort(utc->buffer, UT_BUF, sizeof(uint32_t), ut_compar);
65
 
 
66
 
  utc->index = UT_BUF - 1;
67
 
}
68
 
 
69
 
uint32_t
70
 
ut_next_index(ut_connection *utc) {
71
 
  uint32_t tmp;
72
 
 
73
 
  tmp = utc->buffer[0];
74
 
  utc->index++;
75
 
  utc->buffer[0] = utc->index;
76
 
 
77
 
  qsort(utc->buffer, UT_BUF, sizeof(uint32_t), ut_compar);
78
 
 
79
 
  return tmp;
80
 
}
81
 
 
82
 
 
83
 
 
84
 
#ifdef UT_TEST
85
 
 
86
 
#include <stdio.h>
87
 
 
88
 
int
89
 
main() {
90
 
  uint32_t i, irecvd, idiff;
91
 
  ut_connection utc;
92
 
 
93
 
  ut_init(&utc);
94
 
 
95
 
  for (i=0; i < 1000; i++) {
96
 
    irecvd = ut_next_index(&utc);
97
 
    idiff = i - irecvd;
98
 
    printf("%lu\t%lu\t%d\n", i, irecvd, idiff);
99
 
  }
100
 
 
101
 
  return 0;
102
 
}
103
 
 
104
 
 
105
 
#endif