Deleted Added
full compact
iplang_y.y (34739) iplang_y.y (37074)
1%{
2/*
3 * Copyright (C) 1997 by Darren Reed.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and due credit is given
7 * to the original author and the contributors.
8 *
1%{
2/*
3 * Copyright (C) 1997 by Darren Reed.
4 *
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and due credit is given
7 * to the original author and the contributors.
8 *
9 * $Id: iplang_y.y,v 2.0.2.18.2.5 1997/12/10 09:54:45 darrenr Exp $
9 * $Id: iplang_y.y,v 2.0.2.18.2.7 1998/05/23 14:29:53 darrenr Exp $
10 */
11
12#include <stdio.h>
13#include <string.h>
14#include <fcntl.h>
15#if !defined(__SVR4) && !defined(__svr4__)
16#include <strings.h>
17#else

--- 25 unchanged lines hidden (view full) ---

43#include <arpa/inet.h>
44#include <resolv.h>
45#include <ctype.h>
46#include "ipsend.h"
47#include "ip_compat.h"
48#include "ipf.h"
49#include "iplang.h"
50
10 */
11
12#include <stdio.h>
13#include <string.h>
14#include <fcntl.h>
15#if !defined(__SVR4) && !defined(__svr4__)
16#include <strings.h>
17#else

--- 25 unchanged lines hidden (view full) ---

43#include <arpa/inet.h>
44#include <resolv.h>
45#include <ctype.h>
46#include "ipsend.h"
47#include "ip_compat.h"
48#include "ipf.h"
49#include "iplang.h"
50
51#ifndef __NetBSD__
51extern struct ether_addr *ether_aton __P((char *));
52extern struct ether_addr *ether_aton __P((char *));
53#endif
52
53extern int opts;
54extern struct ipopt_names ionames[];
55extern int state, state, lineNum, token;
56extern int yylineno;
57extern char yytext[];
58extern FILE *yyin;
59int yylex __P((void));

--- 280 unchanged lines hidden (view full) ---

340
341tcpopts:
342 | tcpopt tcpopts
343 ;
344
345tcpopt: IL_TCPO_NOP ';' { set_tcpopt(IL_TCPO_NOP, NULL); }
346 | IL_TCPO_EOL ';' { set_tcpopt(IL_TCPO_EOL, NULL); }
347 | IL_TCPO_MSS optoken { set_tcpopt(IL_TCPO_MSS,&$2);}
54
55extern int opts;
56extern struct ipopt_names ionames[];
57extern int state, state, lineNum, token;
58extern int yylineno;
59extern char yytext[];
60extern FILE *yyin;
61int yylex __P((void));

--- 280 unchanged lines hidden (view full) ---

342
343tcpopts:
344 | tcpopt tcpopts
345 ;
346
347tcpopt: IL_TCPO_NOP ';' { set_tcpopt(IL_TCPO_NOP, NULL); }
348 | IL_TCPO_EOL ';' { set_tcpopt(IL_TCPO_EOL, NULL); }
349 | IL_TCPO_MSS optoken { set_tcpopt(IL_TCPO_MSS,&$2);}
348 | IL_TCPO_WSCALE optoken { set_tcpopt(IL_TCPO_MSS,&$2);}
350 | IL_TCPO_WSCALE optoken { set_tcpopt(IL_TCPO_WSCALE,&$2);}
349 | IL_TCPO_TS optoken { set_tcpopt(IL_TCPO_TS, &$2);}
350 ;
351
352udp: IL_UDP { new_udpheader(); }
353 ;
354
355udpline:
356 '{' udpheader '}' ';' { end_udp(); }

--- 417 unchanged lines hidden (view full) ---

774 }
775 val <<= 3;
776 val |= (c - '0');
777 }
778 if (!isdigit(c) || !todo) {
779 *t++ = (u_char)(val & 0xff);
780 todo = 0;
781 }
351 | IL_TCPO_TS optoken { set_tcpopt(IL_TCPO_TS, &$2);}
352 ;
353
354udp: IL_UDP { new_udpheader(); }
355 ;
356
357udpline:
358 '{' udpheader '}' ';' { end_udp(); }

--- 417 unchanged lines hidden (view full) ---

