1 /* 2 * m_pedit_tcp.c packet editor: TCP header 3 * 4 * This program is free software; you can distribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 7 * 2 of the License, or (at your option) any later version. 8 * 9 * Authors: J Hadi Salim (hadi (at) cyberus.ca) 10 * 11 */ 12 13 #include <stdio.h> 14 #include <stdlib.h> 15 #include <unistd.h> 16 #include <syslog.h> 17 #include <fcntl.h> 18 #include <sys/socket.h> 19 #include <netinet/in.h> 20 #include <arpa/inet.h> 21 #include <string.h> 22 #include "utils.h" 23 #include "tc_util.h" 24 #include "m_pedit.h" 25 26 static int 27 parse_tcp(int *argc_p, char ***argv_p, 28 struct m_pedit_sel *sel, struct m_pedit_key *tkey) 29 { 30 int res = -1; 31 int argc = *argc_p; 32 char **argv = *argv_p; 33 34 if (argc < 2) 35 return -1; 36 37 if (!sel->extended) 38 return -1; 39 40 tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_TCP; 41 42 if (strcmp(*argv, "sport") == 0) { 43 NEXT_ARG(); 44 tkey->off = 0; 45 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey); 46 goto done; 47 } 48 49 if (strcmp(*argv, "dport") == 0) { 50 NEXT_ARG(); 51 tkey->off = 2; 52 res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey); 53 goto done; 54 } 55 56 if (strcmp(*argv, "flags") == 0) { 57 NEXT_ARG(); 58 tkey->off = 13; 59 res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey); 60 goto done; 61 } 62 63 return -1; 64 65 done: 66 *argc_p = argc; 67 *argv_p = argv; 68 return res; 69 } 70 struct m_pedit_util p_pedit_tcp = { 71 NULL, 72 "tcp", 73 parse_tcp, 74 }; 75