| 164 | #endif |
| 165 | |
| 166 | static void |
| 167 | AliasHandleIrcOut(struct libalias *la, |
| 168 | struct ip *pip, /* IP packet to examine */ |
| 169 | struct alias_link *lnk, /* Which link are we on? */ |
| 170 | int maxsize /* Maximum size of IP packet including |
| 171 | * headers */ |
| 172 | ) |
| 173 | { |
| 174 | int hlen, tlen, dlen; |
| 175 | struct in_addr true_addr; |
| 176 | u_short true_port; |
| 177 | char *sptr; |
| 178 | struct tcphdr *tc; |
| 179 | int i; /* Iterator through the source */ |
| 180 | |
| 181 | /* Calculate data length of TCP packet */ |
| 182 | tc = (struct tcphdr *)ip_next(pip); |
| 183 | hlen = (pip->ip_hl + tc->th_off) << 2; |
| 184 | tlen = ntohs(pip->ip_len); |
| 185 | dlen = tlen - hlen; |
| 186 | |
| 187 | /* |
| 188 | * Return if data length is too short - assume an entire PRIVMSG in |
| 189 | * each packet. |
| 190 | */ |
| 191 | if (dlen < (int)sizeof(":A!a@n.n PRIVMSG A :aDCC 1 1a") - 1) |
| 192 | return; |
| 193 | |
| 194 | /* Place string pointer at beginning of data */ |
| 195 | sptr = (char *)pip; |
| 196 | sptr += hlen; |
| 197 | maxsize -= hlen; /* We're interested in maximum size of |
| 198 | * data, not packet */ |
| 199 | |
| 200 | /* Search for a CTCP command [Note 1] */ |
| 201 | for (i = 0; i < dlen; i++) { |
| 202 | if (sptr[i] == '\001') |
| 203 | goto lFOUND_CTCP; |
| 204 | } |
| 205 | return; /* No CTCP commands in */ |
| 206 | /* Handle CTCP commands - the buffer may have to be copied */ |
| 207 | lFOUND_CTCP: |
| 208 | { |
| 209 | unsigned int copyat = i; |
| 210 | unsigned int iCopy = 0; /* How much data have we written to |
| 211 | * copy-back string? */ |
| 212 | unsigned long org_addr; /* Original IP address */ |
| 213 | unsigned short org_port; /* Original source port |
| 214 | * address */ |
| 215 | |
| 216 | lCTCP_START: |
| 217 | if (i >= dlen || iCopy >= PKTSIZE) |
| 218 | goto lPACKET_DONE; |
| 219 | newpacket[iCopy++] = sptr[i++]; /* Copy the CTCP start |
| 220 | * character */ |
| 221 | /* Start of a CTCP */ |
| 222 | if (i + 4 >= dlen) /* Too short for DCC */ |
| 223 | goto lBAD_CTCP; |
no test coverage detected