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