check_bound.c (258564) | check_bound.c (293229) |
---|---|
1/* $NetBSD: check_bound.c,v 1.2 2000/06/22 08:09:26 fvdl Exp $ */ | 1/* $NetBSD: check_bound.c,v 1.2 2000/06/22 08:09:26 fvdl Exp $ */ |
2/* $FreeBSD: head/usr.sbin/rpcbind/check_bound.c 258564 2013-11-25 16:44:02Z hrs $ */ | 2/* $FreeBSD: head/usr.sbin/rpcbind/check_bound.c 293229 2016-01-06 00:00:11Z asomers $ */ |
3 4/*- 5 * Copyright (c) 2009, Sun Microsystems, Inc. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * - Redistributions of source code must retain the above copyright notice, --- 34 unchanged lines hidden (view full) --- 45 * Checks to see whether the program is still bound to the 46 * claimed address and returns the universal merged address 47 * 48 */ 49 50#include <sys/types.h> 51#include <sys/socket.h> 52#include <rpc/rpc.h> | 3 4/*- 5 * Copyright (c) 2009, Sun Microsystems, Inc. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * - Redistributions of source code must retain the above copyright notice, --- 34 unchanged lines hidden (view full) --- 45 * Checks to see whether the program is still bound to the 46 * claimed address and returns the universal merged address 47 * 48 */ 49 50#include <sys/types.h> 51#include <sys/socket.h> 52#include <rpc/rpc.h> |
53#include <rpc/svc_dg.h> |
|
53#include <stdio.h> 54#include <netconfig.h> 55#include <syslog.h> 56#include <string.h> 57#include <unistd.h> 58#include <stdlib.h> 59 60#include "rpcbind.h" --- 93 unchanged lines hidden (view full) --- 154 * Returns NULL if there was some system error. 155 * Returns "" if the address was not bound, i.e the server crashed. 156 * Returns the merged address otherwise. 157 */ 158char * 159mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char *saddr) 160{ 161 struct fdlist *fdl; | 54#include <stdio.h> 55#include <netconfig.h> 56#include <syslog.h> 57#include <string.h> 58#include <unistd.h> 59#include <stdlib.h> 60 61#include "rpcbind.h" --- 93 unchanged lines hidden (view full) --- 155 * Returns NULL if there was some system error. 156 * Returns "" if the address was not bound, i.e the server crashed. 157 * Returns the merged address otherwise. 158 */ 159char * 160mergeaddr(SVCXPRT *xprt, char *netid, char *uaddr, char *saddr) 161{ 162 struct fdlist *fdl; |
163 struct svc_dg_data *dg_data; |
|
162 char *c_uaddr, *s_uaddr, *m_uaddr, *allocated_uaddr = NULL; 163 164 for (fdl = fdhead; fdl; fdl = fdl->next) 165 if (strcmp(fdl->nconf->nc_netid, netid) == 0) 166 break; 167 if (fdl == NULL) 168 return (NULL); 169 if (check_bound(fdl, uaddr) == FALSE) 170 /* that server died */ 171 return (nullstring); 172 /* | 164 char *c_uaddr, *s_uaddr, *m_uaddr, *allocated_uaddr = NULL; 165 166 for (fdl = fdhead; fdl; fdl = fdl->next) 167 if (strcmp(fdl->nconf->nc_netid, netid) == 0) 168 break; 169 if (fdl == NULL) 170 return (NULL); 171 if (check_bound(fdl, uaddr) == FALSE) 172 /* that server died */ 173 return (nullstring); 174 /* |
175 * Try to determine the local address on which the client contacted us, 176 * so we can send a reply from the same address. If it's unknown, then 177 * try to determine which address the client used, and pick a nearby 178 * local address. 179 * |
|
173 * If saddr is not NULL, the remote client may have included the 174 * address by which it contacted us. Use that for the "client" uaddr, 175 * otherwise use the info from the SVCXPRT. 176 */ | 180 * If saddr is not NULL, the remote client may have included the 181 * address by which it contacted us. Use that for the "client" uaddr, 182 * otherwise use the info from the SVCXPRT. 183 */ |
177 if (saddr != NULL) { | 184 dg_data = (struct svc_dg_data*)xprt->xp_p2; 185 if (dg_data != NULL && dg_data->su_srcaddr.buf != NULL) { 186 c_uaddr = taddr2uaddr(fdl->nconf, &dg_data->su_srcaddr); 187 } 188 else if (saddr != NULL) { |
178 c_uaddr = saddr; 179 } else { 180 c_uaddr = taddr2uaddr(fdl->nconf, svc_getrpccaller(xprt)); 181 if (c_uaddr == NULL) { 182 syslog(LOG_ERR, "taddr2uaddr failed for %s", 183 fdl->nconf->nc_netid); 184 return (NULL); 185 } --- 26 unchanged lines hidden (view full) --- 212 return (m_uaddr); 213} 214 215/* 216 * Returns a netconf structure from its internal list. This 217 * structure should not be freed. 218 */ 219struct netconfig * | 189 c_uaddr = saddr; 190 } else { 191 c_uaddr = taddr2uaddr(fdl->nconf, svc_getrpccaller(xprt)); 192 if (c_uaddr == NULL) { 193 syslog(LOG_ERR, "taddr2uaddr failed for %s", 194 fdl->nconf->nc_netid); 195 return (NULL); 196 } --- 26 unchanged lines hidden (view full) --- 223 return (m_uaddr); 224} 225 226/* 227 * Returns a netconf structure from its internal list. This 228 * structure should not be freed. 229 */ 230struct netconfig * |
220rpcbind_get_conf(char *netid) | 231rpcbind_get_conf(const char *netid) |
221{ 222 struct fdlist *fdl; 223 224 for (fdl = fdhead; fdl; fdl = fdl->next) 225 if (strcmp(fdl->nconf->nc_netid, netid) == 0) 226 break; 227 if (fdl == NULL) 228 return (NULL); 229 return (fdl->nconf); 230} | 232{ 233 struct fdlist *fdl; 234 235 for (fdl = fdhead; fdl; fdl = fdl->next) 236 if (strcmp(fdl->nconf->nc_netid, netid) == 0) 237 break; 238 if (fdl == NULL) 239 return (NULL); 240 return (fdl->nconf); 241} |