This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/lib/faddr.c

106 lines
2.6 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2002-04-25 21:03:54 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Fidonet Address conversions.
*
*****************************************************************************
2002-04-25 21:03:54 +00:00
* Copyright (C) 1993-2002
2001-08-17 05:46:24 +00:00
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MB BBS.
*
* This BBS is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* MB BBS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MB BBS; see the file COPYING. If not, write to the Free
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "libs.h"
#include "structs.h"
#include "common.h"
/************************************************************************
*
* String functions
*/
/*
* Fidonet aka to string, returns Z:N/N@domain or Z:N/N.P@domain
*/
char *aka2str(fidoaddr aka)
{
2002-04-25 21:03:54 +00:00
static char result[43];
2001-08-17 05:46:24 +00:00
2002-04-25 21:03:54 +00:00
result[0] = '\0';
if (strlen(aka.domain)) {
2001-08-17 05:46:24 +00:00
if (aka.point == 0)
2002-04-25 21:03:54 +00:00
sprintf(result, "%d:%d/%d@%s", aka.zone, aka.net, aka.node, aka.domain);
2001-08-17 05:46:24 +00:00
else
2002-04-25 21:03:54 +00:00
sprintf(result, "%d:%d/%d.%d@%s", aka.zone, aka.net, aka.node, aka.point, aka.domain);
} else {
if (aka.point == 0)
sprintf(result, "%d:%d/%d", aka.zone, aka.net, aka.node);
else
sprintf(result, "%d:%d/%d.%d", aka.zone, aka.net, aka.node, aka.point);
}
return result;
2001-08-17 05:46:24 +00:00
}
fidoaddr str2aka(char *addr)
{
char a[256];
static char b[43];
char *temp;
fidoaddr n;
sprintf(b, "%s~", addr);
n.zone = 0;
n.net = 0;
n.node = 0;
n.point = 0;
n.domain[0] = '\0';
if ((strchr(b, ':') == NULL) || (strchr(b, '@') == NULL))
return n;
/* First split the f:n/n.p and domain part
*/
temp = strtok(b, "@");
strcpy(n.domain, strtok(NULL, "~"));
/* Handle f:n/n.p part
*/
strcpy(a, strcat(temp, "~"));
if (strchr(a, '.') == NULL) {
n.zone = atoi(strtok(a, ":"));
n.net = atoi(strtok(NULL, "/"));
n.node = atoi(strtok(NULL, "~"));
} else {
n.zone = atoi(strtok(a, ":"));
n.net = atoi(strtok(NULL, "/"));
n.node = atoi(strtok(NULL, "."));
n.point = atoi(strtok(NULL, "~"));
}
return n;
}