Annotation of embedaddon/libpdel/net/test/arptest.c, revision 1.1.1.1

1.1       misho       1: 
                      2: /*
                      3:  * Copyright (c) 2001-2002 Packet Design, LLC.
                      4:  * All rights reserved.
                      5:  * 
                      6:  * Subject to the following obligations and disclaimer of warranty,
                      7:  * use and redistribution of this software, in source or object code
                      8:  * forms, with or without modifications are expressly permitted by
                      9:  * Packet Design; provided, however, that:
                     10:  * 
                     11:  *    (i)  Any and all reproductions of the source or object code
                     12:  *         must include the copyright notice above and the following
                     13:  *         disclaimer of warranties; and
                     14:  *    (ii) No rights are granted, in any manner or form, to use
                     15:  *         Packet Design trademarks, including the mark "PACKET DESIGN"
                     16:  *         on advertising, endorsements, or otherwise except as such
                     17:  *         appears in the above copyright notice or in the software.
                     18:  * 
                     19:  * THIS SOFTWARE IS BEING PROVIDED BY PACKET DESIGN "AS IS", AND
                     20:  * TO THE MAXIMUM EXTENT PERMITTED BY LAW, PACKET DESIGN MAKES NO
                     21:  * REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING
                     22:  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY AND ALL IMPLIED
                     23:  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
                     24:  * OR NON-INFRINGEMENT.  PACKET DESIGN DOES NOT WARRANT, GUARANTEE,
                     25:  * OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF, OR THE RESULTS
                     26:  * OF THE USE OF THIS SOFTWARE IN TERMS OF ITS CORRECTNESS, ACCURACY,
                     27:  * RELIABILITY OR OTHERWISE.  IN NO EVENT SHALL PACKET DESIGN BE
                     28:  * LIABLE FOR ANY DAMAGES RESULTING FROM OR ARISING OUT OF ANY USE
                     29:  * OF THIS SOFTWARE, INCLUDING WITHOUT LIMITATION, ANY DIRECT,
                     30:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE, OR CONSEQUENTIAL
                     31:  * DAMAGES, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, LOSS OF
                     32:  * USE, DATA OR PROFITS, HOWEVER CAUSED AND UNDER ANY THEORY OF
                     33:  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     34:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
                     35:  * THE USE OF THIS SOFTWARE, EVEN IF PACKET DESIGN IS ADVISED OF
                     36:  * THE POSSIBILITY OF SUCH DAMAGE.
                     37:  *
                     38:  * Author: Archie Cobbs <archie@freebsd.org>
                     39:  */
                     40: 
                     41: #include <sys/types.h>
                     42: #include <sys/socket.h>
                     43: #include <net/ethernet.h>
                     44: #include <netinet/in.h>
                     45: #include <arpa/inet.h>
                     46: 
                     47: #include <stdio.h>
                     48: #include <unistd.h>
                     49: #include <err.h>
                     50: 
                     51: #include <pdel/net/if_util.h>
                     52: 
                     53: int
                     54: main(int ac, char **av)
                     55: {
                     56:        struct ether_addr *ea;
                     57:        const u_char *ether = NULL;
                     58:        struct in_addr ip;
                     59:        int publish = 0;
                     60:        int temp = 0;
                     61:        int ch;
                     62: 
                     63:        while ((ch = getopt(ac, av, "tp")) != -1) {
                     64:                switch (ch) {
                     65:                case 't':
                     66:                        temp = 1;
                     67:                        break;
                     68:                case 'p':
                     69:                        publish = 1;
                     70:                        break;
                     71:                default:
                     72:                        goto usage;
                     73:                }
                     74:        }
                     75:        ac -= optind;
                     76:        av += optind;
                     77: 
                     78:        /* set command */
                     79:        if ((ac == 2 || ac == 3) && strcmp(av[0], "set") == 0) {
                     80:                if (ac == 3) {
                     81:                        if ((ea = ether_aton(av[2])) == NULL)
                     82:                                goto usage;
                     83:                        ether = ea->octet;
                     84:                }
                     85:                if (!inet_aton(av[1], &ip))
                     86:                        goto usage;
                     87:                if (if_set_arp(ip, ether, temp, publish) == -1)
                     88:                        err(1, "if_set_arp");
                     89:                return (0);
                     90:        }
                     91: 
                     92:        /* flush command */
                     93:        if (ac == 1 && strcmp(av[0], "flush") == 0) {
                     94:                if (if_flush_arp() == -1)
                     95:                        err(1, "if_flush_arp");
                     96:                return (0);
                     97:        }
                     98: 
                     99:        /* get command */
                    100:        if (ac == 2 && strcmp(av[0], "get") == 0) {
                    101:                struct ether_addr mac;
                    102: 
                    103:                if (!inet_aton(av[1], &ip))
                    104:                        goto usage;
                    105:                if (if_get_arp(ip, (u_char *)&mac) == -1)
                    106:                        err(1, "%s", inet_ntoa(ip));
                    107:                printf("%s is at %s\n", inet_ntoa(ip), ether_ntoa(&mac));
                    108:                return (0);
                    109:        }
                    110: 
                    111: usage:
                    112:        /* Unknown usage */
                    113:        (void)fprintf(stderr, "Usage: arptest"
                    114:            " < [-tp] set ip [ether] | flush | get ip >\n");
                    115:        exit(1);
                    116: }
                    117: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>