📄 ether.c
字号:
/* ether.c * linqianghe@163.com * 2006-10-20 */#include "config.h"#include <sys/types.h>#include <sys/socket.h>#include <net/if_arp.h>#include <linux/if_ether.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 "util.h"extern struct hwtype ether_hwtype;static char *pr_ether(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 int in_ether(char *bufp, struct sockaddr *sap){ unsigned char *ptr; char c, *orig; int i; unsigned val; sap->sa_family = ether_hwtype.type; ptr = (unsigned char *)sap->sa_data; i = 0; orig = bufp; while ((*bufp != '\0') && (i < ETH_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{ fprintf(stderr, "in_ether(%s): invalid ether address!\n", orig); 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 if( c == ':' || c == 0 ) val >>= 4; else{ fprintf(stderr, "in_ether(%s): invalid ether address!\n", orig); errno = EINVAL; return (-1); } if( c != 0 ) bufp++; *ptr++ = (unsigned char) (val & 0377); i++; if (*bufp == ':') { if (i == ETH_ALEN) { fprintf(stderr, "in_ether(%s): trailing : ignored!\n", orig); } bufp++; } } return (0);}struct hwtype ether_hwtype ={ "ether", NULL, /*"10Mbps Ethernet", */ ARPHRD_ETHER, ETH_ALEN, pr_ether, in_ether, NULL};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -