2 * Copyright (c) 2004-2008 Voltaire Inc. All rights reserved.
\r
3 * Copyright (c) 2008 Intel Corporation. All rights reserved.
\r
5 * This software is available to you under the OpenFabrics.org BSD license
\r
8 * Redistribution and use in source and binary forms, with or
\r
9 * without modification, are permitted provided that the following
\r
10 * conditions are met:
\r
12 * - Redistributions of source code must retain the above
\r
13 * copyright notice, this list of conditions and the following
\r
16 * - Redistributions in binary form must reproduce the above
\r
17 * copyright notice, this list of conditions and the following
\r
18 * disclaimer in the documentation and/or other materials
\r
19 * provided with the distribution.
\r
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
22 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
23 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AWV
\r
24 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
\r
25 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
26 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
32 # include <config.h>
\r
33 #endif /* HAVE_CONFIG_H */
\r
38 #if defined(_WIN32) || defined(_WIN64)
\r
39 #include <windows.h>
\r
40 #include <winsock2.h>
\r
41 #include <ws2tcpip.h>
\r
42 #define snprintf _snprintf
\r
45 #include <pthread.h>
\r
46 #include <sys/time.h>
\r
48 #include <inttypes.h>
\r
49 #include <arpa/inet.h>
\r
55 #define DEBUG if (ibdebug) IBWARN
\r
57 #if defined(_WIN32) || defined(_WIN64)
\r
58 const char * _inet_ntop(int family, const void *addr, char *dst, size_t len)
\r
60 if (family == AF_INET)
\r
62 struct sockaddr_in in;
\r
63 in.sin_family = AF_INET;
\r
64 memcpy(&in.sin_addr, addr, 4);
\r
65 if (getnameinfo((struct sockaddr *)&in,
\r
66 (socklen_t) (sizeof(struct sockaddr_in)),
\r
67 dst, len, NULL, 0, NI_NUMERICHOST))
\r
70 else if (family == AF_INET6)
\r
72 struct sockaddr_in6 in6;
\r
73 memset(&in6, 0, sizeof in6);
\r
74 in6.sin6_family = AF_INET;
\r
75 memcpy(&in6.sin6_addr, addr, sizeof(struct in_addr6));
\r
77 /* if no ipv6 support return simple IPv6 format rule:
\r
78 * A series of "0's in a 16bit block can be represented by "0"
\r
80 if (getnameinfo((struct sockaddr *)&in6, (socklen_t) (sizeof in6),
\r
81 dst, len, NULL, 0, NI_NUMERICHOST))
\r
83 char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
\r
86 if (len < sizeof(tmp))
\r
89 for (i = 0; i < 8; i++)
\r
90 n += sprintf(tmp+n, "%s%x",
\r
92 ntohs(((unsigned short*)addr)[i]));
\r
99 #define inet_ntop _inet_ntop
\r
103 portid2portnum(ib_portid_t *portid)
\r
105 if (portid->lid > 0)
\r
108 if (portid->drpath.cnt == 0)
\r
111 return portid->drpath.p[(portid->drpath.cnt-1)];
\r
115 portid2str(ib_portid_t *portid)
\r
117 static char buf[1024] = "local";
\r
120 if (portid->lid > 0) {
\r
121 n += sprintf(buf + n, "Lid %d", portid->lid);
\r
122 if (portid->grh_present) {
\r
123 char gid[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];
\r
124 if (inet_ntop(AF_INET6, portid->gid, gid, sizeof(gid)))
\r
125 n += sprintf(buf + n, " Gid %s", gid);
\r
127 if (portid->drpath.cnt)
\r
128 n += sprintf(buf + n, " ");
\r
132 n += sprintf(buf + n, "DR path ");
\r
133 drpath2str(&(portid->drpath), buf + n, sizeof(buf) - n);
\r
139 str2drpath(ib_dr_path_t *path, char *routepath, int drslid, int drdlid)
\r
141 char *s, *str = routepath;
\r
145 DEBUG("DR str: %s", routepath);
\r
146 while (str && *str) {
\r
147 if ((s = strchr(str, ',')))
\r
149 path->p[++path->cnt] = (uint8_t)atoi(str);
\r
155 path->drdlid = drdlid ? drdlid : 0xffff;
\r
156 path->drslid = drslid ? drslid : 0xffff;
\r
162 drpath2str(ib_dr_path_t *path, char *dstr, size_t dstr_size)
\r
165 int rc = snprintf(dstr, dstr_size, "slid %d; dlid %d; %d",
\r
166 path->drslid, path->drdlid, path->p[0]);
\r
167 if (rc >= (int) dstr_size)
\r
169 for (i = 1; i <= path->cnt; i++) {
\r
170 rc += snprintf(dstr+rc, dstr_size-rc, ",%d", path->p[i]);
\r
171 if (rc >= (int) dstr_size)
\r