Mercurial > hg > freeDiameter
annotate libfdproto/utils.c @ 1093:44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
author | Sebastien Decugis <sdecugis@freediameter.net> |
---|---|
date | Mon, 06 May 2013 16:33:22 +0800 |
parents | 7d7266115a34 |
children | d8591b1c56cd |
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 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
38 DECLARE_FD_DUMP_PROTOTYPE(fd_sa_dump_node, 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]; |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
41 FD_DUMP_HANDLE_OFFSET(); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
42 |
1080
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
43 if (sa) { |
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
44 int rc = getnameinfo(sa, sSAlen( sa ), addrbuf, sizeof(addrbuf), NULL, 0, flags); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
45 if (rc) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
46 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
|
47 } else { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
48 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s", &addrbuf[0]), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
49 } |
1080
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
50 } else { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
51 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
|
52 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
53 |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
54 return *buf; |
1080
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
55 } |
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
56 |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
57 DECLARE_FD_DUMP_PROTOTYPE(fd_sa_dump_node_serv, sSA * sa, int flags) |
1080
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
58 { |
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
59 char addrbuf[INET6_ADDRSTRLEN]; |
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
60 char servbuf[32]; |
1093
44f3e48dfe27
Align the behavior of all fd_*dump functions wrt final \n
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1085
diff
changeset
|
61 FD_DUMP_HANDLE_OFFSET(); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
62 |
1080
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
63 if (sa) { |
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
64 int rc = getnameinfo(sa, sSAlen( sa ), addrbuf, sizeof(addrbuf), servbuf, sizeof(servbuf), flags); |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
65 if (rc) { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
66 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
|
67 } else { |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
68 CHECK_MALLOC_DO( fd_dump_extend( FD_DUMP_STD_PARAMS, "%s", &addrbuf[0]), return NULL); |
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
69 } |
1080
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
70 } else { |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
71 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
|
72 } |
1085
7d7266115a34
Cleaning of the traces in progress
Sebastien Decugis <sdecugis@freediameter.net>
parents:
1084
diff
changeset
|
73 return *buf; |
1080
765134772e47
Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff
changeset
|
74 } |