1*ee67461eSJoseph Mingrone /* 2*ee67461eSJoseph Mingrone * Redistribution and use in source and binary forms, with or without 3*ee67461eSJoseph Mingrone * modification, are permitted provided that: (1) source code 4*ee67461eSJoseph Mingrone * distributions retain the above copyright notice and this paragraph 5*ee67461eSJoseph Mingrone * in its entirety, and (2) distributions including binary code include 6*ee67461eSJoseph Mingrone * the above copyright notice and this paragraph in its entirety in 7*ee67461eSJoseph Mingrone * the documentation or other materials provided with the distribution. 8*ee67461eSJoseph Mingrone * THIS SOFTWARE IS PROVIDED ``AS IS'' AND 9*ee67461eSJoseph Mingrone * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT 10*ee67461eSJoseph Mingrone * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 11*ee67461eSJoseph Mingrone * FOR A PARTICULAR PURPOSE. 12*ee67461eSJoseph Mingrone */ 13*ee67461eSJoseph Mingrone 14*ee67461eSJoseph Mingrone /* \summary: Secure Shell (SSH) printer */ 15*ee67461eSJoseph Mingrone 16*ee67461eSJoseph Mingrone #ifdef HAVE_CONFIG_H 17*ee67461eSJoseph Mingrone #include <config.h> 18*ee67461eSJoseph Mingrone #endif 19*ee67461eSJoseph Mingrone 20*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h" 21*ee67461eSJoseph Mingrone #include "netdissect-ctype.h" 22*ee67461eSJoseph Mingrone 23*ee67461eSJoseph Mingrone #include "netdissect.h" 24*ee67461eSJoseph Mingrone #include "extract.h" 25*ee67461eSJoseph Mingrone 26*ee67461eSJoseph Mingrone static int 27*ee67461eSJoseph Mingrone ssh_print_version(netdissect_options *ndo, const u_char *pptr, u_int len) 28*ee67461eSJoseph Mingrone { 29*ee67461eSJoseph Mingrone u_int idx = 0; 30*ee67461eSJoseph Mingrone 31*ee67461eSJoseph Mingrone if ( GET_U_1(pptr+idx) != 'S' ) 32*ee67461eSJoseph Mingrone return 0; 33*ee67461eSJoseph Mingrone idx++; 34*ee67461eSJoseph Mingrone if ( GET_U_1(pptr+idx) != 'S' ) 35*ee67461eSJoseph Mingrone return 0; 36*ee67461eSJoseph Mingrone idx++; 37*ee67461eSJoseph Mingrone if ( GET_U_1(pptr+idx) != 'H' ) 38*ee67461eSJoseph Mingrone return 0; 39*ee67461eSJoseph Mingrone idx++; 40*ee67461eSJoseph Mingrone if ( GET_U_1(pptr+idx) != '-' ) 41*ee67461eSJoseph Mingrone return 0; 42*ee67461eSJoseph Mingrone idx++; 43*ee67461eSJoseph Mingrone 44*ee67461eSJoseph Mingrone while (idx < len) { 45*ee67461eSJoseph Mingrone u_char c; 46*ee67461eSJoseph Mingrone 47*ee67461eSJoseph Mingrone c = GET_U_1(pptr + idx); 48*ee67461eSJoseph Mingrone if (c == '\n') { 49*ee67461eSJoseph Mingrone /* 50*ee67461eSJoseph Mingrone * LF without CR; end of line. 51*ee67461eSJoseph Mingrone * Skip the LF and print the line, with the 52*ee67461eSJoseph Mingrone * exception of the LF. 53*ee67461eSJoseph Mingrone */ 54*ee67461eSJoseph Mingrone goto print; 55*ee67461eSJoseph Mingrone } else if (c == '\r') { 56*ee67461eSJoseph Mingrone /* CR - any LF? */ 57*ee67461eSJoseph Mingrone if ((idx+1) >= len) { 58*ee67461eSJoseph Mingrone /* not in this packet */ 59*ee67461eSJoseph Mingrone goto trunc; 60*ee67461eSJoseph Mingrone } 61*ee67461eSJoseph Mingrone if (GET_U_1(pptr + idx + 1) == '\n') { 62*ee67461eSJoseph Mingrone /* 63*ee67461eSJoseph Mingrone * CR-LF; end of line. 64*ee67461eSJoseph Mingrone * Skip the CR-LF and print the line, with 65*ee67461eSJoseph Mingrone * the exception of the CR-LF. 66*ee67461eSJoseph Mingrone */ 67*ee67461eSJoseph Mingrone goto print; 68*ee67461eSJoseph Mingrone } 69*ee67461eSJoseph Mingrone 70*ee67461eSJoseph Mingrone /* 71*ee67461eSJoseph Mingrone * CR followed by something else; treat this as 72*ee67461eSJoseph Mingrone * if it were binary data and don't print it. 73*ee67461eSJoseph Mingrone */ 74*ee67461eSJoseph Mingrone goto trunc; 75*ee67461eSJoseph Mingrone } else if (!ND_ASCII_ISPRINT(c) ) { 76*ee67461eSJoseph Mingrone /* 77*ee67461eSJoseph Mingrone * Not a printable ASCII character; treat this 78*ee67461eSJoseph Mingrone * as if it were binary data and don't print it. 79*ee67461eSJoseph Mingrone */ 80*ee67461eSJoseph Mingrone goto trunc; 81*ee67461eSJoseph Mingrone } 82*ee67461eSJoseph Mingrone idx++; 83*ee67461eSJoseph Mingrone } 84*ee67461eSJoseph Mingrone trunc: 85*ee67461eSJoseph Mingrone return -1; 86*ee67461eSJoseph Mingrone print: 87*ee67461eSJoseph Mingrone ND_PRINT(": "); 88*ee67461eSJoseph Mingrone nd_print_protocol_caps(ndo); 89*ee67461eSJoseph Mingrone ND_PRINT(": %.*s", (int)idx, pptr); 90*ee67461eSJoseph Mingrone return idx; 91*ee67461eSJoseph Mingrone } 92*ee67461eSJoseph Mingrone 93*ee67461eSJoseph Mingrone void 94*ee67461eSJoseph Mingrone ssh_print(netdissect_options *ndo, const u_char *pptr, u_int len) 95*ee67461eSJoseph Mingrone { 96*ee67461eSJoseph Mingrone ndo->ndo_protocol = "ssh"; 97*ee67461eSJoseph Mingrone 98*ee67461eSJoseph Mingrone ssh_print_version(ndo, pptr, len); 99*ee67461eSJoseph Mingrone } 100