home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ee.lbl.gov
/
2014.05.ftp.ee.lbl.gov.tar
/
ftp.ee.lbl.gov
/
ipsearch-1.0.tar.gz
/
ipsearch-1.0.tar
/
ipsearch-1.0
/
ipsearch.l
< prev
next >
Wrap
Text File
|
2011-07-06
|
4KB
|
208 lines
O ([0-9]|[0-9][0-9]|[0-1][0-9][0-9]|2[0-4][0-9]|25[0-5])
IP {O}((\.{O}){3})
S [ .]
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <ctype.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "version.h"
#ifdef notdef
#ifdef HAVE_OS_PROTO_H
#include "os-proto.h"
#endif
#endif
#undef yywrap
#define YY_NO_UNPUT
#ifdef FLEX_SCANNER
#endif
int yywrap(void);
int yylex(void);
void addr(const char *, size_t);
void chain2(const char *, size_t, int);
void summary(void);
const char *p;
int i;
int debug = 0;
int timestamp = 0;
int stats = 0;
u_int lineno = 1;
const char *file = "?";
char buf[8192];
int matched = 0;
#define MATCH { \
++matched; \
strcat(buf, yytext); \
BEGIN(INITIAL); \
}
%x ipaddr
%%
<*>{S} {
strcat(buf, yytext);
BEGIN(ipaddr);
}
<*>. {
strcat(buf, yytext);
BEGIN(INITIAL);
}
<*>\n {
if (matched) {
printf("%s\n", buf);
matched = 0;
}
buf[0] = '\0';
BEGIN(INITIAL);
}
%%
/*
* Copyright (c) 2011
* The Regents of the University of California. All rights reserved.
*
* 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) all advertising materials mentioning
* features or use of this software display the following acknowledgement:
* ``This product includes software developed by the University of California,
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
* the University 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.
*/
#ifndef lint
static const char copyright[] =
"@(#) Copyright (c) 2011\n\
The Regents of the University of California. All rights reserved.\n";
static const char rcsid[] =
"@(#) $Id: ipsearch.l 4 2011-07-06 22:22:18Z leres $ (LBL)";
#endif
char *prog;
int targc;
char **targv;
extern char *optarg;
extern int optind, opterr;
/* Forwards */
int main(int, char **);
void usage(void) __attribute__((noreturn));
int
main(argc, argv)
int argc;
char **argv;
{
char *cp;
int op;
if (argv[0] == NULL)
prog = "hf";
else if ((cp = strrchr(argv[0], '/')) != NULL)
prog = cp + 1;
else
prog = argv[0];
opterr = 0;
while ((op = getopt(argc, argv, "dts")) != EOF)
switch (op) {
case 'd':
++debug;
break;
case 't':
++timestamp;
break;
case 's':
++stats;
break;
default:
usage();
}
/* Let yywrap() figure out if there are any arguments to open */
targc = argc - optind;
targv = &argv[optind];
yyin = NULL;
(void)yywrap();
/* Process file opened by yywrap() or stdin if no arguments */
if (yyin)
yylex();
exit(0);
/* XXX */
yyunput(0, NULL);
}
int
yywrap()
{
static int didany = 0;
/* Close file, if necessary */
if (yyin) {
if (yyin != stdin)
(void)fclose(yyin);
yyin = NULL;
}
/* Spin through arguments until we run out or successfully open one */
while (targc > 0) {
file = targv[0];
--targc;
++targv;
++didany;
if ((yyin = fopen(file, "r")) != NULL)
return (0);
perror(file);
}
if (!didany) {
++didany;
yyin = stdin;
file = "<stdin>";
return (0);
}
return (1);
}
void
usage()
{
(void)fprintf(stderr, "Version %s\n", version);
(void)fprintf(stderr, "usage: %s [-dts] [file ...]\n", prog);
exit(1);
}