2015-12-22 12:55:44 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the UCB release of Plan 9. It is subject to the license
|
|
|
|
* terms in the LICENSE file found in the top-level directory of this
|
|
|
|
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
|
|
|
|
* part of the UCB release of Plan 9, including this file, may be copied,
|
|
|
|
* modified, propagated, or distributed except according to the terms contained
|
|
|
|
* in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <u.h>
|
|
|
|
#include <libc.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* make an address, add the defaults
|
|
|
|
*/
|
|
|
|
char *
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_netmkaddr(const char *linear, const char *defnet, const char *defsrv)
|
2015-12-22 12:55:44 +01:00
|
|
|
{
|
|
|
|
static char addr[256];
|
|
|
|
char *cp;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dump network name
|
|
|
|
*/
|
2017-04-19 23:33:14 +02:00
|
|
|
cp = jehanne_strchr(linear, '!');
|
2015-12-22 12:55:44 +01:00
|
|
|
if(cp == 0){
|
|
|
|
if(defnet==0){
|
|
|
|
if(defsrv)
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_snprint(addr, sizeof(addr), "net!%s!%s",
|
2015-12-22 12:55:44 +01:00
|
|
|
linear, defsrv);
|
|
|
|
else
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_snprint(addr, sizeof(addr), "net!%s", linear);
|
2015-12-22 12:55:44 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(defsrv)
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_snprint(addr, sizeof(addr), "%s!%s!%s", defnet,
|
2015-12-22 12:55:44 +01:00
|
|
|
linear, defsrv);
|
|
|
|
else
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_snprint(addr, sizeof(addr), "%s!%s", defnet,
|
2015-12-22 12:55:44 +01:00
|
|
|
linear);
|
|
|
|
}
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if there is already a service, use it
|
|
|
|
*/
|
2017-04-19 23:33:14 +02:00
|
|
|
cp = jehanne_strchr(cp+1, '!');
|
2015-12-22 12:55:44 +01:00
|
|
|
if(cp)
|
|
|
|
return (char *)linear;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* add default service
|
|
|
|
*/
|
|
|
|
if(defsrv == 0)
|
|
|
|
return (char *)linear;
|
2017-04-19 23:33:14 +02:00
|
|
|
jehanne_snprint(addr, sizeof(addr), "%s!%s", linear, defsrv);
|
2015-12-22 12:55:44 +01:00
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|