776 }
777 val <<= 3;
778 val |= (c - '0');
779 }
780 if (!isdigit(c) || !todo) {
781 *t++ = (u_char)(val & 0xff);
782 todo = 0;
783 }
784 if (todo)
785 continue;
782 }
783 if (quote) {
784 if (isdigit(c)) {
785 todo = 2;
786 if (c > '7') {
787 fprintf(stderr, "octal with %c!\n", c);
788 break;
789 }

--- 12 unchanged lines hidden (view full) ---

802 break;
803 case 'r' :
804 *t++ = '\r';
805 break;
806 case 't' :
807 *t++ = '\t';
808 break;
809 }
786 }
787 if (quote) {
788 if (isdigit(c)) {
789 todo = 2;
790 if (c > '7') {
791 fprintf(stderr, "octal with %c!\n", c);
792 break;
793 }

--- 12 unchanged lines hidden (view full) ---

806 break;
807 case 'r' :
808 *t++ = '\r';
809 break;
810 case 't' :
811 *t++ = '\t';
812 break;
813 }
810 quote = 0;
811 }
814 }
815 quote = 0;
812 continue;
813 }
814
815 if (c == '\\')
816 quote = 1;
817 else
818 *t++ = c;
819 }
816 continue;
817 }
818
819 if (c == '\\')
820 quote = 1;
821 else
822 *t++ = c;
823 }
824 if (todo)
825 *t++ = (u_char)(val & 0xff);
820 if (quote)
821 *t++ = '\\';
822 len = t - (u_char *)canip->ah_data;
823 inc_anipheaders(len - canip->ah_len);
824 canip->ah_len = len;
825}
826
827

--- 77 unchanged lines hidden (view full) ---

905 free(*arg);
906 *arg = NULL;
907}
908
909
910void set_ipv4off(arg)
911char **arg;
912{
826 if (quote)
827 *t++ = '\\';
828 len = t - (u_char *)canip->ah_data;
829 inc_anipheaders(len - canip->ah_len);
830 canip->ah_len = len;
831}
832
833

--- 77 unchanged lines hidden (view full) ---

