📄 tr.c
字号:
/* * lib/tr.c This file contains an implementation of the "Tokenring" * support functions. * * Version: $Id: tr.c,v 1.4 1999/04/18 20:28:43 philip Exp $ * * Author: Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Copyright 1993 MicroWalt Corporation * * This program 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 of the License, or (at * your option) any later version. */#include "config.h"#if HAVE_HWTR#include <asm/types.h>#include <sys/types.h>#include <sys/socket.h>#include <net/if_arp.h>#include <linux/if_tr.h>#include <stdlib.h>#include <stdio.h>#include <errno.h>#include <ctype.h>#include <string.h>#include <unistd.h>#include "net-support.h"#include "pathnames.h"#include "intl.h"extern struct hwtype tr_hwtype;static char *pr_tr(unsigned char *ptr){ static char buff[64]; snprintf(buff, sizeof(buff), "%02X:%02X:%02X:%02X:%02X:%02X", (ptr[0] & 0377), (ptr[1] & 0377), (ptr[2] & 0377), (ptr[3] & 0377), (ptr[4] & 0377), (ptr[5] & 0377) ); return (buff);}static char *pr_str(struct sockaddr *sap){ if (sap->sa_family == 0xFFFF || sap->sa_family == 0) return ("[NONE SET]"); return (pr_tr(sap->sa_data));}static int in_tr(char *bufp, struct sockaddr *sap){ unsigned char *ptr; char c, *orig; int i, val; sap->sa_family = tr_hwtype.type; ptr = sap->sa_data; i = 0; orig = bufp; while ((*bufp != '\0') && (i < TR_ALEN)) { val = 0; c = *bufp++; if (isdigit(c)) val = c - '0'; else if (c >= 'a' && c <= 'f') val = c - 'a' + 10; else if (c >= 'A' && c <= 'F') val = c - 'A' + 10; else {#ifdef DEBUG fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);#endif errno = EINVAL; return (-1); } val <<= 4; c = *bufp++; if (isdigit(c)) val |= c - '0'; else if (c >= 'a' && c <= 'f') val |= c - 'a' + 10; else if (c >= 'A' && c <= 'F') val |= c - 'A' + 10; else {#ifdef DEBUG fprintf(stderr, _("in_tr(%s): invalid token ring address!\n"), orig);#endif errno = EINVAL; return (-1); } *ptr++ = (unsigned char) (val & 0377); i++; /* We might get a semicolon here - not required. */ if (*bufp == ':') { if (i == TR_ALEN) {#ifdef DEBUG fprintf(stderr, _("in_tr(%s): trailing : ignored!\n"), orig)#endif ; /* nothing */ } bufp++; } } /* That's it. Any trailing junk? */ if ((i == TR_ALEN) && (*bufp != '\0')) {#ifdef DEBUG fprintf(stderr, _("in_tr(%s): trailing junk!\n"), orig); errno = EINVAL; return (-1);#endif }#ifdef DEBUG fprintf(stderr, "in_tr(%s): %s\n", orig, pr_tr(sap->sa_data));#endif return (0);}struct hwtype tr_hwtype ={ "tr", "16/4 Mbps Token Ring", ARPHRD_IEEE802, TR_ALEN, pr_tr, pr_str, in_tr, NULL};#endif /* HAVE_HWTR */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -