1*8583b49cSjoerg /* $NetBSD: stdethers.c,v 1.19 2011/08/30 21:10:29 joerg Exp $ */
260aa689cSthorpej
360aa689cSthorpej /*
460aa689cSthorpej * Copyright (c) 1995 Mats O Jansson <moj@stacken.kth.se>
560aa689cSthorpej * All rights reserved.
660aa689cSthorpej *
760aa689cSthorpej * Redistribution and use in source and binary forms, with or without
860aa689cSthorpej * modification, are permitted provided that the following conditions
960aa689cSthorpej * are met:
1060aa689cSthorpej * 1. Redistributions of source code must retain the above copyright
1160aa689cSthorpej * notice, this list of conditions and the following disclaimer.
1260aa689cSthorpej * 2. Redistributions in binary form must reproduce the above copyright
1360aa689cSthorpej * notice, this list of conditions and the following disclaimer in the
1460aa689cSthorpej * documentation and/or other materials provided with the distribution.
1560aa689cSthorpej *
1660aa689cSthorpej * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
1760aa689cSthorpej * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1860aa689cSthorpej * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1960aa689cSthorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
2060aa689cSthorpej * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2160aa689cSthorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2260aa689cSthorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2360aa689cSthorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2460aa689cSthorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2560aa689cSthorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2660aa689cSthorpej * SUCH DAMAGE.
2760aa689cSthorpej */
2860aa689cSthorpej
297eaa3f73Slukem #include <sys/cdefs.h>
307eaa3f73Slukem #ifndef lint
31*8583b49cSjoerg __RCSID("$NetBSD: stdethers.c,v 1.19 2011/08/30 21:10:29 joerg Exp $");
327eaa3f73Slukem #endif
337eaa3f73Slukem
3460aa689cSthorpej #include <sys/types.h>
3560aa689cSthorpej #include <sys/param.h>
3660aa689cSthorpej #include <sys/socket.h>
3760aa689cSthorpej #include <net/if.h>
3800cef679Sis #include <net/if_ether.h>
3960aa689cSthorpej #include <netinet/in.h>
4060aa689cSthorpej #include <err.h>
4160aa689cSthorpej #include <limits.h>
4260aa689cSthorpej #include <stdio.h>
43211a72a8Slukem #include <stdlib.h>
4460aa689cSthorpej #include <string.h>
4560aa689cSthorpej
4660aa689cSthorpej #include "protos.h"
4760aa689cSthorpej
48*8583b49cSjoerg __dead static void usage(void);
4960aa689cSthorpej
5060aa689cSthorpej
5160aa689cSthorpej int
main(int argc,char * argv[])52559abfe3Swiz main(int argc, char *argv[])
5360aa689cSthorpej {
5460aa689cSthorpej struct ether_addr eth_addr;
55f4fb444bSlukem FILE *data_file;
5641dc2c91Skleink size_t line_no;
57ade3ce97Sthorpej size_t len;
58d3d3aa62Slukem const char *fname;
59d3d3aa62Slukem char *p;
60a8b7ec8dSlukem char hostname[MAXHOSTNAMELEN + 1];
6160aa689cSthorpej
6260aa689cSthorpej if (argc > 2)
6360aa689cSthorpej usage();
6460aa689cSthorpej
6560aa689cSthorpej if (argc == 2) {
6660aa689cSthorpej fname = argv[1];
6760aa689cSthorpej data_file = fopen(fname, "r");
6860aa689cSthorpej if (data_file == NULL)
6960aa689cSthorpej err(1, "%s", fname);
7060aa689cSthorpej } else {
7160aa689cSthorpej fname = "<stdin>";
7260aa689cSthorpej data_file = stdin;
7360aa689cSthorpej }
7460aa689cSthorpej
75f4fb444bSlukem line_no = 0;
76211a72a8Slukem for (;
77211a72a8Slukem (p = fparseln(data_file, &len, &line_no, NULL, FPARSELN_UNESCALL));
78211a72a8Slukem free(p)) {
79211a72a8Slukem if (len == 0)
8060aa689cSthorpej continue;
8160aa689cSthorpej
82f4fb444bSlukem if (ether_line(p, ð_addr, hostname) == 0)
8316199f1dSlukem printf("%s\t%s\n", ether_ntoa(ð_addr), hostname);
8460aa689cSthorpej else
8541dc2c91Skleink warnx("ignoring line %lu: `%s'",
8641dc2c91Skleink (unsigned long)line_no, p);
8760aa689cSthorpej }
8860aa689cSthorpej
891a16cf8dShubertf return 0;
9060aa689cSthorpej }
9160aa689cSthorpej
92*8583b49cSjoerg static void
usage(void)93559abfe3Swiz usage(void)
9460aa689cSthorpej {
9560aa689cSthorpej
9625bdbb66Scgd fprintf(stderr, "usage: %s [file]\n", getprogname());
9760aa689cSthorpej exit(1);
9860aa689cSthorpej }
99