blob: d8df68c110b06b802c7378876d2ea8ef91a3d73b [file] [log] [blame]
* ll_proto.c
* 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.
* Authors: Alexey Kuznetsov, <>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
#include <linux/sockios.h>
#include "utils.h"
#include "rt_names.h"
#define __PF(f,n) { ETH_P_##f, #n },
static const struct {
int id;
const char *name;
} llproto_names[] = {
{ 0x8100, "802.1Q" },
{ 0x88cc, "LLDP" },
{ ETH_P_IP, "ipv4" },
#undef __PF
const char * ll_proto_n2a(unsigned short id, char *buf, int len)
int i;
id = ntohs(id);
for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
if (llproto_names[i].id == id)
return llproto_names[i].name;
snprintf(buf, len, "[%d]", id);
return buf;
int ll_proto_a2n(unsigned short *id, const char *buf)
int i;
for (i=0; i < sizeof(llproto_names)/sizeof(llproto_names[0]); i++) {
if (strcasecmp(llproto_names[i].name, buf) == 0) {
*id = htons(llproto_names[i].id);
return 0;
if (get_u16(id, buf, 0))
return -1;
*id = htons(*id);
return 0;