Downblock, downblock, downblock. If you're not sure what a downblock is, it's when the other guy shoots in, and you change your levels, bring your leg back, and put your hand in the mat, blocking him. In other words, you're going "down" and then "blocking" him with your hand. It's much like a sprawl. If you can change your level, get that leg back, and block him off, he won't even be able to touch your legs. From there, you can go into your short offense.
A couple of downblock drills - 1) Have a partner point to the leg that he's going to shoot at. Then, he shoots at it. You know which leg he will be shooting towards - all you need to focus on in this drill is the timing and the downblock itself. You can do this drill with outside shots or from handfighting/contact. 2) Be in a handfight with a partner, and have your partner try to hit all "high" shots. That means that he's not dropping to his knees on his shots. He's just reaching for the leg, basically. When he goes for the leg, you hit your downblock. 3) Just go live, basically, except that you are on defense and he is on offense. He is doing whatever he can to try and get in on the shot, and you are trying to downblock and not let him touch your leg. If you score, get back up and go again. If he gets in on the shot, get back up and go again. Do this in about 1 minute intervals.
Believe me, these drills help. Defense used to be the WORST part of my game. Flat out. I probably went a year and a half without successfully blocking off an opponent's shot. But, when I started working these drills, and continued to work them, keeping guys off of my legs became one of my best skills.
If a guy gets in on your leg, you have to just remember these key points - hips in, butt in, chest up, and driving into him. You want to break his lock around your leg. This is assuming the guy is in on your leg, but you have sprawled back to a point and he is underneath you. You HAVE to keep your hips in and your chest up. If your hips and butt are sticking way up in the air, you have no pressure on him and he will drive straight through you to finish. When you have him stuffed underneath you, keep your hips and butt in, keep your chest up, keep all your pressure on him, and, while you have this pressure on him, circle around. If you let the pressure off while circling around, he'll fight back up and be able to drive through you.