/* * Copyright (c) 2001 The Regents of the University of California. * All rights reserved. * This software product is developed by Tony McGregor. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that: (1) source code distributions * retain the above copyright notice and this paragraph in its entirety, * (2) distributions including binary code include the above copyright * notice and this paragraph in its entirety in the documentation or other * materials provided with the distribution, and (3) derivative work or other * resulting materials based on this software product display the following * acknowledgement: ``This work utilizes software developed in whole or in * part by the National Laboratory for Applied Network Research (NLANR) at * the University of California San Diego's San Diego Supercomputer Center, * under a National Science Foundation Cooperative Agreement No. ANI-9807479, * and its contributors.'' * * Neither the NLANR name, the name of the University, funding organizations, * nor the names of its contributors may be used to endorse or promote * products derived from this software without specific prior written * permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ #include #include #include #include #include #include "ipas.h" #undef EXTERN #define EXTERN #include "usage.h" #include "util.h" //Example ipas resolver request program. For the sake of a job to do //this program reads throgh the database and checks the entries //against what the resolver thinks. int main(int argc, char *argv[]) { struct request_t request; struct reply_t reply; FILE *file; char line[132]; char addr[20]; int prefix_len; int asn; // ipas init_comms can search the command line for options that // control the location of the server etc. If you want this for the // whole command line you must use the routines from usage.c to // process the other options. if you want you can just pass the // apporpriate options in start_usage (with the command name in // argv[0]), or, if you prefer, none at all. start_usage(argc, argv, ""); init_comms(CLIENT); end_usage(argv); //print usage message if args left over if ( NULL == (file = fopen("as_map", "r")) ) { fprintf(stderr, "Could not open %s\n", "as_map"); perror(""); exit(-1); } while ( NULL != (fgets(line, 132 - 2, file))) { line[132-1] = '\0'; /*ensure null termination*/ if ( 3 != sscanf(line, "%19[0-9.]/%d %d\n", addr, &prefix_len, &asn) ) { fprintf(stderr, "Bad line in file: %s", line); } else { //construct the message request.version = 1; //version of the protocol request.count = 1; //number of addresses in this request request.ip[0] = ntohl(inet_addr(addr)); //address //send it and get reply send_request(&request, &reply); if ( (reply.ans[0].as != asn && reply.ans[0].ambiguous != asn ) || reply.ans[0].len != prefix_len ) { printf("%15s expected %5d %d got %5d %5d %5d \n", ltoa(request.ip[0]), asn, prefix_len, reply.ans[0].as, reply.ans[0].len, reply.ans[0].ambiguous); } /*if not a match*/ } /* not a bad line */ } /*while*/ fclose(file); exit(0); }