annotate libfdproto/utils.c @ 1240:0420ccc4671a

Add a counter for the sent requests for which we did not wait for an answer. It might be relevant this value contributes to the load estimate of the remote peer, but it is not very reliable
author Sebastien Decugis <sdecugis@freediameter.net>
date Thu, 10 Oct 2013 16:30:55 +0200
parents d4371b7aa0ff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1080
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
1 /*********************************************************************************************************
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
2 * Software License Agreement (BSD License) *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
4 * *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
5 * Copyright (c) 2013, WIDE Project and NICT *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
6 * All rights reserved. *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
7 * *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
8 * Redistribution and use of this software in source and binary forms, with or without modification, are *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
9 * permitted provided that the following conditions are met: *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
10 * *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
11 * * Redistributions of source code must retain the above *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
12 * copyright notice, this list of conditions and the *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
13 * following disclaimer. *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
14 * *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
15 * * Redistributions in binary form must reproduce the above *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
16 * copyright notice, this list of conditions and the *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
17 * following disclaimer in the documentation and/or other *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
18 * materials provided with the distribution. *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
19 * *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
20 * * Neither the name of the WIDE Project or NICT nor the *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
21 * names of its contributors may be used to endorse or *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
22 * promote products derived from this software without *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
23 * specific prior written permission of WIDE Project and *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
24 * NICT. *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
25 * *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
34 *********************************************************************************************************/
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
35
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
36 #include "fdproto-internal.h"
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
37
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
38 DECLARE_FD_DUMP_PROTOTYPE(fd_sa_dump, sSA * sa, int flags)
1080
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
39 {
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
40 char addrbuf[INET6_ADDRSTRLEN];
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
41 char servbuf[32];
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
42 int rc;
1093
44f3e48dfe27 Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1085
diff changeset
43 FD_DUMP_HANDLE_OFFSET();
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
44
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
45 servbuf[0] = 0;
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
46
1080
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
47 if (sa) {
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
48 if (sSAport(sa)) {
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
49 rc = getnameinfo(sa, sSAlen( sa ), addrbuf, sizeof(addrbuf), servbuf, sizeof(servbuf), flags);
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
50 } else {
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
51 rc = getnameinfo(sa, sSAlen( sa ), addrbuf, sizeof(addrbuf), NULL, 0, flags);
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
52 }
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
53 if (rc) {
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
54 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s", gai_strerror(rc)), return NULL);
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
55 } else {
1122
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
56 if (servbuf[0]) {
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
57 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s(%s)", &addrbuf[0], &servbuf[0]), return NULL);
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
58 } else {
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
59 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s", &addrbuf[0]), return NULL);
d4371b7aa0ff New CMake option: ADDRESS_AVP_INCLUDE_PORT. Turn off for standard Host-IP-Address AVPs
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1119
diff changeset
60 }
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
61 }
1080
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
62 } else {
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
63 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "(NULL / ANY)"), return NULL);
1080
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
64 }
1085
7d7266115a34 Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1084
diff changeset
65 return *buf;
1080
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
66 }
1103
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
67
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
68 void fd_sa_sdump_numeric(char * buf /* must be at least sSA_DUMP_STRLEN */, sSA * sa)
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
69 {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
70 char addrbuf[INET6_ADDRSTRLEN];
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
71 char servbuf[32];
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
72
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
73 if (sa) {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
74 int rc = getnameinfo(sa, sSAlen( sa ), addrbuf, sizeof(addrbuf), servbuf, sizeof(servbuf), NI_NUMERICHOST | NI_NUMERICSERV);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
75 if (rc) {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
76 snprintf(buf, sSA_DUMP_STRLEN, "%s", gai_strerror(rc));
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
77 } else {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
78 snprintf(buf, sSA_DUMP_STRLEN, "%s(%s)", addrbuf, servbuf);
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
79 }
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
80 } else {
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
81 snprintf(buf, sSA_DUMP_STRLEN, "(NULL / ANY)");
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
82 }
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
83
d8591b1c56cd Implemented a few hooks
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1093
diff changeset
84 }
"Welcome to our mercurial repository"