911 free(*arg);
912 *arg = NULL;
913}
914
915
916void set_ipv4off(arg)
917char **arg;
918{
913 ip->ip_off = strtol(*arg, NULL, 0);
919 ip->ip_off = htons(strtol(*arg, NULL, 0));
914 free(*arg);
915 *arg = NULL;
916}
917
918
919void set_ipv4v(arg)
920char **arg;
921{

--- 34 unchanged lines hidden (view full) ---

956 free(*arg);
957 *arg = NULL;
958}
959
960
961void set_ipv4id(arg)
962char **arg;
963{
920 free(*arg);
921 *arg = NULL;
922}
923
924
925void set_ipv4v(arg)
926char **arg;
927{

--- 34 unchanged lines hidden (view full) ---

962 free(*arg);
963 *arg = NULL;
964}
965
966
967void set_ipv4id(arg)
968char **arg;
969{
964 ip->ip_id = strtol(*arg, NULL, 0);
970 ip->ip_id = htons(strtol(*arg, NULL, 0));
965 free(*arg);
966 *arg = NULL;
967}
968
969
970void set_ipv4sum(arg)
971char **arg;
972{

--- 21 unchanged lines hidden (view full) ---

994
995 if ((ip->ip_p) && (ip->ip_p != IPPROTO_TCP)) {
996 fprintf(stderr, "protocol %d specified with TCP!\n", ip->ip_p);
997 return;
998 }
999 ip->ip_p = IPPROTO_TCP;
1000
1001 tcp = (tcphdr_t *)new_header(IPPROTO_TCP);
971 free(*arg);
972 *arg = NULL;
973}
974
975
976void set_ipv4sum(arg)
977char **arg;
978{

--- 21 unchanged lines hidden (view full) ---

1000
1001 if ((ip->ip_p) && (ip->ip_p != IPPROTO_TCP)) {
1002 fprintf(stderr, "protocol %d specified with TCP!\n", ip->ip_p);
1003 return;
1004 }
1005 ip->ip_p = IPPROTO_TCP;
1006
1007 tcp = (tcphdr_t *)new_header(IPPROTO_TCP);
1002 tcp->th_win = 4096;
1008 tcp->th_win = htons(4096);
1003 tcp->th_off = sizeof(*tcp) >> 2;
1004}
1005
1006
1007void set_tcpsport(arg)
1008char **arg;
1009{
1010 u_short *port;

--- 31 unchanged lines hidden (view full) ---

1042 free(*arg);
1043 *arg = NULL;
1044}
1045
1046
1047void set_tcpseq(arg)
1048char **arg;
1049{
1009 tcp->th_off = sizeof(*tcp) >> 2;
1010}
1011
1012
1013void set_tcpsport(arg)
1014char **arg;
1015{
1016 u_short *port;

--- 31 unchanged lines hidden (view full) ---

1048 free(*arg);
1049 *arg = NULL;
1050}
1051
1052
1053void set_tcpseq(arg)
1054char **arg;
1055{
1050 tcp->th_seq = strtol(*arg, NULL, 0);
1056 tcp->th_seq = htonl(strtol(*arg, NULL, 0));
1051 free(*arg);
1052 *arg = NULL;
1053}
1054
1055
1056void set_tcpack(arg)
1057char **arg;
1058{
1057 free(*arg);
1058 *arg = NULL;
1059}
1060
1061
1062void set_tcpack(arg)
1063char **arg;
1064{
1059 tcp->th_ack = strtol(*arg, NULL, 0);
1065 tcp->th_ack = htonl(strtol(*arg, NULL, 0));
1060 free(*arg);
1061 *arg = NULL;
1062}
1063
1064
1065void set_tcpoff(arg)
1066char **arg;
1067{

--- 5 unchanged lines hidden (view full) ---

1073 free(*arg);
1074 *arg = NULL;
1075}
1076
1077
1078void set_tcpurp(arg)
1079char **arg;
1080{
1066 free(*arg);
1067 *arg = NULL;
1068}
1069
1070
1071void set_tcpoff(arg)
1072char **arg;
1073{

--- 5 unchanged lines hidden (view full) ---

1079 free(*arg);
1080 *arg = NULL;
1081}
1082
1083
1084void set_tcpurp(arg)
1085char **arg;
1086{
1081 tcp->th_urp = strtol(*arg, NULL, 0);
1087 tcp->th_urp = htons(strtol(*arg, NULL, 0));
1082 free(*arg);
1083 *arg = NULL;
1084}
1085
1086
1087void set_tcpwin(arg)
1088char **arg;
1089{
1088 free(*arg);
1089 *arg = NULL;
1090}
1091
1092
1093void set_tcpwin(arg)
1094char **arg;
1095{
1090 tcp->th_win = strtol(*arg, NULL, 0);
1096 tcp->th_win = htons(strtol(*arg, NULL, 0));
1091 free(*arg);
1092 *arg = NULL;
1093}
1094
1095
1096void set_tcpsum(arg)
1097char **arg;
1098{

--- 194 unchanged lines hidden (view full) ---

1293
1294void packet_done()
1295{
1296 char outline[80];
1297 int i, j, k;
1298 u_char *s = (u_char *)ipbuffer, *t = (u_char *)outline;
1299
1300 if (opts & OPT_VERBOSE) {
1097 free(*arg);
1098 *arg = NULL;
1099}
1100
1101
1102void set_tcpsum(arg)
1103char **arg;
1104{

--- 194 unchanged lines hidden (view full) ---

1299
1300void packet_done()
1301{
1302 char outline[80];
1303 int i, j, k;
1304 u_char *s = (u_char *)ipbuffer, *t = (u_char *)outline;
1305
1306 if (opts & OPT_VERBOSE) {
1301 for (i = ip->ip_len, j = 0; i; i--, j++, s++) {
1307 ip->ip_len = htons(ip->ip_len);
1308 for (i = ntohs(ip->ip_len), j = 0; i; i--, j++, s++) {
1302 if (j && !(j & 0xf)) {
1303 *t++ = '\n';
1304 *t = '\0';
1305 fputs(outline, stdout);
1306 fflush(stdout);
1307 t = (u_char *)outline;
1308 *t = '\0';
1309 }

--- 23 unchanged lines hidden (view full) ---

1333 s -= j & 0xf;
1334 for (k = j & 0xf; k; k--, s++)
1335 *t++ = (isprint(*s) ? *s : '.');
1336 *t++ = '\n';
1337 *t = '\0';
1338 }
1339 fputs(outline, stdout);
1340 fflush(stdout);
1309 if (j && !(j & 0xf)) {
1310 *t++ = '\n';
1311 *t = '\0';
1312 fputs(outline, stdout);
1313 fflush(stdout);
1314 t = (u_char *)outline;
1315 *t = '\0';
1316 }

--- 23 unchanged lines hidden (view full) ---

1340 s -= j & 0xf;
1341 for (k = j & 0xf; k; k--, s++)
1342 *t++ = (isprint(*s) ? *s : '.');
1343 *t++ = '\n';
1344 *t = '\0';
1345 }
1346 fputs(outline, stdout);
1347 fflush(stdout);
1348 ip->ip_len = ntohs(ip->ip_len);
1341 }
1342
1343 prep_packet();
1344 free_aniplist();
1345}
1346
1347
1348void new_interface()

--- 188 unchanged lines hidden (view full) ---

1537 free(*type);
1538 *type = NULL;
1539}
1540
1541
1542void set_icmpid(arg)
1543int arg;
1544{
1349 }
1350
1351 prep_packet();
1352 free_aniplist();
1353}
1354
1355
1356void new_interface()

--- 188 unchanged lines hidden (view full) ---

1545 free(*type);
1546 *type = NULL;
1547}
1548
1549
1550void set_icmpid(arg)
1551int arg;
1552{
1545 icmp->icmp_id = arg;
1553 icmp->icmp_id = htons(arg);
1546}
1547
1548
1549void set_icmpseq(arg)
1550int arg;
1551{
1554}
1555
1556
1557void set_icmpseq(arg)
1558int arg;
1559{
1552 icmp->icmp_seq = arg;
1560 icmp->icmp_seq = htons(arg);
1553}
1554
1555
1556void set_icmpotime(arg)
1557int arg;
1558{
1561}
1562
1563
1564void set_icmpotime(arg)
1565int arg;
1566{
1559 icmp->icmp_otime = arg;
1567 icmp->icmp_otime = htonl(arg);
1560}
1561
1562
1563void set_icmprtime(arg)
1564int arg;
1565{
1568}
1569
1570
1571void set_icmprtime(arg)
1572int arg;
1573{
1566 icmp->icmp_rtime = arg;
1574 icmp->icmp_rtime = htonl(arg);
1567}
1568
1569
1570void set_icmpttime(arg)
1571int arg;
1572{
1575}
1576
1577
1578void set_icmpttime(arg)
1579int arg;
1580{
1573 icmp->icmp_ttime = arg;
1581 icmp->icmp_ttime = htonl(arg);
1574}
1575
1576
1577void set_icmpmtu(arg)
1578int arg;
1579{
1580#if BSD >= 199306
1582}
1583
1584
1585void set_icmpmtu(arg)
1586int arg;
1587{
1588#if BSD >= 199306
1581 icmp->icmp_nextmtu = arg;
1589 icmp->icmp_nextmtu = htons(arg);
1582#endif
1583}
1584
1585
1586void set_redir(redir, arg)
1587int redir;
1588char **arg;
1589{

--- 135 unchanged lines hidden (view full) ---

1725}
1726
1727
1728void end_ipv4()
1729{
1730 aniphdr_t *aip;
1731
1732 ip->ip_sum = 0;
1590#endif
1591}
1592
1593
1594void set_redir(redir, arg)
1595int redir;
1596char **arg;
1597{

--- 135 unchanged lines hidden (view full) ---

1733}
1734
1735
1736void end_ipv4()
1737{
1738 aniphdr_t *aip;
1739
1740 ip->ip_sum = 0;
1741 ip->ip_len = htons(ip->ip_len);
1733 ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
1742 ip->ip_sum = chksum((u_short *)ip, ip->ip_hl << 2);
1743 ip->ip_len = ntohs(ip->ip_len);
1734 free_anipheader();
1735 for (aip = aniphead, ip = NULL; aip; aip = aip->ah_next)
1736 if (aip->ah_p == IPPROTO_IP)
1737 ip = aip->ah_ip;
1738}
1739
1740
1741void end_icmp()

