| 3333 | #pragma GCC diagnostic ignored "-Wformat" |
| 3334 | #pragma GCC diagnostic ignored "-Wformat-extra-args" |
| 3335 | static char * |
| 3336 | tcp_log_addr(struct in_conninfo *inc, struct tcphdr *th, void *ip4hdr, |
| 3337 | const void *ip6hdr) |
| 3338 | { |
| 3339 | char *s, *sp; |
| 3340 | size_t size; |
| 3341 | struct ip *ip; |
| 3342 | #ifdef INET6 |
| 3343 | const struct ip6_hdr *ip6; |
| 3344 | |
| 3345 | ip6 = (const struct ip6_hdr *)ip6hdr; |
| 3346 | #endif /* INET6 */ |
| 3347 | ip = (struct ip *)ip4hdr; |
| 3348 | |
| 3349 | /* |
| 3350 | * The log line looks like this: |
| 3351 | * "TCP: [1.2.3.4]:50332 to [1.2.3.4]:80 tcpflags 0x2<SYN>" |
| 3352 | */ |
| 3353 | size = sizeof("TCP: []:12345 to []:12345 tcpflags 0x2<>") + |
| 3354 | sizeof(PRINT_TH_FLAGS) + 1 + |
| 3355 | #ifdef INET6 |
| 3356 | 2 * INET6_ADDRSTRLEN; |
| 3357 | #else |
| 3358 | 2 * INET_ADDRSTRLEN; |
| 3359 | #endif /* INET6 */ |
| 3360 | |
| 3361 | s = malloc(size, M_TCPLOG, M_ZERO|M_NOWAIT); |
| 3362 | if (s == NULL) |
| 3363 | return (NULL); |
| 3364 | |
| 3365 | strcat(s, "TCP: ["); |
| 3366 | sp = s + strlen(s); |
| 3367 | |
| 3368 | if (inc && ((inc->inc_flags & INC_ISIPV6) == 0)) { |
| 3369 | inet_ntoa_r(inc->inc_faddr, sp); |
| 3370 | sp = s + strlen(s); |
| 3371 | sprintf(sp, "]:%i to [", ntohs(inc->inc_fport)); |
| 3372 | sp = s + strlen(s); |
| 3373 | inet_ntoa_r(inc->inc_laddr, sp); |
| 3374 | sp = s + strlen(s); |
| 3375 | sprintf(sp, "]:%i", ntohs(inc->inc_lport)); |
| 3376 | #ifdef INET6 |
| 3377 | } else if (inc) { |
| 3378 | ip6_sprintf(sp, &inc->inc6_faddr); |
| 3379 | sp = s + strlen(s); |
| 3380 | sprintf(sp, "]:%i to [", ntohs(inc->inc_fport)); |
| 3381 | sp = s + strlen(s); |
| 3382 | ip6_sprintf(sp, &inc->inc6_laddr); |
| 3383 | sp = s + strlen(s); |
| 3384 | sprintf(sp, "]:%i", ntohs(inc->inc_lport)); |
| 3385 | } else if (ip6 && th) { |
| 3386 | ip6_sprintf(sp, &ip6->ip6_src); |
| 3387 | sp = s + strlen(s); |
| 3388 | sprintf(sp, "]:%i to [", ntohs(th->th_sport)); |
| 3389 | sp = s + strlen(s); |
| 3390 | ip6_sprintf(sp, &ip6->ip6_dst); |
| 3391 | sp = s + strlen(s); |
| 3392 | sprintf(sp, "]:%i", ntohs(th->th_dport)); |
no test coverage detected