annotate libfdproto/utils.c @ 1084:6b7966ea27fb

Fix a few compilation issues
author Sebastien Decugis <sdecugis@freediameter.net>
date Fri, 03 May 2013 15:33:57 +0800
parents 765134772e47
children 7d7266115a34
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
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
38 char * fd_sa_dump_node(char * buf, size_t bufsize, sSA * sa, int flags)
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];
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
41 if (sa) {
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
42 int rc = getnameinfo(sa, sSAlen( sa ), addrbuf, sizeof(addrbuf), NULL, 0, flags);
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
43 if (rc)
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
44 snprintf(buf, bufsize, "%s", gai_strerror(rc));
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
45 else
1084
6b7966ea27fb Fix a few compilation issues
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1080
diff changeset
46 snprintf(buf, bufsize, "%s", &addrbuf[0]);
1080
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
47 } else {
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
48 snprintf(buf, bufsize, "(NULL / ANY)");
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
49 }
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
50 return buf;
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
51 }
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
52
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
53 char * fd_sa_dump_node_serv(char * buf, size_t bufsize, sSA * sa, int flags)
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
54 {
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
55 char addrbuf[INET6_ADDRSTRLEN];
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
56 char servbuf[32];
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
57 if (sa) {
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
58 int rc = getnameinfo(sa, sSAlen( sa ), addrbuf, sizeof(addrbuf), servbuf, sizeof(servbuf), flags);
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
59 if (rc)
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
60 snprintf(buf, bufsize, "%s", gai_strerror(rc));
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
61 else
1084
6b7966ea27fb Fix a few compilation issues
Sebastien Decugis <sdecugis@freediameter.net>
parents: 1080
diff changeset
62 snprintf(buf, bufsize, "%s", &addrbuf[0]);
1080
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
63 } else {
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
64 snprintf(buf, bufsize, "(NULL / ANY)");
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
65 }
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
66 return buf;
765134772e47 Replace macros with functions for dumping sockaddr structures
Sebastien Decugis <sdecugis@freediameter.net>
parents:
diff changeset
67 }
"Welcome to our mercurial repository"