How can I convert Arduino String to C string type?
Try

unsigned char z[100];
IP.getBytes(z, 100);
z[IP.length()] = 0;
int n = atoi(z);


To retrieve bytes inside the string. This assumes IP string's length is shorter than 100.