<s>[INST] Find the indefinite integral $\frac{x\sin x}{1+\cos^2 x}$ 
Evaluate $$\int\frac{x\sin x}{1+\cos^2 x}dx$$

My attempt:
$$I=\int\frac{x\sin x}{1+\cos^2 x}dx=\int x\frac{\sin x}{1+\cos^2 x}dx=\\x\int \frac{\sin x}{1+\cos^2 x}dx-\int \left[\frac{d}{dx}x\int\frac{\sin x}{1+\cos^2 x}dx\right]dx$$

$I'=\displaystyle \int \frac{\sin x}{1+\cos^2 x}dx$
Let $u=\cos x$
$\therefore \dfrac{du}{dx}=-\sin x$
$\implies du=(-\sin x)dx$
$\therefore \displaystyle I'=-\int \frac{du}{1+u^2} $
$\implies I'=-\dfrac{1}{1}\tan^{-1}\left(\dfrac{u}{1}\right)+C \implies I'=-\tan^{-1}(u)+C$
$\implies I'=-\tan^{-1}(\cos x)+C$
$\therefore \displaystyle \int \frac{\sin x}{1+\cos^2 x}dx=-\tan^{-1} (\cos x)+C$

$\therefore \displaystyle I=x\cdot[-\tan^{-1} (\cos x)]-\int [-\tan^{-1} (\cos x)] dx$
$\implies  \displaystyle I=-x \tan^{-1} (\cos x)+\int \tan^{-1} (\cos x)dx$
I cannot understand how to proceed further. Please help.
 [/INST] I wrote this in response to the comment by the OP that he/she actually was trying to solve the definite integral over $[0, \pi]$.
Using the fact that
$$\int_{a}^{b} f(x) dx = \int_{a}^{b} f(b + a - x) dx$$
we find
\begin{align}
I &= \int_{0}^{\pi} \frac{x \sin x}{1 + \cos^{2}x} dx \\
&= \int_{0}^{\pi} \frac{(\pi - x) \sin(\pi - x)}{1 + \cos^{2}(\pi - x)} dx \\
&= \int_{0}^{\pi} \frac{(\pi - x) \sin x}{1 + \cos^{2}x} dx \\
&= \pi \int_{0}^{\pi} \frac{\sin x}{1 + \cos^{2} x} dx - I \\
\implies I &= \frac{\pi}{2} \int_{0}^{\pi} \frac{\sin x}{1 + \cos^{2}x} dx \qquad \text{(use substitution $u = \cos(x)$ to evaluate)} \\
&= \frac{\pi}{2} \cdot \frac{\pi}{2} \\
&= \frac{\pi^{2}}{4}
\end{align}
</s>