--- 14 unchanged lines hidden (view full) ---

1756 u_long sum;
1757 aniphdr_t *aip;
1758 ip_t iptmp;
1759
1760 bzero((char *)&iptmp, sizeof(iptmp));
1761 iptmp.ip_p = ip->ip_p;
1762 iptmp.ip_src = ip->ip_src;
1763 iptmp.ip_dst = ip->ip_dst;
1744 free_anipheader();
1745 for (aip = aniphead, ip = NULL; aip; aip = aip->ah_next)
1746 if (aip->ah_p == IPPROTO_IP)
1747 ip = aip->ah_ip;
1748}
1749
1750
1751void end_icmp()

--- 14 unchanged lines hidden (view full) ---

1766 u_long sum;
1767 aniphdr_t *aip;
1768 ip_t iptmp;
1769
1770 bzero((char *)&iptmp, sizeof(iptmp));
1771 iptmp.ip_p = ip->ip_p;
1772 iptmp.ip_src = ip->ip_src;
1773 iptmp.ip_dst = ip->ip_dst;
1764 iptmp.ip_len = ip->ip_len - (ip->ip_hl << 2);
1774 iptmp.ip_len = htons(ip->ip_len - (ip->ip_hl << 2));
1765 sum = p_chksum((u_short *)&iptmp, (u_int)sizeof(iptmp));
1775 sum = p_chksum((u_short *)&iptmp, (u_int)sizeof(iptmp));
1766 udp->uh_sum = c_chksum((u_short *)udp, (u_int)iptmp.ip_len, sum);
1776 udp->uh_ulen = htons(udp->uh_ulen);
1777 udp->uh_sum = c_chksum((u_short *)udp, (u_int)ntohs(iptmp.ip_len), sum);
1767 free_anipheader();
1768 for (aip = aniphead, udp = NULL; aip; aip = aip->ah_next)
1769 if (aip->ah_p == IPPROTO_UDP)
1770 udp = aip->ah_udp;
1771}
1772
1773
1774void end_tcp()
1775{
1776 u_long sum;
1777 aniphdr_t *aip;
1778 ip_t iptmp;
1779
1780 bzero((char *)&iptmp, sizeof(iptmp));
1781 iptmp.ip_p = ip->ip_p;
1782 iptmp.ip_src = ip->ip_src;
1783 iptmp.ip_dst = ip->ip_dst;
1778 free_anipheader();
1779 for (aip = aniphead, udp = NULL; aip; aip = aip->ah_next)
1780 if (aip->ah_p == IPPROTO_UDP)
1781 udp = aip->ah_udp;
1782}
1783
1784
1785void end_tcp()
1786{
1787 u_long sum;
1788 aniphdr_t *aip;
1789 ip_t iptmp;
1790
1791 bzero((char *)&iptmp, sizeof(iptmp));
1792 iptmp.ip_p = ip->ip_p;
1793 iptmp.ip_src = ip->ip_src;
1794 iptmp.ip_dst = ip->ip_dst;
1784 iptmp.ip_len = ip->ip_len - (ip->ip_hl << 2);
1795 iptmp.ip_len = htons(ip->ip_len - (ip->ip_hl << 2));
1785 sum = p_chksum((u_short *)&iptmp, (u_int)sizeof(iptmp));
1786 tcp->th_sum = 0;
1796 sum = p_chksum((u_short *)&iptmp, (u_int)sizeof(iptmp));
1797 tcp->th_sum = 0;
1787 tcp->th_sum = c_chksum((u_short *)tcp, (u_int)iptmp.ip_len, sum);
1798 tcp->th_sum = c_chksum((u_short *)tcp, (u_int)ntohs(iptmp.ip_len), sum);
1788 free_anipheader();
1789 for (aip = aniphead, tcp = NULL; aip; aip = aip->ah_next)
1790 if (aip->ah_p == IPPROTO_TCP)
1791 tcp = aip->ah_tcp;
1792}
1793
1794
1795void end_data()

--- 44 unchanged lines hidden ---
1799 free_anipheader();
1800 for (aip = aniphead, tcp = NULL; aip; aip = aip->ah_next)
1801 if (aip->ah_p == IPPROTO_TCP)
1802 tcp = aip->ah_tcp;
1803}
1804
1805
1806void end_data()

--- 44 unchanged lines hidden ---