* Append the specified data to the indicated mbuf chain, * Extend the mbuf chain if the new data does not fit in * existing space. * * Return 1 if able to complete the job; otherwise 0. */
| 1178 | * Return 1 if able to complete the job; otherwise 0. |
| 1179 | */ |
| 1180 | int |
| 1181 | m_append(struct mbuf *m0, int len, c_caddr_t cp) |
| 1182 | { |
| 1183 | struct mbuf *m, *n; |
| 1184 | int remainder, space; |
| 1185 | |
| 1186 | for (m = m0; m->m_next != NULL; m = m->m_next) |
| 1187 | ; |
| 1188 | remainder = len; |
| 1189 | space = M_TRAILINGSPACE(m); |
| 1190 | if (space > 0) { |
| 1191 | /* |
| 1192 | * Copy into available space. |
| 1193 | */ |
| 1194 | if (space > remainder) |
| 1195 | space = remainder; |
| 1196 | bcopy(cp, mtod(m, caddr_t) + m->m_len, space); |
| 1197 | m->m_len += space; |
| 1198 | cp += space, remainder -= space; |
| 1199 | } |
| 1200 | while (remainder > 0) { |
| 1201 | /* |
| 1202 | * Allocate a new mbuf; could check space |
| 1203 | * and allocate a cluster instead. |
| 1204 | */ |
| 1205 | n = m_get(M_NOWAIT, m->m_type); |
| 1206 | if (n == NULL) |
| 1207 | break; |
| 1208 | n->m_len = min(MLEN, remainder); |
| 1209 | bcopy(cp, mtod(n, caddr_t), n->m_len); |
| 1210 | cp += n->m_len, remainder -= n->m_len; |
| 1211 | m->m_next = n; |
| 1212 | m = n; |
| 1213 | } |
| 1214 | if (m0->m_flags & M_PKTHDR) |
| 1215 | m0->m_pkthdr.len += len - remainder; |
| 1216 | return (remainder == 0); |
| 1217 | } |
| 1218 | |
| 1219 | /* |
| 1220 | * Apply function f to the data in an mbuf chain starting "off" bytes from |
no test coverage detected